Expand description
§Cargo test support.
See https://rust-lang.github.io/cargo/contrib/ for a guide on writing tests.
There are two places you can find API documentation
- https://docs.rs/cargo-test-support:
targeted at external tool developers testing cargo-related code
- Released with every rustc release
- https://doc.rust-lang.org/nightly/nightly-rustc/cargo_test_support:
targeted at cargo contributors
- Updated on each update of the
cargo
submodule inrust-lang/rust
- Updated on each update of the
This crate is maintained by the Cargo team, primarily for use by Cargo and not intended for external use. This crate may make major changes to its APIs or be deprecated without warning.
§Example
use cargo_test_support::prelude::*;
use cargo_test_support::str;
use cargo_test_support::project;
#[cargo_test]
fn some_test() {
let p = project()
.file("src/main.rs", r#"fn main() { println!("hi!"); }"#)
.build();
p.cargo("run --bin foo")
.with_stderr_data(str![[r#"
[COMPILING] foo [..]
[FINISHED] [..]
[RUNNING] `target/debug/foo`
"#]])
.with_stdout_data(str![["hi!"]])
.run();
}
Modules§
- Routines for comparing and diffing output.
- Support for testing using Docker containers.
- Support for cross-compile tests with the
--target
flag. - Git Testing Support
- Helpers for testing
cargo install
- Access common paths and manipulate the filesystem
- Helpers for testing
cargo package
/cargo publish
- Interact with the
TestRegistry
- Common executables that can be reused by various tests.
Macros§
- Declare an expected value for an assert from a file
- Declare an expected value from within Rust source
- Unwrap a
Result
with a useful panic message
Structs§
- Run and verify a
ProcessBuilder
- A builder object for an external process, similar to
std::process::Command
. - A cargo project to run tests against.
- Create a project to run tests against
- This is the raw output from the process.
Traits§
- Add a list of arguments as a line
- Test the cargo command
- Enable nightly features for testing
- Establish a process’s test environment
Functions§
- _process 🔒
- Generate a
Cargo.toml
with the specifiedbin.name
- Generate a
Cargo.toml
with the specifiedlib.name
- Generate a basic
Cargo.toml
- Path to the cargo binary
- Run
cargo $arg_line
, seeExecs
- Run and verify a process, see
Execs
- Run
git $arg_line
, seeProcessBuilder
- Returns
true
if the local filesystem has low-resolution mtimes. - Generate a
main.rs
printing the specified text - The error message for ENOENT.
panic!
, reporting the specified error , see alsot!
- Run
$bin
in the test’s environment, seeProcessBuilder
- Generates a project layout, see
ProjectBuilder
- Generates a project layout in given directory, see
ProjectBuilder
- Generates a project layout inside our fake home dir, see
ProjectBuilder
- Helper to retry a function
n
times. - The rustc host such as
x86_64-unknown-linux-gnu
. - The host triple suitable for use in a cargo environment variable (uppercased).
- A way for to increase the cut off for all the time based test.
- Helper that waits for a thread to finish, up to
n
tenths of a second. - Helper that runs some function, and waits up to
n
tenths of a second for it to finish.
Attribute Macros§
- Replacement for
#[test]