* 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:
parent
76eab3527f
commit
086745b7d6
15
ChangeLog
15
ChangeLog
@ -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>
|
Tue Dec 2 20:03:20 2003 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* test/fileutils/test_fileutils.rb: check if Pathnames are usable
|
* test/fileutils/test_fileutils.rb: check if Pathnames are usable
|
||||||
|
5
bin/testrb
Executable file
5
bin/testrb
Executable 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
|
@ -272,4 +272,4 @@ module Test
|
|||||||
end
|
end
|
||||||
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?)}
|
||||||
|
@ -5,11 +5,11 @@ require 'test/unit/ui/console/testrunner'
|
|||||||
module Test
|
module Test
|
||||||
module Unit
|
module Unit
|
||||||
class AutoRunner
|
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)
|
if(!current_file || current_file == $0)
|
||||||
r = new(!current_file, &block)
|
r = new(!current_file, &block)
|
||||||
if(default_dir && r.to_run.empty?)
|
if !r.process_args(argv) && default_dir
|
||||||
r.to_run = default_dir
|
r.to_run << default_dir
|
||||||
end
|
end
|
||||||
r.run
|
r.run
|
||||||
end
|
end
|
||||||
@ -17,9 +17,7 @@ module Test
|
|||||||
|
|
||||||
RUNNERS = {
|
RUNNERS = {
|
||||||
:console => proc do |r|
|
:console => proc do |r|
|
||||||
output_level = r.output_level || Test::Unit::UI::Console::TestRunner::NORMAL
|
Test::Unit::UI::Console::TestRunner.run(r.suite, r.output_level)
|
||||||
passed = Test::Unit::UI::Console::TestRunner.run(r.suite, output_level).passed?
|
|
||||||
exit(passed ? 0 : 1)
|
|
||||||
end,
|
end,
|
||||||
:gtk => proc do |r|
|
:gtk => proc do |r|
|
||||||
require 'test/unit/ui/gtk/testrunner'
|
require 'test/unit/ui/gtk/testrunner'
|
||||||
@ -73,104 +71,106 @@ module Test
|
|||||||
@collector = COLLECTORS[(standalone ? :dir : :objectspace)]
|
@collector = COLLECTORS[(standalone ? :dir : :objectspace)]
|
||||||
@filters = []
|
@filters = []
|
||||||
@to_run = []
|
@to_run = []
|
||||||
process_args
|
@output_level = Test::Unit::UI::Console::TestRunner::NORMAL
|
||||||
yield(self) if(block_given?)
|
yield(self) if(block_given?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_args
|
def process_args(args = ARGV)
|
||||||
catch(:stop_processing) do
|
begin
|
||||||
ARGV.options do |o|
|
@to_run.concat options.parse!(args)
|
||||||
o.program_name = "test/unit.rb"
|
rescue OptionParser::ParseError => e
|
||||||
o.banner = "Test::Unit automatic runner."
|
puts e
|
||||||
o.banner = "#{$0} [options] [-- untouched arguments]"
|
puts options
|
||||||
|
$! = nil
|
||||||
|
abort
|
||||||
|
else
|
||||||
|
@filters << proc{false} unless(@filters.empty?)
|
||||||
|
end
|
||||||
|
not @to_run.empty?
|
||||||
|
end
|
||||||
|
|
||||||
o.on
|
def options
|
||||||
o.on('-r', '--runner=RUNNER', RUNNERS.keys,
|
@options ||= OptionParser.new do |o|
|
||||||
"Use the given RUNNER.",
|
o.banner = "Test::Unit automatic runner."
|
||||||
"(" + keyword_display(RUNNERS.keys) + ")") do |r|
|
o.banner << "\nUsage: #{$0} [options] [-- untouched arguments]"
|
||||||
@runner = RUNNERS[r]
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
if(@standalone)
|
o.on('-p', '--pattern=PATTERN', String,
|
||||||
o.on('-a', '--add=TORUN', Array,
|
"Match files to collect against PATTERN.") do |e|
|
||||||
"Add TORUN to the list of things to run;",
|
@pattern = Regexp.new(e.sub(%r{\A/(.*)/\Z}m, '\\1'))
|
||||||
"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)
|
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
@filters << proc{false} unless(@filters.empty?)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def keyword_display(array)
|
def keyword_display(array)
|
||||||
@ -179,7 +179,8 @@ module Test
|
|||||||
|
|
||||||
def run
|
def run
|
||||||
@suite = @collector[self]
|
@suite = @collector[self]
|
||||||
@runner[self]
|
result = @runner[self] or return false
|
||||||
|
result.passed?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -41,6 +41,7 @@ module Test
|
|||||||
@suite = suite
|
@suite = suite
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@result = nil
|
||||||
@red = false
|
@red = false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -50,6 +51,7 @@ module Test
|
|||||||
setup_mediator
|
setup_mediator
|
||||||
attach_to_mediator
|
attach_to_mediator
|
||||||
start_ui
|
start_ui
|
||||||
|
@result
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_mediator # :nodoc:
|
def setup_mediator # :nodoc:
|
||||||
@ -132,6 +134,7 @@ module Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def started(result) # :nodoc:
|
def started(result) # :nodoc:
|
||||||
|
@result = result
|
||||||
output_status("Started...")
|
output_status("Started...")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ module Test
|
|||||||
else
|
else
|
||||||
@suite = suite
|
@suite = suite
|
||||||
end
|
end
|
||||||
|
@result = nil
|
||||||
|
|
||||||
@runner = Thread.current
|
@runner = Thread.current
|
||||||
@restart_signal = Class.new(Exception)
|
@restart_signal = Class.new(Exception)
|
||||||
@ -49,6 +50,7 @@ module Test
|
|||||||
setup_ui
|
setup_ui
|
||||||
attach_to_mediator
|
attach_to_mediator
|
||||||
start_ui
|
start_ui
|
||||||
|
@result
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -94,7 +96,6 @@ module Test
|
|||||||
retry
|
retry
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
exit !@red
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop(*) # :nodoc:
|
def stop(*) # :nodoc:
|
||||||
@ -145,6 +146,7 @@ module Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def started(result) # :nodoc:
|
def started(result) # :nodoc:
|
||||||
|
@result = result
|
||||||
output_status("Started...")
|
output_status("Started...")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -322,6 +322,7 @@ module Test
|
|||||||
private :test_started
|
private :test_started
|
||||||
|
|
||||||
def started(result) # :nodoc:
|
def started(result) # :nodoc:
|
||||||
|
@result = result
|
||||||
output_status("Started...")
|
output_status("Started...")
|
||||||
end # def started(result)
|
end # def started(result)
|
||||||
private :started
|
private :started
|
||||||
@ -405,8 +406,8 @@ module Test
|
|||||||
rescue @restart_signal
|
rescue @restart_signal
|
||||||
retry
|
retry
|
||||||
rescue
|
rescue
|
||||||
|
puts $!, $@
|
||||||
end
|
end
|
||||||
exit !@red
|
|
||||||
end # def start_ui
|
end # def start_ui
|
||||||
private :start_ui
|
private :start_ui
|
||||||
|
|
||||||
@ -437,6 +438,7 @@ module Test
|
|||||||
setup_ui
|
setup_ui
|
||||||
attach_to_mediator
|
attach_to_mediator
|
||||||
start_ui
|
start_ui
|
||||||
|
@result
|
||||||
end # def start
|
end # def start
|
||||||
|
|
||||||
def initialize(suite)
|
def initialize(suite)
|
||||||
@ -445,6 +447,7 @@ module Test
|
|||||||
else
|
else
|
||||||
@suite = suite
|
@suite = suite
|
||||||
end
|
end
|
||||||
|
@result = nil
|
||||||
|
|
||||||
@runner = Thread.current
|
@runner = Thread.current
|
||||||
@restart_signal = Class.new(Exception)
|
@restart_signal = Class.new(Exception)
|
||||||
|
@ -34,6 +34,7 @@ module Test
|
|||||||
else
|
else
|
||||||
@suite = suite
|
@suite = suite
|
||||||
end
|
end
|
||||||
|
@result = nil
|
||||||
|
|
||||||
@red = false
|
@red = false
|
||||||
@fault_detail_list = []
|
@fault_detail_list = []
|
||||||
@ -52,6 +53,7 @@ module Test
|
|||||||
setup_mediator
|
setup_mediator
|
||||||
attach_to_mediator
|
attach_to_mediator
|
||||||
start_ui
|
start_ui
|
||||||
|
@result
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -102,7 +104,6 @@ module Test
|
|||||||
retry
|
retry
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
exit !@red
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop # :nodoc:
|
def stop # :nodoc:
|
||||||
@ -112,7 +113,7 @@ module Test
|
|||||||
def reset_ui(count) # :nodoc:
|
def reset_ui(count) # :nodoc:
|
||||||
@test_total_count = count.to_f
|
@test_total_count = count.to_f
|
||||||
@test_progress_bar.configure('background'=>'green')
|
@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
|
@red = false
|
||||||
|
|
||||||
@test_count_label.value = 0
|
@test_count_label.value = 0
|
||||||
@ -155,6 +156,7 @@ module Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def started(result) # :nodoc:
|
def started(result) # :nodoc:
|
||||||
|
@result = result
|
||||||
output_status("Started...")
|
output_status("Started...")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,7 +4,4 @@ rcsid = %w$Id$
|
|||||||
Version = rcsid[2].scan(/\d+/).collect!(&method(:Integer)).freeze
|
Version = rcsid[2].scan(/\d+/).collect!(&method(:Integer)).freeze
|
||||||
Release = rcsid[3].freeze
|
Release = rcsid[3].freeze
|
||||||
|
|
||||||
runner = Test::Unit::AutoRunner.new(true)
|
exit Test::Unit::AutoRunner.run(false, File.dirname($0))
|
||||||
runner.to_run.concat(ARGV)
|
|
||||||
runner.to_run << File.dirname(__FILE__) if runner.to_run.empty?
|
|
||||||
runner.run
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user