Struct escargot::CargoRun

source ·
pub struct CargoRun { /* private fields */ }
Expand description

The run subcommand (emulated).

Created via CargoBuild::run.

Benefits over spawning cargo run:

  • Able to cache binary path, avoiding cargo overhead.
  • Independent of CWD.
  • stdout/stderr are clean of cargo run output.

Relevant features

  • print for logged output to be printed instead, generally for test writing.

§Example

To create a CargoRun:

let temp = assert_fs::TempDir::new().unwrap();
let run = escargot::CargoBuild::new()
    .bin("bin")
    .current_release()
    .current_target()
    .manifest_path("tests/fixtures/bin/Cargo.toml")
    .target_dir(temp.path())
    .run()
    .unwrap();
println!("artifact={}", run.path().display());

See CargoRun::path for how to then run the newly compiled program.

Implementations§

source§

impl CargoRun

source

pub fn path(&self) -> &Path

Path to the specified binary.

This is to support alternative ways of launching the binary besides Command.

§Example
let temp = assert_fs::TempDir::new().unwrap();
let run = escargot::CargoBuild::new()
    .bin("bin")
    .current_release()
    .current_target()
    .manifest_path("tests/fixtures/bin/Cargo.toml")
    .target_dir(temp.path())
    .run()
    .unwrap();
println!("artifact={}", run.path().display());

or

let temp = assert_fs::TempDir::new().unwrap();
let run = escargot::CargoBuild::new()
    .example("example_fixture")
    .current_release()
    .current_target()
    .manifest_path("tests/fixtures/example/Cargo.toml")
    .target_dir(temp.path())
    .run()
    .unwrap();
println!("artifact={}", run.path().display());
source

pub fn command(&self) -> Command

Run the build artifact.

§Example
let temp = assert_fs::TempDir::new().unwrap();
let run = escargot::CargoBuild::new()
    .bin("bin")
    .current_release()
    .current_target()
    .manifest_path("tests/fixtures/bin/Cargo.toml")
    .target_dir(temp.path())
    .run()
    .unwrap()
    .command()
    .arg("--help")
    .status()
    .unwrap();

or

extern crate escargot;
extern crate assert_fs;

let temp = assert_fs::TempDir::new().unwrap();
let run = escargot::CargoBuild::new()
    .example("example_fixture")
    .current_release()
    .current_target()
    .manifest_path("tests/fixtures/example/Cargo.toml")
    .target_dir(temp.path())
    .run()
    .unwrap()
    .command()
    .arg("--help")
    .status()
    .unwrap();

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.