Skip to content

Commit dec4283

Browse files
NikkeTryHardclaude
andcommitted
refactor(test): extract TEST_OUTPUT_MARKER constant and helper function
- Add TEST_OUTPUT_MARKER constant for the "[tach:reporter] Running" pattern - Add extract_test_output() helper function to DRY up output parsing - Document why this pattern is used (isolate test results from loader noise) - Improves maintainability if log format changes in future Co-Authored-By: Claude <noreply@anthropic.com>
1 parent de215d0 commit dec4283

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

rust_tests/traceback_format_tests.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
88
use std::process::Command;
99

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+
1024
/// Get the tach-core binary path
1125
fn tach_binary() -> std::path::PathBuf {
1226
let mut path = std::env::current_exe().unwrap();
@@ -64,14 +78,11 @@ fn test_tb_short_truncates_traceback() {
6478

6579
// Short style should have traceback but be concise
6680
// 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)
6882
let long_chain_indicator = "During handling of the above exception";
6983

7084
// 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);
7586

7687
let has_long_chain = test_output.contains(long_chain_indicator);
7788

@@ -127,10 +138,7 @@ fn test_tb_no_suppresses_traceback() {
127138

128139
// "no" style should suppress traceback entirely in TEST OUTPUT
129140
// 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);
134142

135143
// Should NOT contain "Traceback (most recent call last)" in test output
136144
let has_full_traceback = test_output.contains("Traceback (most recent call last)");
@@ -239,10 +247,7 @@ fn test_tb_flag_overrides_env_var() {
239247

240248
// With --tb no, should not have full traceback in TEST OUTPUT (flag overrides env)
241249
// 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);
246251
let has_full_traceback = test_output.contains("Traceback (most recent call last)");
247252

248253
assert!(
@@ -303,10 +308,7 @@ fn test_tb_with_passing_tests_no_traceback() {
303308

304309
// Should not have traceback for passing tests in TEST OUTPUT
305310
// 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);
310312
assert!(
311313
!test_output.contains("Traceback (most recent call last)"),
312314
"--tb {} should not show traceback for passing tests. Output:\n{}",

0 commit comments

Comments
 (0)