Module term_transcript::test
source · Available on crate feature
test
only.Expand description
Snapshot testing tools for Transcript
s.
§Examples
Simple scenario in which the tested transcript calls to one or more Cargo binaries / examples by their original names.
use term_transcript::{
ShellOptions, Transcript,
test::{MatchKind, TestConfig, TestOutputConfig},
};
// Test configuration that can be shared across tests.
fn config() -> TestConfig {
let shell_options = ShellOptions::default().with_cargo_path();
TestConfig::new(shell_options)
.with_match_kind(MatchKind::Precise)
.with_output(TestOutputConfig::Verbose)
}
// Usage in tests:
#[test]
fn help_command() {
config().test("tests/__snapshots__/help.svg", &["my-command --help"]);
}
Use TestConfig::test_transcript()
for more complex scenarios or increased control:
use term_transcript::{test::TestConfig, ShellOptions, Transcript, UserInput};
use std::io;
fn read_svg_file() -> anyhow::Result<impl io::BufRead> {
// snipped...
}
let reader = read_svg_file()?;
let transcript = Transcript::from_svg(reader)?;
TestConfig::new(ShellOptions::default()).test_transcript(&transcript);
Structs§
- Parsed terminal output.
- Testing configuration.
- Stats of a single snapshot test output by
TestConfig::test_transcript_for_stats()
.
Enums§
- Kind of terminal output matching.
- Configuration of output produced during testing.
- UpdateMode
svg
Strategy for saving a new snapshot on a test failure withinTestConfig::test()
and related methods.