| 1 | #!/usr/bin/ruby -wIsrc |
|---|
| 2 | |
|---|
| 3 | Dir.chdir ".." if Dir.pwd =~ /bin.?$/ |
|---|
| 4 | |
|---|
| 5 | require "test/unit/testcase" |
|---|
| 6 | require "test/unit/ui/console/testrunner" |
|---|
| 7 | require 'getoptlong' |
|---|
| 8 | |
|---|
| 9 | Dir.entries('test').each do |file| |
|---|
| 10 | require "test/#{file}" if file =~ /\.rb$/ |
|---|
| 11 | end |
|---|
| 12 | |
|---|
| 13 | runner = Test::Unit::UI::Console::TestRunner |
|---|
| 14 | suite = Test::Unit::TestSuite |
|---|
| 15 | level = Test::Unit::UI::NORMAL |
|---|
| 16 | |
|---|
| 17 | opts = GetoptLong.new( |
|---|
| 18 | ['--verbose', '-v', GetoptLong::NO_ARGUMENT], |
|---|
| 19 | ['--help', '-h', GetoptLong::NO_ARGUMENT], |
|---|
| 20 | ['--list', '-l', GetoptLong::OPTIONAL_ARGUMENT], |
|---|
| 21 | ['--gui', '-g', GetoptLong::NO_ARGUMENT] |
|---|
| 22 | ) |
|---|
| 23 | opts.each { |opt, arg| |
|---|
| 24 | case opt |
|---|
| 25 | when '--help' |
|---|
| 26 | puts "USAGE: #$0 [--verbose][--help|--list [<suite>]|[--gui] <suite> [<method>]|<method>]\n"+ |
|---|
| 27 | " --list\tList the available test suites\n"+ |
|---|
| 28 | " <suite>\tList the methods of a suite\n"+ |
|---|
| 29 | " <suite>\tRun all of the tests in a suite\n"+ |
|---|
| 30 | " <method>\tRun the given method" |
|---|
| 31 | exit |
|---|
| 32 | when '--list' |
|---|
| 33 | if ARGV[0] |
|---|
| 34 | suite = ARGV[0] |
|---|
| 35 | ObjectSpace.each_object(Class){|ob|suite = ob if ob.to_s == suite} |
|---|
| 36 | puts((suite.instance_methods - Object.methods).collect{|mn| " "+mn}) |
|---|
| 37 | else |
|---|
| 38 | ObjectSpace.each_object(Class){|ob| |
|---|
| 39 | puts ob.to_s if ob.ancestors.include? Test::Unit::TestCase and ob.to_s != 'RUNIT::TestCase' |
|---|
| 40 | } |
|---|
| 41 | end |
|---|
| 42 | exit |
|---|
| 43 | when '--verbose' |
|---|
| 44 | level = Test::Unit::UI::VERBOSE |
|---|
| 45 | when '--gui' |
|---|
| 46 | ARGV.shift |
|---|
| 47 | begin |
|---|
| 48 | require 'test/unit/ui/fox/testrunner' |
|---|
| 49 | runner = Test::Unit::UI::Fox::TestRunner |
|---|
| 50 | suite = Test::Unit::TestSuite |
|---|
| 51 | rescue Exception |
|---|
| 52 | puts $! |
|---|
| 53 | puts "You must have Test::Unit and FXRuby installed to run the GUI test runner.\n" |
|---|
| 54 | puts "I'm continuing without the GUI." |
|---|
| 55 | end |
|---|
| 56 | end |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | puts "REXML version = #{REXML::VERSION}" |
|---|
| 60 | |
|---|
| 61 | if ARGV.size > 0 |
|---|
| 62 | # Get the test Class object for the named test |
|---|
| 63 | test = ARGV[0] |
|---|
| 64 | ObjectSpace.each_object(Class) {|ob| test = ob if ob.to_s == test } |
|---|
| 65 | |
|---|
| 66 | # Are we running a single test, or a test suite? |
|---|
| 67 | if ARGV.size == 2 |
|---|
| 68 | test = test.new(ARGV[1]) |
|---|
| 69 | else |
|---|
| 70 | # They didn't supply a unit test name; look for methods |
|---|
| 71 | if test.kind_of? String |
|---|
| 72 | method = test |
|---|
| 73 | ObjectSpace.each_object(Class) {|ob| |
|---|
| 74 | test = ob if ob.instance_methods(false).include? method |
|---|
| 75 | } |
|---|
| 76 | test = test.new( method ) |
|---|
| 77 | else |
|---|
| 78 | test = test.suite |
|---|
| 79 | end |
|---|
| 80 | end |
|---|
| 81 | |
|---|
| 82 | results = runner.run( test, level ) |
|---|
| 83 | else |
|---|
| 84 | suite = suite.new 'REXML' |
|---|
| 85 | ObjectSpace.each_object(Class){|ob| |
|---|
| 86 | if ob.ancestors.include? Test::Unit::TestCase and ob.to_s != 'RUNIT::TestCase' and ob.to_s != 'Test::Unit::TestCase' |
|---|
| 87 | suite << ob.suite |
|---|
| 88 | end |
|---|
| 89 | } |
|---|
| 90 | results = runner.run( suite, level ) |
|---|
| 91 | end |
|---|
| 92 | |
|---|
| 93 | exit 1 unless (results.failure_count == 0 and results.error_count == 0) |
|---|