diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2026-01-15 12:30:29 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2026-01-15 12:30:29 +0900 |
| commit | 886202bac80130ec6f2f3f67f306f9d5f860fb01 (patch) | |
| tree | 6d4e0b4c3ae560b73ef5395a028a6abbb4abf683 | |
| parent | 189bb64af8951d79bd812f2dca18a0104339b56e (diff) | |
Count assertions in child processes
Fix up GH-15785.
| -rw-r--r-- | tool/lib/core_assertions.rb | 3 | ||||
| -rw-r--r-- | tool/test/testunit/test_assertion.rb | 23 |
2 files changed, 24 insertions, 2 deletions
diff --git a/tool/lib/core_assertions.rb b/tool/lib/core_assertions.rb index 419704448b..e29a0e3c25 100644 --- a/tool/lib/core_assertions.rb +++ b/tool/lib/core_assertions.rb @@ -384,11 +384,10 @@ eom end raise if $! abort = status.coredump? || (status.signaled? && ABORT_SIGNALS.include?(status.termsig)) - assertions = 0 marshal_error = nil assert(!abort, FailDesc[status, nil, stderr]) res.scan(/^<error id="#{token_re}" assertions=(\d+)>\n(.*?)\n(?=<\/error id="#{token_re}">$)/m) do - assertions += $1.to_i + self._assertions += $1.to_i res = Marshal.load($2.unpack1("m")) or next rescue => marshal_error ignore_stderr = nil diff --git a/tool/test/testunit/test_assertion.rb b/tool/test/testunit/test_assertion.rb index 7b1f28a869..d9bdc8f3c5 100644 --- a/tool/test/testunit/test_assertion.rb +++ b/tool/test/testunit/test_assertion.rb @@ -17,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 |
