Count assertions in child processes

Fix up GH-15785.
This commit is contained in:
Nobuyoshi Nakada 2026-01-15 12:30:29 +09:00
parent 189bb64af8
commit 886202bac8
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2026-01-15 04:02:30 +00:00
2 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -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