Skip to content

Commit cd17c19

Browse files
committed
Count assertions in child processes
Fix up rubyGH-15785.
1 parent 189bb64 commit cd17c19

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

tool/lib/core_assertions.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,10 @@ def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **o
384384
end
385385
raise if $!
386386
abort = status.coredump? || (status.signaled? && ABORT_SIGNALS.include?(status.termsig))
387-
assertions = 0
388387
marshal_error = nil
389388
assert(!abort, FailDesc[status, nil, stderr])
390389
res.scan(/^<error id="#{token_re}" assertions=(\d+)>\n(.*?)\n(?=<\/error id="#{token_re}">$)/m) do
391-
assertions += $1.to_i
390+
@_assertions += $1.to_i
392391
res = Marshal.load($2.unpack1("m")) or next
393392
rescue => marshal_error
394393
ignore_stderr = nil

tool/test/testunit/test_assertion.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ def test_timeout_separately
1717
end
1818
end
1919

20+
def test_assertion_count_separately
21+
beginning = self._assertions
22+
23+
assert_separately([], "")
24+
assertions_at_nothing = self._assertions - beginning
25+
26+
prev_assertions = self._assertions + assertions_at_nothing
27+
assert_separately([], "assert true")
28+
assert_equal(1, self._assertions - prev_assertions)
29+
30+
omit unless Process.respond_to?(:fork)
31+
prev_assertions = self._assertions + assertions_at_nothing
32+
assert_separately([], "Process.fork {assert true}; assert true")
33+
assert_equal(2, self._assertions - prev_assertions)
34+
35+
prev_assertions = self._assertions + assertions_at_nothing
36+
# TODO: assertions before `fork` are counted twice; it is possible
37+
# to reset `_assertions` at `Process._fork`, but the hook can
38+
# interfere in other tests.
39+
assert_separately([], "assert true; Process.fork {assert true}")
40+
assert_equal(3, self._assertions - prev_assertions)
41+
end
42+
2043
def return_in_assert_raise
2144
assert_raise(RuntimeError) do
2245
return

0 commit comments

Comments
 (0)