Struct cargo_test_support::Project
source · pub struct Project { /* private fields */ }
Expand description
A cargo project to run tests against.
See ProjectBuilder
or Project::from_template
to get started.
Implementations§
source§impl Project
impl Project
sourcepub fn from_template(template_path: impl AsRef<Path>) -> Self
pub fn from_template(template_path: impl AsRef<Path>) -> Self
Copy the test project from a fixed state
sourcepub fn build_dir(&self) -> PathBuf
pub fn build_dir(&self) -> PathBuf
Project’s target dir, ex: /path/to/cargo/target/cit/t0/foo/target
sourcepub fn target_debug_dir(&self) -> PathBuf
pub fn target_debug_dir(&self) -> PathBuf
Project’s debug dir, ex: /path/to/cargo/target/cit/t0/foo/target/debug
sourcepub fn example_lib(&self, name: &str, kind: &str) -> PathBuf
pub fn example_lib(&self, name: &str, kind: &str) -> PathBuf
Path to an example built as a library.
kind
should be one of: “lib”, “rlib”, “staticlib”, “dylib”, “proc-macro”
ex: /path/to/cargo/target/cit/t0/foo/target/debug/examples/libex.rlib
sourcepub fn bin(&self, b: &str) -> PathBuf
pub fn bin(&self, b: &str) -> PathBuf
Path to a debug binary.
ex: /path/to/cargo/target/cit/t0/foo/target/debug/foo
sourcepub fn release_bin(&self, b: &str) -> PathBuf
pub fn release_bin(&self, b: &str) -> PathBuf
Path to a release binary.
ex: /path/to/cargo/target/cit/t0/foo/target/release/foo
sourcepub fn target_bin(&self, target: &str, b: &str) -> PathBuf
pub fn target_bin(&self, target: &str, b: &str) -> PathBuf
Path to a debug binary for a specific target triple.
ex: /path/to/cargo/target/cit/t0/foo/target/i686-apple-darwin/debug/foo
sourcepub fn glob<P: AsRef<Path>>(&self, pattern: P) -> Paths
pub fn glob<P: AsRef<Path>>(&self, pattern: P) -> Paths
Returns an iterator of paths matching the glob pattern, which is relative to the project root.
sourcepub fn change_file(&self, path: &str, body: &str)
pub fn change_file(&self, path: &str, body: &str)
Changes the contents of an existing file.
sourcepub fn process<T: AsRef<OsStr>>(&self, program: T) -> Execs
pub fn process<T: AsRef<OsStr>>(&self, program: T) -> Execs
Creates a ProcessBuilder
to run a program in the project
and wrap it in an Execs to assert on the execution.
Example:
p.process(&p.bin(“foo”))
.with_stdout(“bar\n”)
.run();
sourcepub fn cargo(&self, cmd: &str) -> Execs
pub fn cargo(&self, cmd: &str) -> Execs
Creates a ProcessBuilder
to run cargo.
Arguments can be separated by spaces.
Example:
p.cargo(“build –bin foo”).run();
sourcepub fn rename_run(&self, src: &str, dst: &str) -> Execs
pub fn rename_run(&self, src: &str, dst: &str) -> Execs
Safely run a process after cargo build
.
Windows has a problem where a process cannot be reliably be replaced, removed, or renamed immediately after executing it. The action may fail (with errors like Access is denied), or it may succeed, but future attempts to use the same filename will fail with “Already Exists”.
If you have a test that needs to do cargo run
multiple
times, you should instead use cargo build
and use this
method to run the executable. Each time you call this,
use a new name for dst
.
See rust-lang/cargo#5481.
sourcepub fn read_lockfile(&self) -> String
pub fn read_lockfile(&self) -> String
Returns the contents of Cargo.lock
.
sourcepub fn read_file(&self, path: &str) -> String
pub fn read_file(&self, path: &str) -> String
Returns the contents of a path in the project root
sourcepub fn uncomment_root_manifest(&self)
pub fn uncomment_root_manifest(&self)
Modifies Cargo.toml
to remove all commented lines.
pub fn symlink(&self, src: impl AsRef<Path>, dst: impl AsRef<Path>)
Auto Trait Implementations§
impl Freeze for Project
impl RefUnwindSafe for Project
impl Send for Project
impl Sync for Project
impl Unpin for Project
impl UnwindSafe for Project
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
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more