Expand description
insta-cmd is an extension to insta that lets you snapshot
a command that produces (text) output to stdout and stderr. It takes a
Command from the standard library, runs it and
snapshots the output alongside the exit code.
use std::process::Command;
use insta_cmd::assert_cmd_snapshot;
assert_cmd_snapshot!(Command::new("echo").arg("Hello World!"));§Testing Binaries
If you want to test binaries from your own project you can use the
get_cargo_bin and get_cargo_example functions to retrieve the path to
your binary. Note that it’s unlikely that cargo will have built the binary
under normal circumstances so you will have to run cargo build --bin my-bin
or cargo build --example my-example before.
Afterwards you can test it like this:
use std::process::Command;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
assert_cmd_snapshot!(Command::new(get_cargo_bin("hello")).arg("first arg"));§Passing Stdin
To pass data via stdin and to have it snapshotted alongside, use the
pass_stdin extension method. Inside the macro
it’s automatically in scope.
use std::process::Command;
use insta_cmd::assert_cmd_snapshot;
assert_cmd_snapshot!(Command::new("cat").arg("-b").pass_stdin("Hello World"));Macros§
- assert_
cmd_ snapshot - Runs an spawnable and snapshots the output.
Structs§
- Command
- A process builder, providing fine-grained control over how a new process should be spawned.
- Stdin
Command Deprecated - Like
Commandbut sends some input to stdin.
Traits§
- Spawn
- Implemented by different types that can be spawned and snapshotted.
- Spawn
Ext - Utility methods for spawning.
Functions§
- get_
cargo_ bin - Helper function to return the path to an executable that cargo is building.
- get_
cargo_ example - Helper function to return the path to an example that cargo is building.