Skip to content

Commit 2e32822

Browse files
committed
fix(cargo): Point people to escargot
Fixes #44
1 parent fe0d12c commit 2e32822

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

src/cargo.rs

+34-16
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@
2020
//! .unwrap();
2121
//! ```
2222
//!
23-
//! Caching the binary's location:
23+
//! For caching to minimize cargo overhead or customize the build process, see [`escargot`].
2424
//!
25-
//! ```rust
25+
//! ```rust,ignore
2626
//! use assert_cmd::prelude::*;
27+
//! use escargot;
2728
//!
2829
//! use std::process::Command;
2930
//!
30-
//! let bin_under_test = assert_cmd::cargo::main_binary_path().unwrap();
31-
//! Command::new(&bin_under_test)
31+
//! let bin_under_test = escargot::CargoBuild::new()
32+
//! .bin("bin_fixture")
33+
//! .current_release()
34+
//! .current_target()
35+
//! .run()
36+
//! .unwrap();
37+
//! bin_under_test.command()
3238
//! .unwrap();
3339
//! ```
3440
//!
@@ -37,6 +43,7 @@
3743
//! [`lazy_static`]: https://crates.io/crates/lazy_static
3844
//! [`CommandCargoExt`]: trait.CommandCargoExt.html
3945
//! [`Command`]: https://doc.rust-lang.org/std/process/struct.Command.html
46+
//! [`escargot`]: https://docs.rs/escargot/
4047
4148
use std::error::Error;
4249
use std::ffi;
@@ -128,18 +135,29 @@ where
128135

129136
impl CommandCargoExt for process::Command {
130137
fn main_binary() -> Result<Self, CargoError> {
131-
let cmd = main_binary_path()?;
132-
Ok(process::Command::new(&cmd))
138+
let runner = escargot::CargoBuild::new()
139+
.current_release()
140+
.run()
141+
.map_err(CargoError::with_cause)?;
142+
Ok(runner.command())
133143
}
134144

135145
fn cargo_bin<S: AsRef<ffi::OsStr>>(name: S) -> Result<Self, CargoError> {
136-
let cmd = cargo_bin_path(name)?;
137-
Ok(process::Command::new(&cmd))
146+
let runner = escargot::CargoBuild::new()
147+
.bin(name)
148+
.current_release()
149+
.run()
150+
.map_err(CargoError::with_cause)?;
151+
Ok(runner.command())
138152
}
139153

140154
fn cargo_example<S: AsRef<ffi::OsStr>>(name: S) -> Result<Self, CargoError> {
141-
let cmd = cargo_example_path(name)?;
142-
Ok(process::Command::new(&cmd))
155+
let runner = escargot::CargoBuild::new()
156+
.example(name)
157+
.current_release()
158+
.run()
159+
.map_err(CargoError::with_cause)?;
160+
Ok(runner.command())
143161
}
144162
}
145163

@@ -160,9 +178,9 @@ impl CommandCargoExt for process::Command {
160178
/// Command::new(&bin_under_test)
161179
/// .unwrap();
162180
/// ```
181+
#[deprecated(since = "0.9.1", note = "For caching, using escargot directly.")]
163182
pub fn main_binary_path() -> Result<path::PathBuf, CargoError> {
164-
let runner = escargot::Cargo::new()
165-
.build()
183+
let runner = escargot::CargoBuild::new()
166184
.current_release()
167185
.run()
168186
.map_err(CargoError::with_cause)?;
@@ -184,9 +202,9 @@ pub fn main_binary_path() -> Result<path::PathBuf, CargoError> {
184202
/// Command::new(&bin_under_test)
185203
/// .unwrap();
186204
/// ```
205+
#[deprecated(since = "0.9.1", note = "For caching, using escargot directly.")]
187206
pub fn cargo_bin_path<S: AsRef<ffi::OsStr>>(name: S) -> Result<path::PathBuf, CargoError> {
188-
let runner = escargot::Cargo::new()
189-
.build()
207+
let runner = escargot::CargoBuild::new()
190208
.bin(name)
191209
.current_release()
192210
.run()
@@ -209,9 +227,9 @@ pub fn cargo_bin_path<S: AsRef<ffi::OsStr>>(name: S) -> Result<path::PathBuf, Ca
209227
/// Command::new(&bin_under_test)
210228
/// .unwrap();
211229
/// ```
230+
#[deprecated(since = "0.9.1", note = "For caching, using escargot directly.")]
212231
pub fn cargo_example_path<S: AsRef<ffi::OsStr>>(name: S) -> Result<path::PathBuf, CargoError> {
213-
let runner = escargot::Cargo::new()
214-
.build()
232+
let runner = escargot::CargoBuild::new()
215233
.example(name)
216234
.current_release()
217235
.run()

tests/cargo.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extern crate assert_cmd;
2+
extern crate escargot;
23
extern crate predicates;
34

45
use std::process;
@@ -46,3 +47,14 @@ fn cargo_example_with_empty_env() {
4647
cmd.env_clear().env("stdout", "42");
4748
cmd.assert().success().stdout("42\n");
4849
}
50+
51+
#[test]
52+
fn cargo_example_cache() {
53+
let bin_under_test = escargot::CargoBuild::new()
54+
.bin("bin_fixture")
55+
.current_release()
56+
.current_target()
57+
.run()
58+
.unwrap();
59+
bin_under_test.command().unwrap();
60+
}

0 commit comments

Comments
 (0)