diff options
Diffstat (limited to 'tool/test/testunit')
-rw-r--r-- | tool/test/testunit/test4test_hideskip.rb | 8 | ||||
-rw-r--r-- | tool/test/testunit/test4test_load_failure.rb | 1 | ||||
-rw-r--r-- | tool/test/testunit/test4test_sorting.rb | 2 | ||||
-rw-r--r-- | tool/test/testunit/test4test_timeout.rb | 15 | ||||
-rw-r--r-- | tool/test/testunit/test_assertion.rb | 24 | ||||
-rw-r--r-- | tool/test/testunit/test_hideskip.rb | 8 | ||||
-rw-r--r-- | tool/test/testunit/test_launchable.rb | 69 | ||||
-rw-r--r-- | tool/test/testunit/test_load_failure.rb | 23 | ||||
-rw-r--r-- | tool/test/testunit/test_minitest_unit.rb | 24 | ||||
-rw-r--r-- | tool/test/testunit/test_parallel.rb | 29 | ||||
-rw-r--r-- | tool/test/testunit/test_sorting.rb | 2 | ||||
-rw-r--r-- | tool/test/testunit/test_timeout.rb | 10 | ||||
-rw-r--r-- | tool/test/testunit/tests_for_parallel/slow_helper.rb | 8 | ||||
-rw-r--r-- | tool/test/testunit/tests_for_parallel/test4test_slow_0.rb | 5 | ||||
-rw-r--r-- | tool/test/testunit/tests_for_parallel/test4test_slow_1.rb | 5 |
15 files changed, 207 insertions, 26 deletions
diff --git a/tool/test/testunit/test4test_hideskip.rb b/tool/test/testunit/test4test_hideskip.rb index 410bffc13c..14f79a5743 100644 --- a/tool/test/testunit/test4test_hideskip.rb +++ b/tool/test/testunit/test4test_hideskip.rb @@ -4,7 +4,11 @@ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" require 'test/unit' class TestForTestHideSkip < Test::Unit::TestCase - def test_skip - skip "do nothing" + def test_omit + omit "do nothing" + end + + def test_pend + pend "do nothing" end end diff --git a/tool/test/testunit/test4test_load_failure.rb b/tool/test/testunit/test4test_load_failure.rb new file mode 100644 index 0000000000..e1570c2542 --- /dev/null +++ b/tool/test/testunit/test4test_load_failure.rb @@ -0,0 +1 @@ +raise LoadError, "no-such-library" diff --git a/tool/test/testunit/test4test_sorting.rb b/tool/test/testunit/test4test_sorting.rb index 698c875b79..f5a6866425 100644 --- a/tool/test/testunit/test4test_sorting.rb +++ b/tool/test/testunit/test4test_sorting.rb @@ -5,7 +5,7 @@ require 'test/unit' class TestForTestHideSkip < Test::Unit::TestCase def test_c - skip "do nothing" + omit "do nothing" end def test_b diff --git a/tool/test/testunit/test4test_timeout.rb b/tool/test/testunit/test4test_timeout.rb new file mode 100644 index 0000000000..3225f66398 --- /dev/null +++ b/tool/test/testunit/test4test_timeout.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" + +require 'test/unit' +require 'timeout' + +class TestForTestTimeout < Test::Unit::TestCase + 10.times do |i| + define_method("test_timeout_#{i}") do + Timeout.timeout(0.001) do + sleep + end + end + end +end diff --git a/tool/test/testunit/test_assertion.rb b/tool/test/testunit/test_assertion.rb index 8c83b447a7..709b495572 100644 --- a/tool/test/testunit/test_assertion.rb +++ b/tool/test/testunit/test_assertion.rb @@ -26,4 +26,28 @@ class TestAssertion < Test::Unit::TestCase return_in_assert_raise end end + + def test_assert_pattern_list + assert_pattern_list([/foo?/], "foo") + assert_not_pattern_list([/foo?/], "afoo") + assert_not_pattern_list([/foo?/], "foo?") + assert_pattern_list([:*, /foo?/, :*], "foo") + assert_pattern_list([:*, /foo?/], "afoo") + assert_not_pattern_list([:*, /foo?/], "afoo?") + assert_pattern_list([/foo?/, :*], "foo?") + + assert_not_pattern_list(["foo?"], "foo") + assert_not_pattern_list(["foo?"], "afoo") + assert_pattern_list(["foo?"], "foo?") + assert_not_pattern_list([:*, "foo?", :*], "foo") + assert_not_pattern_list([:*, "foo?"], "afoo") + assert_pattern_list([:*, "foo?"], "afoo?") + assert_pattern_list(["foo?", :*], "foo?") + end + + def assert_not_pattern_list(pattern_list, actual, message=nil) + assert_raise(Test::Unit::AssertionFailedError) do + assert_pattern_list(pattern_list, actual, message) + end + end end diff --git a/tool/test/testunit/test_hideskip.rb b/tool/test/testunit/test_hideskip.rb index e90be5da32..0c4c9b40f2 100644 --- a/tool/test/testunit/test_hideskip.rb +++ b/tool/test/testunit/test_hideskip.rb @@ -4,16 +4,16 @@ require 'test/unit' class TestHideSkip < Test::Unit::TestCase def test_hideskip assert_not_match(/^ *1\) Skipped/, hideskip) - assert_match(/^ *1\) Skipped/, hideskip("--show-skip")) + assert_match(/^ *1\) Skipped.*^ *2\) Skipped/m, hideskip("--show-skip")) output = hideskip("--hide-skip") - output.gsub!(/Successful MJIT finish\n/, '') if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? - assert_match(/assertions\/s.\n+1 tests, 0 assertions, 0 failures, 0 errors, 1 skips/, output) + output.gsub!(/Successful RJIT finish\n/, '') if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled? + assert_match(/assertions\/s.\n+2 tests, 0 assertions, 0 failures, 0 errors, 2 skips/, output) end private def hideskip(*args) - IO.popen([*@options[:ruby], "#{File.dirname(__FILE__)}/test4test_hideskip.rb", + IO.popen([*@__runner_options__[:ruby], "#{File.dirname(__FILE__)}/test4test_hideskip.rb", "--verbose", *args], err: [:child, :out]) {|f| f.read } diff --git a/tool/test/testunit/test_launchable.rb b/tool/test/testunit/test_launchable.rb new file mode 100644 index 0000000000..70c371e212 --- /dev/null +++ b/tool/test/testunit/test_launchable.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: false +require 'test/unit' +require 'tempfile' +require 'json' + +class TestLaunchable < Test::Unit::TestCase + def test_json_stream_writer + Tempfile.create(['launchable-test-', '.json']) do |f| + json_stream_writer = Test::Unit::LaunchableOption::JsonStreamWriter.new(f.path) + json_stream_writer.write_array('testCases') + json_stream_writer.write_object( + { + testPath: "file=test/test_a.rb#class=class1#testcase=testcase899", + duration: 42, + status: "TEST_FAILED", + stdout: nil, + stderr: nil, + createdAt: "2021-10-05T12:34:00", + data: { + lineNumber: 1 + } + } + ) + json_stream_writer.write_object( + { + testPath: "file=test/test_a.rb#class=class1#testcase=testcase899", + duration: 45, + status: "TEST_PASSED", + stdout: "This is stdout", + stderr: "This is stderr", + createdAt: "2021-10-05T12:36:00", + data: { + lineNumber: 10 + } + } + ) + json_stream_writer.close() + expected = <<JSON +{ + "testCases": [ + { + "testPath": "file=test/test_a.rb#class=class1#testcase=testcase899", + "duration": 42, + "status": "TEST_FAILED", + "stdout": null, + "stderr": null, + "createdAt": "2021-10-05T12:34:00", + "data": { + "lineNumber": 1 + } + }, + { + "testPath": "file=test/test_a.rb#class=class1#testcase=testcase899", + "duration": 45, + "status": "TEST_PASSED", + "stdout": "This is stdout", + "stderr": "This is stderr", + "createdAt": "2021-10-05T12:36:00", + "data": { + "lineNumber": 10 + } + } + ] +} +JSON + assert_equal(expected, f.read) + end + end +end diff --git a/tool/test/testunit/test_load_failure.rb b/tool/test/testunit/test_load_failure.rb new file mode 100644 index 0000000000..8defa9e39a --- /dev/null +++ b/tool/test/testunit/test_load_failure.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true +require 'test/unit' + +class TestLoadFailure < Test::Unit::TestCase + def test_load_failure + assert_not_predicate(load_failure, :success?) + end + + def test_load_failure_parallel + assert_not_predicate(load_failure("-j2"), :success?) + end + + private + + def load_failure(*args) + IO.popen([*@__runner_options__[:ruby], "#{__dir__}/../runner.rb", + "#{__dir__}/test4test_load_failure.rb", + "--verbose", *args], err: [:child, :out]) {|f| + assert_include(f.read, "test4test_load_failure.rb") + } + $? + end +end diff --git a/tool/test/testunit/test_minitest_unit.rb b/tool/test/testunit/test_minitest_unit.rb index 5941392fa0..84b6cf688c 100644 --- a/tool/test/testunit/test_minitest_unit.rb +++ b/tool/test/testunit/test_minitest_unit.rb @@ -171,7 +171,7 @@ class TestMiniTestUnit < MetaMetaMetaTestCase def test_passed_eh_teardown_skipped test_class = Class.new Test::Unit::TestCase do def teardown; assert true; end - def test_omg; skip "bork"; end + def test_omg; omit "bork"; end end test = test_class.new :test_omg @@ -896,7 +896,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase begin raise "blah" rescue - skip "skipped" + omit "skipped" end end end @@ -1323,11 +1323,19 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase end end - def test_skip + def test_omit @assertion_count = 0 util_assert_triggered "haha!", Test::Unit::PendedError do - @tc.skip "haha!" + @tc.omit "haha!" + end + end + + def test_pend + @assertion_count = 0 + + util_assert_triggered "haha!", Test::Unit::PendedError do + @tc.pend "haha!" end end @@ -1467,7 +1475,13 @@ class TestMiniTestUnitRecording < MetaMetaMetaTestCase def test_record_skip assert_run_record Test::Unit::PendedError do def test_method - skip "not yet" + omit "not yet" + end + end + + assert_run_record Test::Unit::PendedError do + def test_method + pend "not yet" end end end diff --git a/tool/test/testunit/test_parallel.rb b/tool/test/testunit/test_parallel.rb index 56ebb7df90..6882fd6c5f 100644 --- a/tool/test/testunit/test_parallel.rb +++ b/tool/test/testunit/test_parallel.rb @@ -6,14 +6,14 @@ module TestParallel PARALLEL_RB = "#{__dir__}/../../lib/test/unit/parallel.rb" TESTS = "#{__dir__}/tests_for_parallel" # use large timeout for --jit-wait - TIMEOUT = EnvUtil.apply_timeout_scale(defined?(RubyVM::JIT) && RubyVM::JIT.enabled? ? 100 : 30) + TIMEOUT = EnvUtil.apply_timeout_scale(defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled? ? 100 : 30) class TestParallelWorker < Test::Unit::TestCase def setup i, @worker_in = IO.pipe @worker_out, o = IO.pipe - @worker_pid = spawn(*@options[:ruby], PARALLEL_RB, - "--ruby", @options[:ruby].join(" "), + @worker_pid = spawn(*@__runner_options__[:ruby], PARALLEL_RB, + "--ruby", @__runner_options__[:ruby].join(" "), "-j", "t1", "-v", out: o, in: i) [i,o].each(&:close) end @@ -119,7 +119,7 @@ module TestParallel result = Marshal.load($1.chomp.unpack1("m")) assert_equal(5, result[0]) - pend "TODO: result[1] returns 17. We should investigate it" do + pend "TODO: result[1] returns 17. We should investigate it" do # TODO: misusage of pend (pend doens't use given block) assert_equal(12, result[1]) end assert_kind_of(Array,result[2]) @@ -143,11 +143,11 @@ module TestParallel end class TestParallel < Test::Unit::TestCase - def spawn_runner(*opt_args) + def spawn_runner(*opt_args, jobs: "t1") @test_out, o = IO.pipe - @test_pid = spawn(*@options[:ruby], TESTS+"/runner.rb", - "--ruby", @options[:ruby].join(" "), - "-j","t1",*opt_args, out: o, err: o) + @test_pid = spawn(*@__runner_options__[:ruby], TESTS+"/runner.rb", + "--ruby", @__runner_options__[:ruby].join(" "), + "-j", jobs, *opt_args, out: o, err: o) o.close end @@ -166,11 +166,7 @@ module TestParallel end def test_ignore_jzero - @test_out, o = IO.pipe - @test_pid = spawn(*@options[:ruby], TESTS+"/runner.rb", - "--ruby", @options[:ruby].join(" "), - "-j","0", out: File::NULL, err: o) - o.close + spawn_runner(jobs: "0") Timeout.timeout(TIMEOUT) { assert_match(/Error: parameter of -j option should be greater than 0/,@test_out.read) } @@ -215,5 +211,12 @@ module TestParallel assert_match(/^Retrying hung up testcases\.+$/, buf) assert_match(/^2 tests,.* 0 failures,/, buf) end + + def test_retry_workers + spawn_runner "--worker-timeout=1", "test4test_slow_0.rb", "test4test_slow_1.rb", jobs: "2" + buf = Timeout.timeout(TIMEOUT) {@test_out.read} + assert_match(/^Retrying hung up testcases\.+$/, buf) + assert_match(/^2 tests,.* 0 failures,/, buf) + end end end diff --git a/tool/test/testunit/test_sorting.rb b/tool/test/testunit/test_sorting.rb index 7678249ec2..3e5d7bfdcc 100644 --- a/tool/test/testunit/test_sorting.rb +++ b/tool/test/testunit/test_sorting.rb @@ -10,7 +10,7 @@ class TestTestUnitSorting < Test::Unit::TestCase end def sorting(*args) - IO.popen([*@options[:ruby], "#{File.dirname(__FILE__)}/test4test_sorting.rb", + IO.popen([*@__runner_options__[:ruby], "#{File.dirname(__FILE__)}/test4test_sorting.rb", "--verbose", *args], err: [:child, :out]) {|f| f.read } diff --git a/tool/test/testunit/test_timeout.rb b/tool/test/testunit/test_timeout.rb new file mode 100644 index 0000000000..452f5e1a7e --- /dev/null +++ b/tool/test/testunit/test_timeout.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: false +require 'test/unit' + +class TestTiemout < Test::Unit::TestCase + def test_timeout + cmd = [*@__runner_options__[:ruby], "#{File.dirname(__FILE__)}/test4test_timeout.rb"] + result = IO.popen(cmd, err: [:child, :out], &:read) + assert_not_match(/^T{10}$/, result) + end +end diff --git a/tool/test/testunit/tests_for_parallel/slow_helper.rb b/tool/test/testunit/tests_for_parallel/slow_helper.rb new file mode 100644 index 0000000000..38067c1f47 --- /dev/null +++ b/tool/test/testunit/tests_for_parallel/slow_helper.rb @@ -0,0 +1,8 @@ +require 'test/unit' + +module TestSlowTimeout + def test_slow + sleep_for = EnvUtil.apply_timeout_scale((ENV['sec'] || 3).to_i) + sleep sleep_for if on_parallel_worker? + end +end diff --git a/tool/test/testunit/tests_for_parallel/test4test_slow_0.rb b/tool/test/testunit/tests_for_parallel/test4test_slow_0.rb new file mode 100644 index 0000000000..a749b0e1d3 --- /dev/null +++ b/tool/test/testunit/tests_for_parallel/test4test_slow_0.rb @@ -0,0 +1,5 @@ +require_relative 'slow_helper' + +class TestSlowV0 < Test::Unit::TestCase + include TestSlowTimeout +end diff --git a/tool/test/testunit/tests_for_parallel/test4test_slow_1.rb b/tool/test/testunit/tests_for_parallel/test4test_slow_1.rb new file mode 100644 index 0000000000..924a3b11fa --- /dev/null +++ b/tool/test/testunit/tests_for_parallel/test4test_slow_1.rb @@ -0,0 +1,5 @@ +require_relative 'slow_helper' + +class TestSlowV1 < Test::Unit::TestCase + include TestSlowTimeout +end |