Skip to content

Split print_test_output() into focused helpers#536

Merged
MatthewMckee4 merged 1 commit intomainfrom
refactor/print-test-output-split
Mar 21, 2026
Merged

Split print_test_output() into focused helpers#536
MatthewMckee4 merged 1 commit intomainfrom
refactor/print-test-output-split

Conversation

@MatthewMckee4
Copy link
Member

Summary

print_test_output() was a 74-line function in karva/src/commands/test/mod.rs that mixed four concerns: diagnostic printing, duration display, blank-line spacing decisions, and result summary formatting. This made the spacing logic especially hard to follow, since blank lines depended on what the other sections had printed.

This PR extracts two focused helpers:

  • print_diagnostics_section() — prints discovery diagnostics and regular diagnostics, each with their concise-mode trailing newline. The caller no longer needs to know about the internal structure of the two diagnostic blocks.
  • print_durations_section() — prints the N-slowest-tests table and returns bool indicating whether anything was printed. This lets the caller's spacing logic read as a simple condition (!has_diagnostics && !durations_printed) instead of recomputing the durations check inline.

With these extracted, print_test_output() shrinks to a clear sequence: leading blank line (if diagnostics), diagnostics, durations, trailing blank line (if nothing else printed one), result summary.

Also simplifies test() by resolving num_workers in one step (folding the no_parallel check into the fallback) and moving the --watch/--dry-run conflict check before the local variable extraction block.

Terminal output is unchanged — all 685 snapshot and integration tests pass.

Test plan

  • just test — all 685 tests pass
  • uvx prek run -a — all pre-commit checks pass (including clippy)
  • No snapshot changes, confirming terminal output is identical

🤖 Generated with Claude Code

The 74-line print_test_output() mixed diagnostic printing, duration
display, spacing logic, and result summary formatting. Extract two
helpers so each section is self-contained:

- print_diagnostics_section(): handles discovery and regular diagnostics
  with concise-mode spacing
- print_durations_section(): handles the N-slowest display, returns
  whether anything was printed so the caller can decide on spacing

Also simplify test() by resolving num_workers inline (merging the
no_parallel check with the fallback) and validating watch+dry_run
before extracting local variables.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@MatthewMckee4 MatthewMckee4 added the internal An internal refactor or improvement label Mar 21, 2026
@MatthewMckee4 MatthewMckee4 merged commit 991988e into main Mar 21, 2026
8 checks passed
@MatthewMckee4 MatthewMckee4 deleted the refactor/print-test-output-split branch March 21, 2026 08:58
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 21, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 1 untouched benchmark


Comparing refactor/print-test-output-split (7940340) with main (1514ec8)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant