From 96863dc358cc86435099627a7afc1ec58a1fd79c Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 16 Jul 2010 05:58:39 +0000 Subject: [PATCH] * lib/test/unit.rb (Test::Unit.setup_argv): run tests only when any tests have not run. * bin/testrb, test/runner.rb: use Test::Unit.start. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ bin/testrb | 4 ++-- lib/test/unit.rb | 36 ++++++++++++++++++++++++++++++++---- test/runner.rb | 2 +- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc17791732..615edb681a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Jul 16 14:58:38 2010 Nobuyoshi Nakada + + * lib/test/unit.rb (Test::Unit.setup_argv): run tests only when + any tests have not run. + + * bin/testrb, test/runner.rb: use Test::Unit.start. + Fri Jul 16 12:06:08 2010 Nobuyoshi Nakada * tool/rbinstall.rb (ext-arch): prune directories start with '-'. diff --git a/bin/testrb b/bin/testrb index e4eb9099b3..6a65fba3fa 100755 --- a/bin/testrb +++ b/bin/testrb @@ -1,9 +1,9 @@ #!/usr/bin/env ruby require 'test/unit' -Test::Unit.setup_argv {|files| +exit Test::Unit.start {|files| if files.empty? puts "Usage: testrb [options] tests..." - exit 1 + exit false end if files.size == 1 $0 = File.basename(files[0]) diff --git a/lib/test/unit.rb b/lib/test/unit.rb index 4aecc49450..b518426893 100644 --- a/lib/test/unit.rb +++ b/lib/test/unit.rb @@ -9,7 +9,21 @@ module Test module Unit TEST_UNIT_IMPLEMENTATION = 'test/unit compatibility layer using minitest' - def self.setup_argv(original_argv=ARGV) + @@installed_at_exit = true + @@run_count = 0 + + RunCount = Module.new do + def run(*) + @@run_count += 1 + super + end + end + + def self.new(*) + super.extend(RunCount) + end + + def self.setup_argv(original_argv=::ARGV) minitest_argv = [] files = [] reject = [] @@ -67,9 +81,23 @@ module Test end } - ARGV.replace minitest_argv + at_exit { + next if @@run_count.nonzero? + next if $! # don't run if there was an exception + exit false unless run(minitest_argv) + } unless @@installed_at_exit + @@installed_at_exit = true + + minitest_argv + end + + def self.run(args) + exit_code = MiniTest::Unit.new.run(args) + !exit_code || exit_code == 0 + end + + def self.start(argv=::ARGV, &block) + run(setup_argv(argv, &block)) end end end - -MiniTest::Unit.autorun diff --git a/test/runner.rb b/test/runner.rb index 3f1c8abc19..3735461ba6 100644 --- a/test/runner.rb +++ b/test/runner.rb @@ -6,7 +6,7 @@ require 'test/unit' src_testdir = File.dirname(File.expand_path(__FILE__)) srcdir = File.dirname(src_testdir) -Test::Unit.setup_argv {|files| +exit Test::Unit.start {|files| if files.empty? [src_testdir] else