diff --git a/ChangeLog b/ChangeLog index 7fdfa7458d..63ec0ddf8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,35 @@ +Sun Jul 10 20:59:38 2011 Shota Fukumori + + * lib/test/unit.rb: Add new class variable `@@testfile_prefix`. + This is for changing test name prefix. (For testing) + + * test/testunit/tests_for_parallel/ptest_first.rb: Renamed from + test_first.rb + + * test/testunit/tests_for_parallel/ptest_second.rb: Renamed from + test_second.rb + + * test/testunit/tests_for_parallel/ptest_third.rb: Renamed from + test_third.rb + + * test/testunit/tests_for_parallel/ptest_forth.rb: Renamed from + test_forth.rb + + * test/testunit/tests_for_parallel/runner.rb: Remove misc.rb + + * test/testunit/tests_for_parallel/ptest_first.rb: ditto. + + * test/testunit/tests_for_parallel/ptest_second.rb: ditto. + + * test/testunit/tests_for_parallel/ptest_third.rb: ditto. + + * test/testunit/tests_for_parallel/ptest_forth.rb: ditto. + + * test/testunit/tests_for_parallel/misc.rb: Removed because no longer + needed. + + * test/testunit/test_parallel.rb: Fix assertions for above. + Sun Jul 10 16:57:08 2011 Koichi Sasada * vm_insnhelper.c (vm_throw): check a class frame. diff --git a/lib/test/unit.rb b/lib/test/unit.rb index af67a7aabd..5aa9cb9a88 100644 --- a/lib/test/unit.rb +++ b/lib/test/unit.rb @@ -126,6 +126,8 @@ module Test module GlobOption include Options + @@testfile_prefix = "test" + def setup_options(parser, options) super parser.on '-b', '--basedir=DIR', 'Base directory of test suites.' do |dir| @@ -150,7 +152,7 @@ module Test next if f.empty? path = f end - if !(match = Dir["#{path}/**/test_*.rb"]).empty? + if !(match = Dir["#{path}/**/#{@@testfile_prefix}_*.rb"]).empty? if reject match.reject! {|n| n[(prefix.length+1)..-1] if prefix diff --git a/test/testunit/test_parallel.rb b/test/testunit/test_parallel.rb index c8f6a9ec18..2af339b9d2 100644 --- a/test/testunit/test_parallel.rb +++ b/test/testunit/test_parallel.rb @@ -37,11 +37,10 @@ module TestParallel def test_run timeout(10) do assert_match(/^ready/,@worker_out.gets) - @worker_in.puts "run #{TESTS}/test_first.rb ptest" + @worker_in.puts "run #{TESTS}/ptest_first.rb test" assert_match(/^okay/,@worker_out.gets) assert_match(/^p/,@worker_out.gets) assert_match(/^done/,@worker_out.gets) - assert_match(/^done/,@worker_out.gets) assert_match(/^ready/,@worker_out.gets) end end @@ -49,13 +48,12 @@ module TestParallel def test_run_multiple_testcase_in_one_file timeout(10) do assert_match(/^ready/,@worker_out.gets) - @worker_in.puts "run #{TESTS}/test_second.rb ptest" + @worker_in.puts "run #{TESTS}/ptest_second.rb test" assert_match(/^okay/,@worker_out.gets) assert_match(/^p/,@worker_out.gets) assert_match(/^done/,@worker_out.gets) assert_match(/^p/,@worker_out.gets) assert_match(/^done/,@worker_out.gets) - assert_match(/^done/,@worker_out.gets) assert_match(/^ready/,@worker_out.gets) end end @@ -63,13 +61,12 @@ module TestParallel def test_accept_run_command_multiple_times timeout(10) do assert_match(/^ready/,@worker_out.gets) - @worker_in.puts "run #{TESTS}/test_first.rb ptest" + @worker_in.puts "run #{TESTS}/ptest_first.rb test" assert_match(/^okay/,@worker_out.gets) assert_match(/^p/,@worker_out.gets) assert_match(/^done/,@worker_out.gets) - assert_match(/^done/,@worker_out.gets) assert_match(/^ready/,@worker_out.gets) - @worker_in.puts "run #{TESTS}/test_second.rb ptest" + @worker_in.puts "run #{TESTS}/ptest_second.rb test" assert_match(/^okay/,@worker_out.gets) assert_match(/^p/,@worker_out.gets) assert_match(/^done/,@worker_out.gets) @@ -81,24 +78,23 @@ module TestParallel def test_p timeout(10) do - @worker_in.puts "run #{TESTS}/test_first.rb ptest" + @worker_in.puts "run #{TESTS}/ptest_first.rb test" while buf = @worker_out.gets break if /^p (.+?)$/ =~ buf end - assert_match(/TestA#ptest_nothing_test = \d+\.\d+ s = \.\n/, $1.chomp.unpack("m")[0]) + assert_match(/TestA#test_nothing_test = \d+\.\d+ s = \.\n/, $1.chomp.unpack("m")[0]) end end def test_done timeout(10) do - @worker_in.puts "run #{TESTS}/test_forth.rb ptest" + @worker_in.puts "run #{TESTS}/ptest_forth.rb test" i = 0 - while buf = @worker_out.gets - if /^done (.+?)$/ =~ buf - i += 1 - break if i == 2 # Break at 2nd "done" - end - end + 5.times { @worker_out.gets } + buf = @worker_out.gets + assert_match(/^done (.+?)$/, buf) + + /^done (.+?)$/ =~ buf result = Marshal.load($1.chomp.unpack("m")[0]) @@ -107,8 +103,8 @@ module TestParallel assert_kind_of(Array,result[2]) assert_kind_of(Array,result[3]) assert_kind_of(Array,result[4]) - assert_match(/Skipped:$/,result[2][0]) - assert_match(/Failure:$/,result[2][1]) + assert_match(/Skipped:$/,result[2][1]) + assert_match(/Failure:$/,result[2][0]) assert_equal(result[5], "TestE") end end @@ -169,13 +165,13 @@ module TestParallel spawn_runner "--no-retry" buf = timeout(10){@test_out.read} refute_match(/^Retrying\.+$/,buf) - assert_match(/^ +\d+\) Failure:\nptest_fail_at_worker\(TestD\)/,buf) + assert_match(/^ +\d+\) Failure:\ntest_fail_at_worker\(TestD\)/,buf) end def test_jobs_status spawn_runner "--jobs-status" buf = timeout(10){@test_out.read} - assert_match(/\d+=test_(first|second|third|forth) */,buf) + assert_match(/\d+=ptest_(first|second|third|forth) */,buf) end end diff --git a/test/testunit/tests_for_parallel/misc.rb b/test/testunit/tests_for_parallel/misc.rb deleted file mode 100644 index f60b25d6c3..0000000000 --- a/test/testunit/tests_for_parallel/misc.rb +++ /dev/null @@ -1,36 +0,0 @@ -# FIXME: more portability code -if caller(7) && /block in non_options/ =~ caller(7)[0] - class TestCaseForParallelTest < Test::Unit::TestCase;end -else - module Test - module Unit - class Worker - def run_tests - _run_anything :ptest - end - end - class Runner - def run_tests - _run_anything :ptest - end - end - end - end - module MiniTest - class Unit - class << TestCase - alias ptest_suites test_suites - def ptest_methods;[];end - end - end - end - - class TestCaseForParallelTest < Test::Unit::TestCase - class << self - undef ptest_methods - def ptest_methods - public_instance_methods(true).grep(/^ptest/).map { |m| m.to_s } - end - end - end -end diff --git a/test/testunit/tests_for_parallel/ptest_first.rb b/test/testunit/tests_for_parallel/ptest_first.rb new file mode 100644 index 0000000000..66c7704a45 --- /dev/null +++ b/test/testunit/tests_for_parallel/ptest_first.rb @@ -0,0 +1,7 @@ +require 'test/unit' + +class TestA < Test::Unit::TestCase + def test_nothing_test + end +end + diff --git a/test/testunit/tests_for_parallel/ptest_forth.rb b/test/testunit/tests_for_parallel/ptest_forth.rb new file mode 100644 index 0000000000..c778a2ecc9 --- /dev/null +++ b/test/testunit/tests_for_parallel/ptest_forth.rb @@ -0,0 +1,16 @@ +require 'test/unit' + +class TestE < Test::Unit::TestCase + def test_not_fail + assert_equal(1,1) + end + + def test_always_skip + skip "always" + end + + def test_always_fail + assert_equal(0,1) + end +end + diff --git a/test/testunit/tests_for_parallel/ptest_second.rb b/test/testunit/tests_for_parallel/ptest_second.rb new file mode 100644 index 0000000000..7004d68493 --- /dev/null +++ b/test/testunit/tests_for_parallel/ptest_second.rb @@ -0,0 +1,11 @@ +require 'test/unit' + +class TestB < Test::Unit::TestCase + def test_nothing + end +end + +class TestC < Test::Unit::TestCase + def test_nothing + end +end diff --git a/test/testunit/tests_for_parallel/test_third.rb b/test/testunit/tests_for_parallel/ptest_third.rb similarity index 58% rename from test/testunit/tests_for_parallel/test_third.rb rename to test/testunit/tests_for_parallel/ptest_third.rb index 61124b291a..338fc32a91 100644 --- a/test/testunit/tests_for_parallel/test_third.rb +++ b/test/testunit/tests_for_parallel/ptest_third.rb @@ -1,8 +1,7 @@ require 'test/unit' -require_relative "misc.rb" -class TestD < TestCaseForParallelTest - def ptest_fail_at_worker +class TestD < Test::Unit::TestCase + def test_fail_at_worker #if /test\/unit\/parallel\.rb/ =~ $0 if on_parallel_worker? assert_equal(0,1) diff --git a/test/testunit/tests_for_parallel/runner.rb b/test/testunit/tests_for_parallel/runner.rb index 88413effc5..261880ad2b 100644 --- a/test/testunit/tests_for_parallel/runner.rb +++ b/test/testunit/tests_for_parallel/runner.rb @@ -1,7 +1,10 @@ require 'rbconfig' require 'test/unit' -require_relative 'misc' src_testdir = File.dirname(File.expand_path(__FILE__)) +class Test::Unit::Runner + @@testfile_prefix = "ptest" +end + exit Test::Unit::AutoRunner.run(true, src_testdir) diff --git a/test/testunit/tests_for_parallel/test_first.rb b/test/testunit/tests_for_parallel/test_first.rb deleted file mode 100644 index 93fcd67e8e..0000000000 --- a/test/testunit/tests_for_parallel/test_first.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'test/unit' -require_relative "misc.rb" - -class TestA < TestCaseForParallelTest - def ptest_nothing_test - end -end - diff --git a/test/testunit/tests_for_parallel/test_forth.rb b/test/testunit/tests_for_parallel/test_forth.rb deleted file mode 100644 index 9a4e66f390..0000000000 --- a/test/testunit/tests_for_parallel/test_forth.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'test/unit' -require_relative "misc.rb" - -class TestE < TestCaseForParallelTest - def ptest_not_fail - assert_equal(1,1) - end - - def ptest_always_skip - skip "always" - end - - def ptest_always_fail - assert_equal(0,1) - end -end - diff --git a/test/testunit/tests_for_parallel/test_second.rb b/test/testunit/tests_for_parallel/test_second.rb deleted file mode 100644 index fbc24a8793..0000000000 --- a/test/testunit/tests_for_parallel/test_second.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'test/unit' -require_relative "misc.rb" - -class TestB < TestCaseForParallelTest - def ptest_nothing - end -end - -class TestC < TestCaseForParallelTest - def ptest_nothing - end -end