diff options
Diffstat (limited to 'tool/test/testunit')
| -rw-r--r-- | tool/test/testunit/test_assertion.rb | 25 | ||||
| -rw-r--r-- | tool/test/testunit/test_minitest_unit.rb | 9 | ||||
| -rw-r--r-- | tool/test/testunit/test_parallel.rb | 6 |
3 files changed, 33 insertions, 7 deletions
diff --git a/tool/test/testunit/test_assertion.rb b/tool/test/testunit/test_assertion.rb index b0c2267b31..d9bdc8f3c5 100644 --- a/tool/test/testunit/test_assertion.rb +++ b/tool/test/testunit/test_assertion.rb @@ -8,6 +8,8 @@ class TestAssertion < Test::Unit::TestCase end def test_timeout_separately + pend "hang-up" if /mswin|mingw/ =~ RUBY_PLATFORM + assert_raise(Timeout::Error) do assert_separately([], <<~"end;", timeout: 0.1) sleep @@ -15,6 +17,29 @@ class TestAssertion < Test::Unit::TestCase end end + def test_assertion_count_separately + beginning = self._assertions + + assert_separately([], "") + assertions_at_nothing = self._assertions - beginning + + prev_assertions = self._assertions + assertions_at_nothing + assert_separately([], "assert true") + assert_equal(1, self._assertions - prev_assertions) + + omit unless Process.respond_to?(:fork) + prev_assertions = self._assertions + assertions_at_nothing + assert_separately([], "Process.fork {assert true}; assert true") + assert_equal(2, self._assertions - prev_assertions) + + prev_assertions = self._assertions + assertions_at_nothing + # TODO: assertions before `fork` are counted twice; it is possible + # to reset `_assertions` at `Process._fork`, but the hook can + # interfere in other tests. + assert_separately([], "assert true; Process.fork {assert true}") + assert_equal(3, self._assertions - prev_assertions) + end + def return_in_assert_raise assert_raise(RuntimeError) do return diff --git a/tool/test/testunit/test_minitest_unit.rb b/tool/test/testunit/test_minitest_unit.rb index 84b6cf688c..7f53e4b7dd 100644 --- a/tool/test/testunit/test_minitest_unit.rb +++ b/tool/test/testunit/test_minitest_unit.rb @@ -646,7 +646,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase def test_assert_in_delta_triggered x = "1.0e-06" - util_assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do + util_assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}.", strip: /\s+\(\/proc\/loadavg=.*\)/ do @tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001 end end @@ -678,7 +678,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase end def test_assert_in_epsilon_triggered - util_assert_triggered 'Expected |10000 - 9990| (10) to be <= 9.99.' do + util_assert_triggered 'Expected |10000 - 9990| (10) to be <= 9.99.', strip: /\s+\(\/proc\/loadavg=.*\)/ do @tc.assert_in_epsilon 10000, 9990 end end @@ -686,7 +686,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase def test_assert_in_epsilon_triggered_negative_case x = "0.100000xxx" y = "0.1" - util_assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do + util_assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}.", strip: /\s+\(\/proc\/loadavg=.*\)/ do @tc.assert_in_epsilon(-1.1, -1, 0.1) end end @@ -1352,7 +1352,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase assert_equal expected, sample_test_case.test_methods.sort end - def assert_triggered expected, klass = Test::Unit::AssertionFailedError + def assert_triggered expected, klass = Test::Unit::AssertionFailedError, strip: nil e = assert_raise klass do yield end @@ -1360,6 +1360,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase msg = e.message.sub(/(---Backtrace---).*/m, '\1') msg.gsub!(/\(oid=[-0-9]+\)/, '(oid=N)') msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform + msg.gsub!(strip, '') if strip assert_equal expected, msg end diff --git a/tool/test/testunit/test_parallel.rb b/tool/test/testunit/test_parallel.rb index d87e0ed327..adf7d62ecd 100644 --- a/tool/test/testunit/test_parallel.rb +++ b/tool/test/testunit/test_parallel.rb @@ -151,9 +151,9 @@ module TestParallel end class TestParallel < Test::Unit::TestCase - def spawn_runner(*opt_args, jobs: "t1") + def spawn_runner(*opt_args, jobs: "t1", env: {}) @test_out, o = IO.pipe - @test_pid = spawn(*@__runner_options__[:ruby], TESTS+"/runner.rb", + @test_pid = spawn(env, *@__runner_options__[:ruby], TESTS+"/runner.rb", "--ruby", @__runner_options__[:ruby].join(" "), "-j", jobs, *opt_args, out: o, err: o) o.close @@ -214,7 +214,7 @@ module TestParallel end def test_hungup - spawn_runner "--worker-timeout=1", "--retry", "test4test_hungup.rb" + spawn_runner("--worker-timeout=1", "--retry", "test4test_hungup.rb", env: {"RUBY_CRASH_REPORT"=>nil}) buf = ::TestParallel.timeout(TIMEOUT) {@test_out.read} assert_match(/^Retrying hung up testcases\.+$/, buf) assert_match(/^2 tests,.* 0 failures,/, buf) |
