Skip to content

Add assert_cmd_snapshot function and Command class#461

Merged
MatthewMckee4 merged 5 commits intomainfrom
add-assert-cmd-snapshot
Feb 11, 2026
Merged

Add assert_cmd_snapshot function and Command class#461
MatthewMckee4 merged 5 commits intomainfrom
add-assert-cmd-snapshot

Conversation

@MatthewMckee4
Copy link
Member

Summary

  • Adds karva.Command builder class wrapping Rust's std::process::Command with .arg(), .args(), .env(), .envs(), .current_dir(), and .stdin() builder methods
  • Adds karva.assert_cmd_snapshot() function for snapshot-testing command output (stdout, stderr, exit code) in insta-cmd style format
  • Extracts inline snapshot call detection into find_snapshot_call() with extensible SNAPSHOT_CALL_PATTERNS constant
  • Updates diff renderer to use box-drawing character () for separator column

Test plan

  • 23 integration tests covering: basic echo, snap.new creation, nonzero exit codes, stderr capture, named snapshots, stdin, filters, env vars, inline matching/mismatch, builder chaining, multiple snapshots with allow_duplicates, current_dir, multiline output, empty output, stable re-run, and inline+name exclusivity
  • Unit tests for format_cmd_output formatting
  • Existing snapshot tests updated for new diff renderer characters

Adds a new `karva.Command` builder class (wrapping Rust's `std::process::Command`)
and `karva.assert_cmd_snapshot()` for snapshot-testing command output (stdout,
stderr, exit code) in insta-cmd style format.

Also extracts inline snapshot call detection into a `find_snapshot_call()` function
with a `SNAPSHOT_CALL_PATTERNS` constant for extensibility, and updates the diff
renderer to use box-drawing characters (│) for the separator column.
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 11, 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 add-assert-cmd-snapshot (c6c0519) with main (febcd92)

Open in CodSpeed

…nt_dir test

Add tests for multiple filters, nested settings, filter on stderr, filter
with named snapshot, and allow_duplicates combined with filters. Remove
test_cmd_snapshot_current_dir which was unpredictable across OSes.
@MatthewMckee4 MatthewMckee4 added the snapshot-testing Related to snapshot testing label Feb 11, 2026
Log the platform-specific error via tracing::debug instead of including
it in the Python exception, so error messages are consistent across OSes.
Avoids platform-dependent behavior from sys.executable on Windows.
@MatthewMckee4 MatthewMckee4 merged commit 15d82f3 into main Feb 11, 2026
16 of 17 checks passed
@MatthewMckee4 MatthewMckee4 deleted the add-assert-cmd-snapshot branch February 11, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

snapshot-testing Related to snapshot testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant