diff --git a/tests/test_progress_dashboard.py b/tests/test_progress_dashboard.py index b5a15e80ce..4b455b9096 100644 --- a/tests/test_progress_dashboard.py +++ b/tests/test_progress_dashboard.py @@ -142,6 +142,132 @@ def test_lasttest_ignores_a_nested_ctest_log(self) -> None: ) self.assertEqual(pd.parse_lasttest(log), [("outer", "fail", 0.23), ("next", "pass", 0.02)]) + def test_lasttest_recovers_when_nested_log_omits_end_testing(self) -> None: + # Mirrors the real CTest 3.31.10 fixture where outer `wrapper` (1/2, fails) prints an inner + # log containing `wrapper` (1/2, passes) and `child_2` (2/2, passes) with identical ordinal + # and timestamps, but without the inner `End testing:` trailer, followed by outer `later` (2/2). + sep = "-" * 58 + ts = "Nov 24 20:47 UTC" + inner_no_end = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Testing: wrapper\n1/2 Test: wrapper\nOutput:\n{sep}\ninner ok\n\n" + f'Test time = 0.01 sec\n{sep}\nTest Passed.\n"wrapper" end time: {ts}\n' + f'"wrapper" time elapsed: 00:00:00\n{sep}\n\n' + f"2/2 Testing: child_2\n2/2 Test: child_2\nOutput:\n{sep}\nchild ok\n\n" + f'Test time = 0.01 sec\n{sep}\nTest Passed.\n"child_2" end time: {ts}\n' + f'"child_2" time elapsed: 00:00:00\n{sep}' + ) + log = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Testing: wrapper\n1/2 Test: wrapper\nOutput:\n{sep}\n{inner_no_end}\n\n" + f'Test time = 0.25 sec\n{sep}\nTest Failed.\n"wrapper" end time: {ts}\n' + f'"wrapper" time elapsed: 00:00:00\n{sep}\n\n' + f"2/2 Testing: later\n2/2 Test: later\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.02 sec\n{sep}\nTest Passed.\n"later" end time: {ts}\n' + f'"later" time elapsed: 00:00:00\n{sep}\n\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 0.25), ("later", "pass", 0.02)]) + + def test_lasttest_recovers_from_empty_incomplete_nested_log(self) -> None: + sep = "-" * 58 + log = ( + f"Start testing: Nov 24 20:47 UTC\n{sep}\n" + f"1/1 Testing: wrapper\n1/1 Test: wrapper\nOutput:\n{sep}\n" + f"Start testing: Nov 24 20:47 UTC\n{sep}\n" + f"\nTest time = 10.00 sec\n{sep}\nTest Failed.\n" + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 10.0)]) + + def test_lasttest_handles_three_level_nested_log_missing_innermost_end_testing(self) -> None: + sep = "-" * 58 + ts = "Nov 24 20:47 UTC" + leaf = ( + f"Start testing: {ts}\n{sep}\n1/1 Test: leaf\nOutput:\n{sep}\nleaf\n\n" + f'Test time = 0.01 sec\n{sep}\nTest Passed.\n"leaf" end time: {ts}\n{sep}' + ) + mid = ( + f"Start testing: {ts}\n{sep}\n1/1 Test: mid\nOutput:\n{sep}\n{leaf}\n\n" + f'Test time = 0.05 sec\n{sep}\nTest Passed.\n"mid" end time: {ts}\n{sep}\n\nEnd testing: {ts}' + ) + log = ( + f"Start testing: {ts}\n{sep}\n1/2 Test: wrapper\nOutput:\n{sep}\n{mid}\n\n" + f'Test time = 0.30 sec\n{sep}\nTest Failed.\n"wrapper" end time: {ts}\n{sep}\n\n' + f"2/2 Test: later\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.02 sec\n{sep}\nTest Passed.\n"later" end time: {ts}\n{sep}\n\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 0.3), ("later", "pass", 0.02)]) + + def test_lasttest_recovers_when_inner_test_output_is_truncated_mid_stream(self) -> None: + sep = "-" * 58 + ts = "Nov 24 20:47 UTC" + inner_truncated = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Test: wrapper\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.01 sec\n{sep}\nTest Passed.\n"wrapper" end time: {ts}\n{sep}\n' + f"2/2 Test: child_2\nOutput:\n{sep}\npartial output before kill" + ) + log = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Test: wrapper\nOutput:\n{sep}\n{inner_truncated}\n\n" + f'Test time = 0.40 sec\n{sep}\nTest Failed.\n"wrapper" end time: {ts}\n{sep}\n\n' + f"2/2 Test: later\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.03 sec\n{sep}\nTest Passed.\n"later" end time: {ts}\n{sep}\n\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 0.4), ("later", "pass", 0.03)]) + + def test_lasttest_recovers_when_multi_level_nested_output_is_truncated_mid_leaf(self) -> None: + sep = "-" * 58 + ts = "Nov 24 21:40 UTC" + middle_truncated_in_leaf = ( + f"Start testing: {ts}\n{sep}\n" + f"1/1 Test: middle\nOutput:\n{sep}\n" + f"Start testing: {ts}\n{sep}\n" + f"1/1 Test: leaf\nOutput:\n{sep}\n" + f"leaf payload" + ) + log = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Test: wrapper\nOutput:\n{sep}\n{middle_truncated_in_leaf}\n\n" + f'Test time = 0.25 sec\n{sep}\nTest Failed.\n"wrapper" end time: {ts}\n{sep}\n\n' + f"2/2 Test: later\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.04 sec\n{sep}\nTest Passed.\n"later" end time: {ts}\n{sep}\n\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 0.25), ("later", "pass", 0.04)]) + + def test_lasttest_recovers_when_middle_finishes_after_truncated_leaf(self) -> None: + sep = "-" * 58 + ts = "Nov 24 21:40 UTC" + middle_with_truncated_leaf = ( + f"Start testing: {ts}\n{sep}\n" + f"1/1 Test: middle\nOutput:\n{sep}\n" + f"Start testing: {ts}\n{sep}\n" + f"1/1 Test: leaf\nOutput:\n{sep}\n" + f"leaf payload\n\n" + f'Test time = 0.10 sec\n{sep}\nTest Failed.\n"middle" end time: {ts}\n{sep}\nEnd testing: {ts}' + ) + log = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Test: wrapper\nOutput:\n{sep}\n{middle_with_truncated_leaf}\n\n" + f'Test time = 0.35 sec\n{sep}\nTest Passed.\n"wrapper" end time: {ts}\n{sep}\n\n' + f"2/2 Test: later\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.05 sec\n{sep}\nTest Passed.\n"later" end time: {ts}\n{sep}\n\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "pass", 0.35), ("later", "pass", 0.05)]) + + def test_lasttest_ignores_spurious_end_testing_inside_nested_test_output(self) -> None: + sep = "-" * 58 + ts = "Nov 24 20:47 UTC" + inner = ( + f"Start testing: {ts}\n{sep}\n1/1 Test: inner\nOutput:\n{sep}\n" + f"End testing: spurious line in child output\n\n" + f'Test time = 0.01 sec\n{sep}\nTest Passed.\n"inner" end time: {ts}\n{sep}\nEnd testing: {ts}' + ) + log = ( + f"Start testing: {ts}\n{sep}\n1/1 Test: wrapper\nOutput:\n{sep}\n{inner}\n\n" + f'Test time = 0.15 sec\n{sep}\nTest Failed.\n"wrapper" end time: {ts}\n{sep}\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 0.15)]) + def test_ci_selection_matches_the_workflow_rule(self): files = pd.ci_test_files() self.assertIn("tests/test_progress_dashboard.py", files) diff --git a/tools/progress_dashboard.py b/tools/progress_dashboard.py index 43d3fafdbb..2f3219eb30 100644 --- a/tools/progress_dashboard.py +++ b/tools/progress_dashboard.py @@ -400,24 +400,78 @@ def parse_junit(xml): return out +_CTEST_HEADER_RE = re.compile(r"^\d+/\d+ Test: (.+)$") + + +def _trailer_end_time_name(lines: list[str], end_of_output_index: int) -> str | None: + """Return `` from the immediate CTest trailer's `\"\" end time: ` line, or None.""" + sep = "-" * 58 + separators = 0 + for idx in range(end_of_output_index + 1, len(lines)): + line = lines[idx] + if line == sep: + separators += 1 + if separators >= 2: + return None + continue + if line.startswith('"'): + marker = line.rfind('" end time: ') + if marker > 0: + return line[1:marker] + if line == "" or line == "Output:" or line.startswith(("Start testing: ", "End testing: ")): + return None + if _CTEST_HEADER_RE.match(line): + return None + return None + + def parse_lasttest(text: str) -> list[tuple[str, str, float | None]]: """[(name, result, seconds)] from CTest's Testing/Temporary/LastTest.log.""" + sep = "-" * 58 out, name, secs = [], None, None captured = False - nested_runs = 0 + # Stack of [in_output, inner_test_name] for nested `Start testing:` runs inside captured output. + nested: list[list[object]] = [] lines = text.splitlines() for index, line in enumerate(lines): next_line = lines[index + 1] if index + 1 < len(lines) else "" if captured: - # CTest writes child output verbatim, so it can contain complete nested logs. - if line.startswith("Start testing: ") and next_line == "-" * 58: - nested_runs += 1 - elif nested_runs and line.startswith("End testing: "): - nested_runs -= 1 - elif not nested_runs and line == "" and next_line.startswith("Test time ="): - captured = False + # CTest writes child output verbatim, so it can contain complete or truncated nested logs. + if line.startswith("Start testing: ") and next_line == sep: + nested.append([False, None]) + elif line == "" and next_line.startswith("Test time ="): + # Unwind any nested runs whose Output: block is already closed (or never opened) and omitted End testing:. + while nested and not nested[-1][0]: + nested.pop() + if not nested: + captured = False + else: + trailer_name = _trailer_end_time_name(lines, index) + matched_depth = None + if trailer_name is not None: + for depth in range(len(nested) - 1, -1, -1): + if nested[depth][1] == trailer_name: + matched_depth = depth + break + if matched_depth is not None: + del nested[matched_depth + 1:] + nested[matched_depth][0] = False + elif trailer_name is not None and trailer_name == name: + # All open nested Output: blocks were truncated before their own ``. + nested.clear() + captured = False + else: + nested[-1][0] = False + elif nested and not nested[-1][0]: + m = _CTEST_HEADER_RE.match(line) + if m: + nested[-1][1] = m.group(1).strip() + elif line == "Output:" and next_line == sep: + nested[-1][0] = True + elif line.startswith("End testing: "): + nested.pop() continue - m = re.match(r"^\d+/\d+ Test: (.+)$", line) + m = _CTEST_HEADER_RE.match(line) if m: name, secs = m.group(1).strip(), None continue @@ -425,6 +479,7 @@ def parse_lasttest(text: str) -> list[tuple[str, str, float | None]]: continue if line == "Output:": captured = True + nested.clear() continue m = re.match(r"^Test time =\s*([\d.]+) sec", line) if m: