ci: show each failed named test's last output lines

The events file is not kept, so the job log showed which tests failed but
not why. The gate now prints the last 40 output lines of every named test
that did not pass. Control: a failed test's reason line appears.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-26 01:53:36 -08:00
1 parent 144ad93c06
commit 774ee23f79
2 files changed
+23 -5

No files matched your search

+5 -1
View File
@@ -85,12 +85,16 @@ def main():
if got != want: if got != want:
print('FAIL %s: exit %d, want %d\n%s' % (name, got, want, out)) print('FAIL %s: exit %d, want %d\n%s' % (name, got, want, out))
fail = 1 fail = 1
got, out = run('TestA\n', [ev('run', 'TestA'), json.dumps({'Action': 'output', 'Test': 'TestA', 'Output': 'x_test.go:7: the reason\n'}), ev('fail', 'TestA', 1)])
if got != 1 or 'x_test.go:7: the reason' not in out:
print('FAIL a failed test''s output is shown: %s' % out)
fail = 1
got, out = run('TestA\n', ran('TestA', secs=2.25)) got, out = run('TestA\n', ran('TestA', secs=2.25))
if got != 0 or '2.2s' not in out and '2.3s' not in out: if got != 0 or '2.2s' not in out and '2.3s' not in out:
print('FAIL the elapsed time is reported: %s' % out) print('FAIL the elapsed time is reported: %s' % out)
fail = 1 fail = 1
if not fail: if not fail:
print('required-tests-check: %d cases ok' % (len(CASES) + len(STATUS) + 1)) print('required-tests-check: %d cases ok' % (len(CASES) + len(STATUS) + 2))
return fail return fail
+18 -4
View File
@@ -15,12 +15,17 @@ also has exactly one line and that status is 0: a test that reports PASS and
then fails, panics or hangs on its way out is not a pass. Prints one line per named test with its outcome and elapsed then fails, panics or hangs on its way out is not a pass. Prints one line per named test with its outcome and elapsed
seconds, then the total. seconds, then the total.
For every named test that did not pass, the last lines of its output follow the
table, so a run's log carries its own reasons.
Exit 0: every named test passed. 1: at least one did not. 2: usage or an Exit 0: every named test passed. 1: at least one did not. 2: usage or an
unreadable input. unreadable input.
""" """
import json import json
import sys import sys
TAIL = 40 # output lines shown per failed test
def names_of(path): def names_of(path):
names, seen = [], set() names, seen = [], set()
@@ -58,7 +63,7 @@ def outcomes(paths):
"""Test name -> list of (action, elapsed) for its terminal events, the """Test name -> list of (action, elapsed) for its terminal events, the
names that started (action run), and the number of package-level names that started (action run), and the number of package-level
failure events.""" failure events."""
ends, started, pkg_fail = {}, set(), 0 ends, started, pkg_fail, output = {}, set(), 0, {}
for path in paths: for path in paths:
with open(path, encoding='utf-8', errors='replace') as f: with open(path, encoding='utf-8', errors='replace') as f:
for raw in f: for raw in f:
@@ -75,11 +80,14 @@ def outcomes(paths):
pkg_fail += 1 # the binary failed outside any test (or after one) pkg_fail += 1 # the binary failed outside any test (or after one)
continue # other package events; a subtest's name never matches a top-level one continue # other package events; a subtest's name never matches a top-level one
action = ev.get('Action') action = ev.get('Action')
if action == 'output':
output.setdefault(test.split('/')[0], []).append(ev.get('Output', ''))
continue
if action == 'run': if action == 'run':
started.add(test) started.add(test)
elif action in ('pass', 'fail', 'skip'): elif action in ('pass', 'fail', 'skip'):
ends.setdefault(test, []).append((action, ev.get('Elapsed'))) ends.setdefault(test, []).append((action, ev.get('Elapsed')))
return ends, started, pkg_fail return ends, started, pkg_fail, output
def main(argv): def main(argv):
@@ -95,12 +103,12 @@ def main(argv):
return 2 return 2
try: try:
names = names_of(args[0]) names = names_of(args[0])
ends, started, pkg_fail = outcomes(args[1:]) ends, started, pkg_fail, output = outcomes(args[1:])
statuses = statuses_of(status_file) if status_file else None statuses = statuses_of(status_file) if status_file else None
except (OSError, ValueError) as e: except (OSError, ValueError) as e:
print('required-tests: %s' % e, file=sys.stderr) print('required-tests: %s' % e, file=sys.stderr)
return 2 return 2
bad, total = 0, 0.0 bad, total, failed = 0, 0.0, []
for name in names: for name in names:
got = ends.get(name, []) got = ends.get(name, [])
actions = {a for a, _ in got} actions = {a for a, _ in got}
@@ -111,6 +119,7 @@ def main(argv):
print('PASS %-70s %7.1fs' % (name, secs)) print('PASS %-70s %7.1fs' % (name, secs))
continue continue
bad += 1 bad += 1
failed.append(name)
if actions == {'pass'} and len(got) == 1: if actions == {'pass'} and len(got) == 1:
why = ('NO EXIT STATUS' if not rcs else why = ('NO EXIT STATUS' if not rcs else
'PASSED, THEN EXIT %s' % ','.join(str(r) for r in rcs)) 'PASSED, THEN EXIT %s' % ','.join(str(r) for r in rcs))
@@ -121,6 +130,11 @@ def main(argv):
else: else:
why = got[0][0].upper() why = got[0][0].upper()
print('%-8s %-70s %7.1fs' % ('FAIL', name, secs) + ' ' + why) print('%-8s %-70s %7.1fs' % ('FAIL', name, secs) + ' ' + why)
for name in failed:
lines = ''.join(output.get(name, [])).splitlines()[-TAIL:]
print('---- %s: last %d output lines' % (name, len(lines)))
for line in lines:
print(' ' + line[:300])
if pkg_fail: if pkg_fail:
print('FAIL the test binary reported %d package-level failure(s)' % pkg_fail) print('FAIL the test binary reported %d package-level failure(s)' % pkg_fail)
print('required-tests: %d named, %d not passed, %.1fs in named tests' % (len(names), bad, total)) print('required-tests: %d named, %d not passed, %.1fs in named tests' % (len(names), bad, total))