pub struct Project {
pub(crate) root: PathBuf,
}
Expand description
A cargo project to run tests against.
See ProjectBuilder
or Project::from_template
to get started.
Fields§
§root: PathBuf
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: $CARGO_TARGET_TMPDIR/cit/t0/foo/target
sourcepub fn target_debug_dir(&self) -> PathBuf
pub fn target_debug_dir(&self) -> PathBuf
Project’s debug dir
ex: $CARGO_TARGET_TMPDIR/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: $CARGO_TARGET_TMPDIR/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: $CARGO_TARGET_TMPDIR/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: $CARGO_TARGET_TMPDIR/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: $CARGO_TARGET_TMPDIR/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 within Project::root
matching the glob pattern
sourcepub fn change_file(&self, path: &str, body: &str)
pub fn change_file(&self, path: &str, body: &str)
Overwrite a file with new content
p.change_file("src/lib.rs", "fn new_fn() {}");
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_data(str!["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.
For cargo run
, see Project::rename_run
.
§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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 24 bytes