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§
- compare
- Routines for comparing and diffing output.
- containers
- Support for testing using Docker containers.
- cross_
compile - Support for cross-compile tests with the
--target
flag. - git
- Git Testing Support
- install
- Helpers for testing
cargo install
- paths
- Access common paths and manipulate the filesystem
- prelude
- publish
- Helpers for testing
cargo package
/cargo publish
- registry
- Interact with the
TestRegistry
- tools
- Common executables that can be reused by various tests.
Macros§
- file
- Declare an expected value for an assert from a file
- str
- Declare an expected value from within Rust source
- t
- Unwrap a
Result
with a useful panic message
Structs§
- Execs
- Run and verify a
ProcessBuilder
- File
Builder 🔒 - Process
Builder - A builder object for an external process, similar to
std::process::Command
. - Project
- A cargo project to run tests against.
- Project
Builder - Create a project to run tests against
- RawOutput
- This is the raw output from the process.
- Rustc
Info 🔒 - Symlink
Builder 🔒
Traits§
- ArgLine
Command Ext - Add a list of arguments as a line
- Cargo
Command Ext - Test the cargo command
- Channel
Changer Command Ext - Enable nightly features for testing
- Test
EnvCommand Ext - Establish a process’s test environment
Functions§
- _process 🔒
- assert_
deps - assert_
deps_ contains - basic_
bin_ manifest - Generate a
Cargo.toml
with the specifiedbin.name
- basic_
lib_ manifest - Generate a
Cargo.toml
with the specifiedlib.name
- basic_
manifest - Generate a basic
Cargo.toml
- cargo_
exe - Path to the cargo binary
- cargo_
process - Run
cargo $arg_line
, seeExecs
- execs
- Run and verify a process, see
Execs
- git_
process - Run
git $arg_line
, seeProcessBuilder
- is_
coarse_ mtime - Returns
true
if the local filesystem has low-resolution mtimes. - is_
nightly - main_
file - Generate a
main.rs
printing the specified text - no_
such_ file_ err_ msg - The error message for ENOENT.
- panic_
error panic!
, reporting the specified error , see alsot!
- process
- Run
$bin
in the test’s environment, seeProcessBuilder
- project
- Generates a project layout, see
ProjectBuilder
- project_
in - Generates a project layout in given directory, see
ProjectBuilder
- project_
in_ home - Generates a project layout inside our fake home dir, see
ProjectBuilder
- retry
- Helper to retry a function
n
times. - rustc_
host - The rustc host such as
x86_64-unknown-linux-gnu
. - rustc_
host_ env - The host triple suitable for use in a cargo environment variable (uppercased).
- rustc_
info 🔒 - sleep_
ms - slow_
cpu_ multiplier - A way for to increase the cut off for all the time based test.
- symlink_
supported - thread_
wait_ timeout - Helper that waits for a thread to finish, up to
n
tenths of a second. - threaded_
timeout - Helper that runs some function, and waits up to
n
tenths of a second for it to finish.
Attribute Macros§
- cargo_
test - Replacement for
#[test]