gauntlet_rdoc.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. require 'rubygems'
  2. Gem.load_yaml
  3. require 'rdoc'
  4. require 'gauntlet'
  5. require 'fileutils'
  6. ##
  7. # Allows for testing of RDoc against every gem
  8. class RDoc::Gauntlet < Gauntlet
  9. def initialize # :nodoc:
  10. super
  11. @args = nil
  12. @type = nil
  13. end
  14. ##
  15. # Runs an RDoc generator for gem +name+
  16. def run name
  17. return if self.data.key? name
  18. dir = File.expand_path "~/.gauntlet/data/#{@type}/#{name}"
  19. FileUtils.rm_rf dir if File.exist? dir
  20. yaml = File.read 'gemspec'
  21. begin
  22. spec = Gem::Specification.from_yaml yaml
  23. rescue Psych::SyntaxError
  24. puts "bad spec #{name}"
  25. self.data[name] = false
  26. return
  27. end
  28. args = @args.dup
  29. args << '--op' << dir
  30. args.push(*spec.rdoc_options)
  31. args << spec.require_paths
  32. args << spec.extra_rdoc_files
  33. args = args.flatten.map { |a| a.to_s }
  34. args.delete '--quiet'
  35. puts "#{name} - rdoc #{args.join ' '}"
  36. self.dirty = true
  37. r = RDoc::RDoc.new
  38. begin
  39. r.document args
  40. self.data[name] = true
  41. puts 'passed'
  42. FileUtils.rm_rf dir
  43. rescue Interrupt, StandardError, RDoc::Error, SystemStackError => e
  44. puts "failed - (#{e.class}) #{e.message}"
  45. self.data[name] = false
  46. end
  47. rescue Gem::Exception
  48. puts "bad gem #{name}"
  49. ensure
  50. puts
  51. end
  52. ##
  53. # Runs the gauntlet with the given +type+ (rdoc or ri) and +filter+ for
  54. # which gems to run
  55. def run_the_gauntlet type = 'rdoc', filter = nil
  56. @type = type || 'rdoc'
  57. @args = type == 'rdoc' ? [] : %w[--ri]
  58. @data_file = "#{DATADIR}/#{@type}-data.yml"
  59. super filter
  60. end
  61. end
  62. type = ARGV.shift
  63. filter = ARGV.shift
  64. filter = /#{filter}/ if filter
  65. RDoc::Gauntlet.new.run_the_gauntlet type, filter