Module test

Module 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§

LocatedParseError
ParseError together with its location in the XML input.
Parsed
Parsed terminal output.
TestConfig
Testing configuration.
TestStats
Stats of a single snapshot test output by TestConfig::test_transcript_for_stats().

Enums§

MatchKind
Kind of terminal output matching.
ParseError
Errors that can occur during parsing SVG transcripts.
TestOutputConfig
Configuration of output produced during testing.
UpdateModesvg
Strategy for saving a new snapshot on a test failure within TestConfig::test() and related methods.