Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions scripts/tests/test_upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ def test_failure_lines_are_names_counts_and_locations_only(self):
log.write_text('\n'.join(output + named + named) + '\n')
self.assertEqual(validation.failure_lines(log), named)

def test_cargo_lines_match_without_their_colors(self):
with tempfile.TemporaryDirectory() as tmp:
log = Path(tmp) / 'stage.log'
log.write_text('\x1b[1m\x1b[91merror\x1b[0m: test failed, to rerun pass `-p codespace-server --lib`\n'
'\x1b[1m\x1b[91merror\x1b[0m: could not compile `codespace-server` (lib test) due to 1 previous error\n'
'\x1b[1m\x1b[32m Running\x1b[0m unittests src/lib.rs\n')
self.assertEqual(validation.failure_lines(log), [
'error: test failed, to rerun pass `-p codespace-server --lib`',
'error: could not compile `codespace-server` (lib test) due to 1 previous error'])

def test_an_unreadable_log_or_many_failures_keep_the_summary_short(self):
with tempfile.TemporaryDirectory() as tmp, contextlib.redirect_stdout(io.StringIO()) as printed:
log = Path(tmp) / 'unit-pty.log'
Expand Down
7 changes: 5 additions & 2 deletions scripts/validate-upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,15 @@ def execute(commands, env, log):
r'FAILED \([\w ]+=\d+(?:, [\w ]+=\d+)*\)']))
# Enough for one test binary's failures; the log keeps the rest.
FAILURES_SHOWN = 40
# The terminal colors of cargo's own lines, which CI asks for with CARGO_TERM_COLOR.
COLOR = re.compile(r'\x1b\[[0-9;]*m')


def failure_lines(path):
"""The lines of a stage's log that FAILURE_LINE matches, each once, in order."""
"""The lines of a stage's log that FAILURE_LINE matches without their colors, each once, in
order."""
with path.open(encoding='utf-8', errors='replace') as log:
lines = (line.strip() for line in log)
lines = (COLOR.sub('', line).strip() for line in log)
return list(dict.fromkeys(line for line in lines if FAILURE_LINE.fullmatch(line)))


Expand Down
Loading