Snapshot Testing for CLI / REPL Applications

Build Status License: MIT OR Apache-2.0 rust 1.66+ required

Documentation: Docs.rs crate docs (master)

This crate allows to:

The primary use case is easy to create and maintain end-to-end tests for CLI / REPL apps. Such tests can be embedded into a readme file.

Usage

Add this to your Crate.toml:

toml [dependencies] term-transcript = "0.3.0"

Example of usage:

```rust use term_transcript::{ svg::{Template, TemplateOptions}, ShellOptions, Transcript, UserInput, }; use std::str;

let transcript = Transcript::frominputs( &mut ShellOptions::default(), vec![UserInput::command(r#"echo "Hello world!""#)], )?; let mut writer = vec![]; // ^ Any std::io::Write implementation will do, such as a File. Template::new(TemplateOptions::default()).render(&transcript, &mut writer)?; println!("{}", str::fromutf8(&writer)?); Ok::<_, anyhow::Error>(()) ```

See more examples in the crate docs and the FAQ for some tips and troubleshooting advice.

CLI app

Most of the library functionality is packaged into a CLI binary, which allows using the library without Rust knowledge. See the binary docs for the installation and usage guides.

Snapshot examples

An SVG snapshot of the rainbow example produced by this crate:

Snapshot of rainbow example

A snapshot of the same example with the scrolling animation and window frame:

Animated snapshot of rainbow example

A snapshot of a similar example rendered to HTML using a custom template is available as a source file and in the rendered form.

See the examples directory for more snapshot examples.

Limitations

Alternatives / similar tools

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in term-transcript by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.