Skip to content

Commit fc0c67d

Browse files
committed
Make assert_separately to count assertions in forked processes
1 parent 364e25b commit fc0c67d

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

tool/lib/core_assertions.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,9 @@ def separated_runner(token, out = nil)
327327
at_exit {
328328
assertions = assertions_ivar_get.call(:@_assertions)
329329
out_write.call <<~OUT
330-
#{token}<error>
331-
#{array_pack.bind_call([marshal_dump.call($!)], 'm')}
332-
#{token}</error>
333-
#{token}assertions=#{integer_to_s.bind_call(assertions)}
330+
<error id="#{token}" assertions=#{integer_to_s.bind_call(assertions)}>
331+
#{array_pack.bind_call([marshal_dump.call($!)], 'm0')}
332+
</error id="#{token}">
334333
OUT
335334
}
336335
if defined?(Test::Unit::Runner)
@@ -385,17 +384,17 @@ def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **o
385384
end
386385
raise if $!
387386
abort = status.coredump? || (status.signaled? && ABORT_SIGNALS.include?(status.termsig))
387+
assertions = 0
388+
marshal_error = nil
388389
assert(!abort, FailDesc[status, nil, stderr])
389-
if (assertions = res[/^#{token_re}assertions=(\d+)/, 1].to_i) > 0
390-
self._assertions += assertions
391-
end
392-
begin
393-
res = Marshal.load(res[/^#{token_re}<error>\n\K.*\n(?=#{token_re}<\/error>$)/m].unpack1("m"))
390+
res.scan(/^<error id="#{token_re}" assertions=(\d+)>\n(.*?)\n(?=<\/error id="#{token_re}">$)/m) do
391+
assertions += $1.to_i
392+
res = Marshal.load($2.unpack1("m")) or next
394393
rescue => marshal_error
395394
ignore_stderr = nil
396395
res = nil
397-
end
398-
if res and !(SystemExit === res)
396+
else
397+
next if SystemExit === res
399398
if bt = res.backtrace
400399
bt.each do |l|
401400
l.sub!(/\A-:(\d+)/){"#{file}:#{line + $1.to_i}"}
@@ -407,7 +406,7 @@ def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **o
407406
raise res
408407
end
409408

410-
# really is it succeed?
409+
# really did it succeed?
411410
unless ignore_stderr
412411
# the body of assert_separately must not output anything to detect error
413412
assert(stderr.empty?, FailDesc[status, "assert_separately failed with error message", stderr])

0 commit comments

Comments
 (0)