diff --git a/Cargo.toml b/Cargo.toml index 2178d1b..5dffdfe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ name = "bin_fixture" predicates = { version = "1.0", default-features = false, features = ["difference"] } predicates-core = "1.0" predicates-tree = "1.0" -escargot = "0.3" +escargot = "0.4" [dev-dependencies] docmatic = "0.1" diff --git a/src/cargo.rs b/src/cargo.rs index b7c5942..6a88058 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -144,6 +144,46 @@ where /// [`Command`]: https://doc.rust-lang.org/std/process/struct.Command.html /// [`cargo`]: index.html fn cargo_example>(name: S) -> Result; + + /// Create a [`Command`] to run a specific binary of a specific crate from workspaces. + /// + /// See the [`cargo` module documentation][`cargo`] for caveats and workarounds. + /// + /// # Examples + /// + /// ```rust + /// use assert_cmd::prelude::*; + /// + /// use std::process::Command; + /// + /// let mut cmd = Command::cargo_crate_bin("assert_cmd", "bin_fixture") + /// .unwrap(); + /// let output = cmd.unwrap(); + /// ``` + /// + /// [`Command`]: https://doc.rust-lang.org/std/process/struct.Command.html + /// [`cargo`]: index.html + fn cargo_crate_bin>(package: S, name: S) -> Result; + + /// Create a [`Command`] to run a specific example of a specific crate from workspaces. + /// + /// See the [`cargo` module documentation][`cargo`] for caveats and workarounds. + /// + /// # Examples + /// + /// ```rust + /// use assert_cmd::prelude::*; + /// + /// use std::process::Command; + /// + /// let mut cmd = Command::cargo_crate_example("assert_cmd", "example_fixture") + /// .unwrap(); + /// let output = cmd.unwrap(); + /// ``` + /// + /// [`Command`]: https://doc.rust-lang.org/std/process/struct.Command.html + /// [`cargo`]: index.html + fn cargo_crate_example>(package: S, name: S) -> Result; } impl CommandCargoExt for process::Command { @@ -175,6 +215,28 @@ impl CommandCargoExt for process::Command { .map_err(CargoError::with_cause)?; Ok(runner.command()) } + + fn cargo_crate_bin>(package: S, name: S) -> Result { + let runner = escargot::CargoBuild::new() + .package(package) + .bin(name) + .current_release() + .current_target() + .run() + .map_err(CargoError::with_cause)?; + Ok(runner.command()) + } + + fn cargo_crate_example>(package: S, name: S) -> Result { + let runner = escargot::CargoBuild::new() + .package(package) + .example(name) + .current_release() + .current_target() + .run() + .map_err(CargoError::with_cause)?; + Ok(runner.command()) + } } /// Error when finding crate binary.