|
7 | 7 |
|
8 | 8 | use std::process::Command; |
9 | 9 |
|
| 10 | +/// Marker that separates loader/discovery output from actual test execution output. |
| 11 | +/// This follows the project's logging convention: `[tach:module]` prefix for all eprintln! output. |
| 12 | +/// We use this to isolate test results from compilation warnings in loader output. |
| 13 | +const TEST_OUTPUT_MARKER: &str = "[tach:reporter] Running"; |
| 14 | + |
| 15 | +/// Extract the test output section from combined stdout/stderr. |
| 16 | +/// This filters out loader/discovery noise to focus on actual test results. |
| 17 | +fn extract_test_output(combined: &str) -> &str { |
| 18 | + combined |
| 19 | + .split(TEST_OUTPUT_MARKER) |
| 20 | + .nth(1) |
| 21 | + .unwrap_or(combined) |
| 22 | +} |
| 23 | + |
10 | 24 | /// Get the tach-core binary path |
11 | 25 | fn tach_binary() -> std::path::PathBuf { |
12 | 26 | let mut path = std::env::current_exe().unwrap(); |
@@ -64,14 +78,11 @@ fn test_tb_short_truncates_traceback() { |
64 | 78 |
|
65 | 79 | // Short style should have traceback but be concise |
66 | 80 | // It should NOT have the full "during handling of the above exception" chains |
67 | | - // in the TEST OUTPUT section (after "[tach:reporter] Running") |
| 81 | + // in the TEST OUTPUT section (after the reporter starts running tests) |
68 | 82 | let long_chain_indicator = "During handling of the above exception"; |
69 | 83 |
|
70 | 84 | // Find the test output section (after loader/discovery) |
71 | | - let test_output = combined |
72 | | - .split("[tach:reporter] Running") |
73 | | - .nth(1) |
74 | | - .unwrap_or(&combined); |
| 85 | + let test_output = extract_test_output(&combined); |
75 | 86 |
|
76 | 87 | let has_long_chain = test_output.contains(long_chain_indicator); |
77 | 88 |
|
@@ -127,10 +138,7 @@ fn test_tb_no_suppresses_traceback() { |
127 | 138 |
|
128 | 139 | // "no" style should suppress traceback entirely in TEST OUTPUT |
129 | 140 | // Find the test output section (after loader/discovery) |
130 | | - let test_output = combined |
131 | | - .split("[tach:reporter] Running") |
132 | | - .nth(1) |
133 | | - .unwrap_or(&combined); |
| 141 | + let test_output = extract_test_output(&combined); |
134 | 142 |
|
135 | 143 | // Should NOT contain "Traceback (most recent call last)" in test output |
136 | 144 | let has_full_traceback = test_output.contains("Traceback (most recent call last)"); |
@@ -239,10 +247,7 @@ fn test_tb_flag_overrides_env_var() { |
239 | 247 |
|
240 | 248 | // With --tb no, should not have full traceback in TEST OUTPUT (flag overrides env) |
241 | 249 | // Find the test output section (after loader/discovery) |
242 | | - let test_output = combined |
243 | | - .split("[tach:reporter] Running") |
244 | | - .nth(1) |
245 | | - .unwrap_or(&combined); |
| 250 | + let test_output = extract_test_output(&combined); |
246 | 251 | let has_full_traceback = test_output.contains("Traceback (most recent call last)"); |
247 | 252 |
|
248 | 253 | assert!( |
@@ -303,10 +308,7 @@ fn test_tb_with_passing_tests_no_traceback() { |
303 | 308 |
|
304 | 309 | // Should not have traceback for passing tests in TEST OUTPUT |
305 | 310 | // Find the test output section (after loader/discovery) |
306 | | - let test_output = combined |
307 | | - .split("[tach:reporter] Running") |
308 | | - .nth(1) |
309 | | - .unwrap_or(&combined); |
| 311 | + let test_output = extract_test_output(&combined); |
310 | 312 | assert!( |
311 | 313 | !test_output.contains("Traceback (most recent call last)"), |
312 | 314 | "--tb {} should not show traceback for passing tests. Output:\n{}", |
|
0 commit comments