summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rwxr-xr-xbin/testrb4
-rw-r--r--lib/test/unit.rb43
-rw-r--r--test/runner.rb2
4 files changed, 46 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 86964ee..8e9158a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,7 @@
-Fri Jul 16 22:08:10 2010 Yusuke Endoh <mame@tsg.ne.jp>
+Sat Jul 17 10:07:52 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/test/unit.rb, bin/testrb, test/runner.rb: revert r28655, which
- broke test-all.
+ * lib/test/unit.rb: MiniTest::Unit is different class from
+ Test::Unit, and install runner before loading test/minitest.
Fri Jul 16 14:58:38 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
diff --git a/bin/testrb b/bin/testrb
index e4eb909..6a65fba 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 4aecc49..646fd5e 100644
--- a/lib/test/unit.rb
+++ b/lib/test/unit.rb
@@ -9,7 +9,20 @@ module Test
module Unit
TEST_UNIT_IMPLEMENTATION = 'test/unit compatibility layer using minitest'
- def self.setup_argv(original_argv=ARGV)
+ module RunCount
+ @@run_count = 0
+
+ def self.have_run?
+ @@run_count.nonzero?
+ end
+
+ def run(*)
+ @@run_count += 1
+ super
+ end
+ end
+
+ def self.setup_argv(original_argv=::ARGV)
minitest_argv = []
files = []
reject = []
@@ -55,6 +68,12 @@ module Test
reject_pat = Regexp.union(reject.map {|r| /#{r}/ })
files.reject! {|f| reject_pat =~ f }
+ MiniTest::Unit._install_at_exit {
+ next if RunCount.have_run?
+ next if $! # don't run if there was an exception
+ exit false unless run(minitest_argv)
+ }
+
files.each {|f|
d = File.dirname(path = File.expand_path(f))
unless $:.include? d
@@ -67,9 +86,27 @@ module Test
end
}
- ARGV.replace minitest_argv
+ 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
+class MiniTest::Unit
+ def self.new(*)
+ super.extend(Test::Unit::RunCount)
+ end
+
+ def self._install_at_exit(&block)
+ at_exit(&block) unless @@installed_at_exit
+ @@installed_at_exit = true
+ end
+end
diff --git a/test/runner.rb b/test/runner.rb
index 3f1c8ab..3735461 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