From 086745b7d6f0edb9b0537b9980e93952b9022b1e Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 2 Dec 2003 12:31:44 +0000 Subject: * bin/testrb: new test runner. [ruby-core:01845] * lib/test/unit/autorunner.rb (Test::Unit::AutoRunner.run, Test::Unit::AutoRunner#initialize): take test list to run. * lib/test/unit/autorunner.rb (Test::Unit::AutoRunner::RUNNERS, Test::Unit::AutoRunner#run): should not exit inside a library, just return the result instead. * lib/test/unit.rb: ditto. * test/runner.rb: exit with the test result. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/test/unit/autorunner.rb | 183 ++++++++++++++++++------------------ lib/test/unit/ui/fox/testrunner.rb | 3 + lib/test/unit/ui/gtk/testrunner.rb | 4 +- lib/test/unit/ui/gtk2/testrunner.rb | 5 +- lib/test/unit/ui/tk/testrunner.rb | 6 +- 5 files changed, 106 insertions(+), 95 deletions(-) (limited to 'lib/test/unit') diff --git a/lib/test/unit/autorunner.rb b/lib/test/unit/autorunner.rb index fb010d52e2..49fe543550 100644 --- a/lib/test/unit/autorunner.rb +++ b/lib/test/unit/autorunner.rb @@ -5,11 +5,11 @@ require 'test/unit/ui/console/testrunner' module Test module Unit class AutoRunner - def self.run(current_file=nil, default_dir=nil, &block) + def self.run(current_file=nil, default_dir=nil, argv=ARGV, &block) if(!current_file || current_file == $0) r = new(!current_file, &block) - if(default_dir && r.to_run.empty?) - r.to_run = default_dir + if !r.process_args(argv) && default_dir + r.to_run << default_dir end r.run end @@ -17,9 +17,7 @@ module Test RUNNERS = { :console => proc do |r| - output_level = r.output_level || Test::Unit::UI::Console::TestRunner::NORMAL - passed = Test::Unit::UI::Console::TestRunner.run(r.suite, output_level).passed? - exit(passed ? 0 : 1) + Test::Unit::UI::Console::TestRunner.run(r.suite, r.output_level) end, :gtk => proc do |r| require 'test/unit/ui/gtk/testrunner' @@ -73,104 +71,106 @@ module Test @collector = COLLECTORS[(standalone ? :dir : :objectspace)] @filters = [] @to_run = [] - process_args + @output_level = Test::Unit::UI::Console::TestRunner::NORMAL yield(self) if(block_given?) end - def process_args - catch(:stop_processing) do - ARGV.options do |o| - o.program_name = "test/unit.rb" - o.banner = "Test::Unit automatic runner." - o.banner = "#{$0} [options] [-- untouched arguments]" - - o.on - o.on('-r', '--runner=RUNNER', RUNNERS.keys, - "Use the given RUNNER.", - "(" + keyword_display(RUNNERS.keys) + ")") do |r| - @runner = RUNNERS[r] - end + def process_args(args = ARGV) + begin + @to_run.concat options.parse!(args) + rescue OptionParser::ParseError => e + puts e + puts options + $! = nil + abort + else + @filters << proc{false} unless(@filters.empty?) + end + not @to_run.empty? + end + + def options + @options ||= OptionParser.new do |o| + o.banner = "Test::Unit automatic runner." + o.banner << "\nUsage: #{$0} [options] [-- untouched arguments]" + + o.on + o.on('-r', '--runner=RUNNER', RUNNERS.keys, + "Use the given RUNNER.", + "(" + keyword_display(RUNNERS.keys) + ")") do |r| + @runner = RUNNERS[r] + end - if(@standalone) - o.on('-a', '--add=TORUN', Array, - "Add TORUN to the list of things to run;", - "can be a file or a directory.") do |a| - @to_run.concat(a) - end - - o.on('-p', '--pattern=PATTERN', String, - "Match files to collect against PATTERN.") do |e| - @pattern = Regexp.new(e.sub(%r{\A/(.*)/\Z}m, '\\1')) - end + if(@standalone) + o.on('-a', '--add=TORUN', Array, + "Add TORUN to the list of things to run;", + "can be a file or a directory.") do |a| + @to_run.concat(a) end - o.on('-n', '--name=NAME', String, - "Runs tests matching NAME.", - "(patterns may be used).") do |n| - n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) - case n - when Regexp - @filters << proc{|t| n =~ t.method_name ? true : nil} - else - @filters << proc{|t| n == t.method_name ? true : nil} - end + o.on('-p', '--pattern=PATTERN', String, + "Match files to collect against PATTERN.") do |e| + @pattern = Regexp.new(e.sub(%r{\A/(.*)/\Z}m, '\\1')) end - - o.on('-t', '--testcase=TESTCASE', String, - "Runs tests in TestCases matching TESTCASE.", - "(patterns may be used).") do |n| - n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) - case n - when Regexp - @filters << proc{|t| n =~ t.class.name ? true : nil} - else - @filters << proc{|t| n == t.class.name ? true : nil} - end + end + + o.on('-n', '--name=NAME', String, + "Runs tests matching NAME.", + "(patterns may be used).") do |n| + n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) + case n + when Regexp + @filters << proc{|t| n =~ t.method_name ? true : nil} + else + @filters << proc{|t| n == t.method_name ? true : nil} end - - o.on('-v', '--verbose=[LEVEL]', OUTPUT_LEVELS.keys, - "Set the output level (default is verbose).", - "(" + keyword_display(OUTPUT_LEVELS.keys) + ")") do |l| - @output_level = (l ? OUTPUT_LEVELS[l] : OUTPUT_LEVELS[:verbose]) + end + + o.on('-t', '--testcase=TESTCASE', String, + "Runs tests in TestCases matching TESTCASE.", + "(patterns may be used).") do |n| + n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) + case n + when Regexp + @filters << proc{|t| n =~ t.class.name ? true : nil} + else + @filters << proc{|t| n == t.class.name ? true : nil} end + end - o.on('--', - "Stop processing options so that the", - "remaining options will be passed to the", - "test."){throw :stop_processing} + o.on('-v', '--verbose=[LEVEL]', OUTPUT_LEVELS.keys, + "Set the output level (default is verbose).", + "(" + keyword_display(OUTPUT_LEVELS.keys) + ")") do |l| + @output_level = (l ? OUTPUT_LEVELS[l] : OUTPUT_LEVELS[:verbose]) + end - o.on('-h', '--help', 'Display this help.'){puts o; exit(0)} + o.on('--', + "Stop processing options so that the", + "remaining options will be passed to the", + "test."){o.terminate} - o.on_tail - o.on_tail('Deprecated options:') - - o.on_tail('--console', 'Console runner (use --runner).') do - warn("Deprecated option (--console).") - @runner = RUNNERS[:console] - end - - o.on_tail('--gtk', 'GTK runner (use --runner).') do - warn("Deprecated option (--gtk).") - @runner = RUNNERS[:gtk] - end - - o.on_tail('--fox', 'Fox runner (use --runner).') do - warn("Deprecated option (--fox).") - @runner = RUNNERS[:fox] - end - - o.on_tail - - begin - o.parse! - rescue OptionParser::ParseError => e - puts e - puts o - exit(1) - end + o.on('-h', '--help', 'Display this help.'){puts o; exit} + + o.on_tail + o.on_tail('Deprecated options:') + + o.on_tail('--console', 'Console runner (use --runner).') do + warn("Deprecated option (--console).") + @runner = RUNNERS[:console] end + + o.on_tail('--gtk', 'GTK runner (use --runner).') do + warn("Deprecated option (--gtk).") + @runner = RUNNERS[:gtk] + end + + o.on_tail('--fox', 'Fox runner (use --runner).') do + warn("Deprecated option (--fox).") + @runner = RUNNERS[:fox] + end + + o.on_tail end - @filters << proc{false} unless(@filters.empty?) end def keyword_display(array) @@ -179,7 +179,8 @@ module Test def run @suite = @collector[self] - @runner[self] + result = @runner[self] or return false + result.passed? end end end diff --git a/lib/test/unit/ui/fox/testrunner.rb b/lib/test/unit/ui/fox/testrunner.rb index 8b82ec634d..b3c0ce0e40 100644 --- a/lib/test/unit/ui/fox/testrunner.rb +++ b/lib/test/unit/ui/fox/testrunner.rb @@ -41,6 +41,7 @@ module Test @suite = suite end + @result = nil @red = false end @@ -50,6 +51,7 @@ module Test setup_mediator attach_to_mediator start_ui + @result end def setup_mediator # :nodoc: @@ -132,6 +134,7 @@ module Test end def started(result) # :nodoc: + @result = result output_status("Started...") end diff --git a/lib/test/unit/ui/gtk/testrunner.rb b/lib/test/unit/ui/gtk/testrunner.rb index d6ce527fe9..14fbce2573 100644 --- a/lib/test/unit/ui/gtk/testrunner.rb +++ b/lib/test/unit/ui/gtk/testrunner.rb @@ -33,6 +33,7 @@ module Test else @suite = suite end + @result = nil @runner = Thread.current @restart_signal = Class.new(Exception) @@ -49,6 +50,7 @@ module Test setup_ui attach_to_mediator start_ui + @result end private @@ -94,7 +96,6 @@ module Test retry rescue end - exit !@red end def stop(*) # :nodoc: @@ -145,6 +146,7 @@ module Test end def started(result) # :nodoc: + @result = result output_status("Started...") end diff --git a/lib/test/unit/ui/gtk2/testrunner.rb b/lib/test/unit/ui/gtk2/testrunner.rb index 1efc7dd758..c68d7a2059 100644 --- a/lib/test/unit/ui/gtk2/testrunner.rb +++ b/lib/test/unit/ui/gtk2/testrunner.rb @@ -322,6 +322,7 @@ module Test private :test_started def started(result) # :nodoc: + @result = result output_status("Started...") end # def started(result) private :started @@ -405,8 +406,8 @@ module Test rescue @restart_signal retry rescue + puts $!, $@ end - exit !@red end # def start_ui private :start_ui @@ -437,6 +438,7 @@ module Test setup_ui attach_to_mediator start_ui + @result end # def start def initialize(suite) @@ -445,6 +447,7 @@ module Test else @suite = suite end + @result = nil @runner = Thread.current @restart_signal = Class.new(Exception) diff --git a/lib/test/unit/ui/tk/testrunner.rb b/lib/test/unit/ui/tk/testrunner.rb index 3c3e0f554f..9e444ca9ac 100644 --- a/lib/test/unit/ui/tk/testrunner.rb +++ b/lib/test/unit/ui/tk/testrunner.rb @@ -34,6 +34,7 @@ module Test else @suite = suite end + @result = nil @red = false @fault_detail_list = [] @@ -52,6 +53,7 @@ module Test setup_mediator attach_to_mediator start_ui + @result end private @@ -102,7 +104,6 @@ module Test retry rescue end - exit !@red end def stop # :nodoc: @@ -112,7 +113,7 @@ module Test def reset_ui(count) # :nodoc: @test_total_count = count.to_f @test_progress_bar.configure('background'=>'green') - @test_progress_bar.place('relwidth'=>0/count) + @test_progress_bar.place('relwidth'=>(count.zero? ? 0 : 0/count)) @red = false @test_count_label.value = 0 @@ -155,6 +156,7 @@ module Test end def started(result) # :nodoc: + @result = result output_status("Started...") end -- cgit v1.2.3