1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2003-12-02 12:31:44 +00:00
parent 76eab3527f
commit 086745b7d6
9 changed files with 133 additions and 105 deletions

View file

@ -1,3 +1,18 @@
Tue Dec 2 21:31:42 2003 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* 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.
Tue Dec 2 20:03:20 2003 Minero Aoki <aamine@loveruby.net>
* test/fileutils/test_fileutils.rb: check if Pathnames are usable

5
bin/testrb Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env ruby
require 'test/unit'
(r = Test::Unit::AutoRunner.new(true)).process_args(ARGV) or
abort r.options.banner + " tests..."
exit r.run

View file

@ -272,4 +272,4 @@ module Test
end
end
at_exit{Test::Unit::AutoRunner.run($0) unless($! || Test::Unit.run?)}
at_exit{exit(Test::Unit::AutoRunner.run($0)) unless($! || Test::Unit.run?)}

View file

@ -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]"
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
o.on
o.on('-r', '--runner=RUNNER', RUNNERS.keys,
"Use the given RUNNER.",
"(" + keyword_display(RUNNERS.keys) + ")") do |r|
@runner = RUNNERS[r]
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
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
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
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('-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('--',
"Stop processing options so that the",
"remaining options will be passed to the",
"test."){throw :stop_processing}
o.on('-h', '--help', 'Display this help.'){puts o; exit(0)}
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)
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
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
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('-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('--',
"Stop processing options so that the",
"remaining options will be passed to the",
"test."){o.terminate}
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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -4,7 +4,4 @@ rcsid = %w$Id$
Version = rcsid[2].scan(/\d+/).collect!(&method(:Integer)).freeze
Release = rcsid[3].freeze
runner = Test::Unit::AutoRunner.new(true)
runner.to_run.concat(ARGV)
runner.to_run << File.dirname(__FILE__) if runner.to_run.empty?
runner.run
exit Test::Unit::AutoRunner.run(false, File.dirname($0))