Module term_transcript::test

source ·
Available on crate feature test only.
Expand description

Snapshot testing tools for Transcripts.

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

Enums