#prelude #maintained #longer #command #testing #cargo-command #output

yanked tryrun

This crate is no longer maintained

0.5.3 Jun 11, 2021
0.5.2 May 30, 2021
0.4.1 May 29, 2021
0.3.7 May 28, 2021
0.1.2 Mar 31, 2021

#64 in #longer

Download history 5/week @ 2024-02-20 1/week @ 2024-03-12 96/week @ 2024-04-02

96 downloads per month

MPL-2.0 license

32KB
641 lines

This project is no longer maintained.


lib.rs:

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

use tryrun::prelude::*;

Command::cargo_miri("test")

.env_remove("LD_LIBRARY_PATH")

.env_remove("DYLD_FALLBACK_LIBRARY_PATH")

 .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

use tryrun::prelude::*;

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

use tryrun::prelude::*;

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

use tryrun::prelude::*;

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

use tryrun::prelude::*;

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


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

use tryrun::prelude::*;

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


### Blessing
This will update all used stdout and stderr files:
```shell
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.

No runtime deps