Crate tryrun[][src]

Expand description

UI testing for arbitrary Commands.

Examples

All the .stdout files listed below can be found in the tests/ui directory in this crate’s repository.

Test that cargo build -q runs successfully and has empty output without normalization

Command::cargo("build").arg("-q").run_pass(OutputStr::empty(), normalize::noop());

Test that cargo miri test -q runs successfully and has expected stdout and empty stderr without normalization

Command::cargo_miri("test")
    .args(&["-q", "--lib", "--target-dir=target/miri"])
    .run_pass(OutputStr::stdout("tests/ui/cargo_miri_test.stdout"), normalize::noop());

Test that rustc -V runs successfully and has expected stdout after normalization and empty stderr

Command::rustc().arg("-V").run_pass(
   OutputStr::stdout("tests/ui/rustc_version.stdout"),
   normalize::stdout(|output| {
       output.truncate("rustc 1.".len());
       output.push(b'\n');
       output
   }),
);

Test that rustdoc -V runs successfully and has expected stdout after normalization and empty stderr

Command::rustdoc().arg("-V").run_pass(
   OutputStr::stdout("tests/ui/rustdoc_version.stdout"),
   normalize::stdout(|output| {
       output.truncate("rustdoc 1.".len());
       output.push(b'\n');
       output
   }),
);

Test that clippy-driver -V runs successfully and has expected stdout after normalization and empty stderr

Command::clippy().arg("-V").run_pass(
    OutputStr::stdout("tests/ui/clippy_version.stdout"),
    normalize::stdout(|output| {
        output.truncate("clippy".len());
        output.push(b'\n');
        output
    }),
);

Test that false runs unsucessfully and has empty output without normalization

Command::new("false").run_fail(OutputStr::empty(), normalize::noop());

Test that false garbage also runs unsucessfully and has empty output without normalization

Command::new("false").arg("garbage").run_fail(OutputStr::empty(), normalize::noop());

Blessing

This will update all used stdout and stderr files:

TRYRUN=bless cargo test

You can see some of the unit tests of this src/lib.rs for more examples. Also see this crate’s own UI tests for more advanced examples.

Dependencies

To display a colourful diff, the git command needs to be installed, otherwise no helpful output will be shown for test failures.

Modules

normalize

Normalizing helper functions.

prelude

The prelude.

Macros

output

Creates an Output that expects stdout to match $base_path.stdout and stderr to match $base_path.stderr.

Structs

Output

Path to files that store expected Command stdout and stderr.

Traits

CommandExt

An extension trait for Command.

Normalizer

Normalizer to normalize stdout and stderr.

Type Definitions

OutputStr

A convenience alias of Output with &'static str.