root / bin / suite.rb

Revision 376:e5c8a9b41bc9, 2.5 kB (checked in by unknown, 3 years ago)

* Changes Date, Version, and Copyright to upper case, to avoid conflicts with

the Date class. All of the other changes in the altered files are because
Subversion doesn't allow block-level commits, like it should.

* Minor, yet incomplete, documentation changes. Again, these are in this patch

because of Subversion's glaring lack of block-level commits.

* I forgot to add the unit tests that I promised in the previous patch for

issue #32.

  • Property exe set to *
Line 
1#!/usr/bin/ruby -wIsrc
2
3Dir.chdir ".." if Dir.pwd =~ /bin.?$/
4
5require "test/unit/testcase"
6require "test/unit/ui/console/testrunner"
7require 'getoptlong'
8
9Dir.entries('test').each do |file|
10        require "test/#{file}" if file =~ /\.rb$/
11end
12
13runner = Test::Unit::UI::Console::TestRunner
14suite = Test::Unit::TestSuite
15level = Test::Unit::UI::NORMAL
16
17opts = 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)
23opts.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
59puts "REXML version = #{REXML::VERSION}"
60
61if 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 )
83else
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 )
91end
92
93exit 1 unless (results.failure_count == 0 and results.error_count == 0)
Note: See TracBrowser for help on using the browser.