Skip to main content

Crate tpt_cli_snap

Crate tpt_cli_snap 

Source
Expand description

CLI process testing with integrated snapshot assertions.

tpt-cli-snap bridges assert_cmd (which runs a binary and lets you inspect its output) and tpt_snapshot_lite (which compares output against .snap files). The result is readable, self-documenting binary-output tests:

use tpt_cli_snap::CliTest;

let outcome = CliTest::cargo_bin("my-binary")
    .unwrap()
    .arg("--format=json")
    .arg("status")
    .assert_snapshot("status_json");
outcome.assert_success();

Snapshots are stored under <crate_root>/tests/snapshots/ by default; use the cli_snap_dir! macro to point at the calling crate’s manifest directory, or pass an explicit directory with CliTest::with_snap_dir.

Set UPDATE_SNAPSHOTS=1 to (re)create snapshot files — the flag is passed straight through to tpt-snapshot-lite.

Macros§

cli_snap_dir
Default snapshot directory for the calling crate, evaluated at the call site’s compile time: <CARGO_MANIFEST_DIR>/tests/snapshots.

Structs§

CliOutcome
The result of running a CLI command, with snapshot assertions already applied.
CliTest
Builder for a CLI test: a binary plus the args/env/stdin to run it with.