pub struct CargoTest { /* private fields */ }
Available on crate feature
test_unstable
only.Expand description
The test
subcommand (emulated).
Created via CargoBuild::run_tests
.
Benefits over spawning cargo test
:
- Able to cache binary path, avoiding cargo overhead.
- Independent of CWD.
- stdout/stderr are clean of
cargo test
output.
Required feature: test_unstable
since the format parsed is unstable.
Relevant features
print
for logged output to be printed instead, generally for test writing.
§Example
extern crate escargot;
extern crate assert_fs;
let temp = assert_fs::TempDir::new().unwrap();
let run = escargot::CargoBuild::new()
.test("test")
.manifest_path("tests/fixtures/test/Cargo.toml")
.target_dir(temp.path())
.run_tests().unwrap()
.next().unwrap().unwrap();
println!("artifact={}", run.path().display());
Implementations§
source§impl CargoTest
impl CargoTest
sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
The name
of test
Used to offer filtering or displays.
§Example
extern crate escargot;
extern crate assert_fs;
let temp = assert_fs::TempDir::new().unwrap();
let run: Result<Vec<_>, _> = escargot::CargoBuild::new()
.tests()
.current_release()
.current_target()
.manifest_path("tests/fixtures/test/Cargo.toml")
.target_dir(temp.path())
.run_tests()
.unwrap()
.collect();
let run = run.unwrap();
let mut names: Vec<_> = run.iter().map(|r| r.name()).collect();
names.sort_unstable();
assert_eq!(names, ["test", "test_fixture", "test_fixture"]);
sourcepub fn kind(&self) -> &str
pub fn kind(&self) -> &str
The kind
of test
Used to distinguish between integration tests (test
) and unit tests (bin
, lib
).
§Example
extern crate escargot;
extern crate assert_fs;
let temp = assert_fs::TempDir::new().unwrap();
let run: Result<Vec<_>, _> = escargot::CargoBuild::new()
.tests()
.current_release()
.current_target()
.manifest_path("tests/fixtures/test/Cargo.toml")
.target_dir(temp.path())
.run_tests()
.unwrap()
.collect();
let run = run.unwrap();
let mut kinds: Vec<_> = run.iter().map(|r| r.kind()).collect();
kinds.sort_unstable();
assert_eq!(kinds, ["bin", "lib", "test"]);
sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
Path to the specified binary.
This is to support alternative ways of launching the binary besides Command
.
§Example
extern crate escargot;
extern crate assert_fs;
let temp = assert_fs::TempDir::new().unwrap();
let run: Vec<_> = escargot::CargoBuild::new()
.tests()
.current_release()
.current_target()
.manifest_path("tests/fixtures/test/Cargo.toml")
.target_dir(temp.path())
.run_tests()
.unwrap()
.collect();
assert_eq!(run.len(), 3);
sourcepub fn exec(&self) -> CargoResult<CommandMessages>
pub fn exec(&self) -> CargoResult<CommandMessages>
Run the configured test, returning test events.
Auto Trait Implementations§
impl RefUnwindSafe for CargoTest
impl Send for CargoTest
impl Sync for CargoTest
impl Unpin for CargoTest
impl UnwindSafe for CargoTest
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more