Parse testlog.txt and display error context for failed tests. Args: testlog_path: Path to meson testlog.txt failed_test_names: Set of test names that failed (e.g., {"fastled:fl_control_remote"}) context_lines: Number of lines to show before/after error lines
(
testlog_path: Path,
failed_test_names: set[str],
context_lines: int = 10,
)
| 97 | |
| 98 | |
| 99 | def extract_error_context_from_testlog( |
| 100 | testlog_path: Path, |
| 101 | failed_test_names: set[str], |
| 102 | context_lines: int = 10, |
| 103 | ) -> None: |
| 104 | """ |
| 105 | Parse testlog.txt and display error context for failed tests. |
| 106 | |
| 107 | Args: |
| 108 | testlog_path: Path to meson testlog.txt |
| 109 | failed_test_names: Set of test names that failed (e.g., {"fastled:fl_control_remote"}) |
| 110 | context_lines: Number of lines to show before/after error lines |
| 111 | """ |
| 112 | entries = parse_testlog(testlog_path) |
| 113 | |
| 114 | # Filter to only failed tests |
| 115 | failed_entries = [ |
| 116 | e |
| 117 | for e in entries |
| 118 | if e.test_name in failed_test_names and "exit status 0" not in e.result |
| 119 | ] |
| 120 | |
| 121 | if not failed_entries: |
| 122 | _ts_print("[MESON] ⚠️ Could not find detailed error information in testlog.txt") |
| 123 | return |
| 124 | |
| 125 | _ts_print("\n[MESON] ❌ Test failure details from testlog.txt:") |
| 126 | _ts_print("=" * 80) |
| 127 | |
| 128 | for entry in failed_entries: |
| 129 | _ts_print(f"\n[TEST FAILED] {entry.test_name} ({entry.duration})") |
| 130 | _ts_print(f"[EXIT CODE] {entry.result}") |
| 131 | _ts_print("-" * 80) |
| 132 | |
| 133 | # Combine stdout and stderr for error detection |
| 134 | combined_output: list[str] = [] |
| 135 | if entry.stdout: |
| 136 | combined_output.append("=== STDOUT ===") |
| 137 | combined_output.extend(entry.stdout.splitlines()) |
| 138 | if entry.stderr: |
| 139 | combined_output.append("=== STDERR ===") |
| 140 | combined_output.extend(entry.stderr.splitlines()) |
| 141 | |
| 142 | if not combined_output: |
| 143 | _ts_print("(No output captured)") |
| 144 | continue |
| 145 | |
| 146 | # Apply error detection with context |
| 147 | error_filter: Callable[[str], None] = _create_error_context_filter( |
| 148 | context_lines=context_lines, |
| 149 | max_unique_errors=10, # Show up to 10 unique errors per test |
| 150 | ) |
| 151 | |
| 152 | line: str |
| 153 | for line in combined_output: |
| 154 | error_filter(line) |
| 155 | |
| 156 | _ts_print("=" * 80) |
no test coverage detected