|
20 | 20 |
|
21 | 21 | #![allow(clippy::disallowed_methods)]
|
22 | 22 |
|
23 |
| -use cargo_test_support::prelude::*; |
24 | 23 | use cargo_test_support::{basic_manifest, paths, project, rustc_host, str, Execs};
|
| 24 | +use cargo_test_support::{prelude::*, Project}; |
25 | 25 | use std::env;
|
26 |
| -use std::path::Path; |
| 26 | +use std::path::{Path, PathBuf}; |
27 | 27 |
|
28 | 28 | fn enable_build_std(e: &mut Execs, arg: Option<&str>, isolated: bool) {
|
29 | 29 | if !isolated {
|
@@ -441,3 +441,34 @@ fn test_panic_abort() {
|
441 | 441 | .arg("-Zbuild-std-features=panic_immediate_abort")
|
442 | 442 | .run();
|
443 | 443 | }
|
| 444 | + |
| 445 | +pub trait CargoProjectExt { |
| 446 | + /// Creates a `ProcessBuilder` to run cargo. |
| 447 | + /// |
| 448 | + /// Arguments can be separated by spaces. |
| 449 | + /// |
| 450 | + /// For `cargo run`, see [`Project::rename_run`]. |
| 451 | + /// |
| 452 | + /// # Example: |
| 453 | + /// |
| 454 | + /// ```no_run |
| 455 | + /// # let p = cargo_test_support::project().build(); |
| 456 | + /// p.cargo("build --bin foo").run(); |
| 457 | + /// ``` |
| 458 | + fn cargo(&self, cmd: &str) -> Execs; |
| 459 | +} |
| 460 | + |
| 461 | +impl CargoProjectExt for Project { |
| 462 | + fn cargo(&self, cmd: &str) -> Execs { |
| 463 | + let cargo = cargo_exe(); |
| 464 | + let mut execs = self.process(&cargo); |
| 465 | + execs.env("CARGO", cargo); |
| 466 | + execs.arg_line(cmd); |
| 467 | + execs |
| 468 | + } |
| 469 | +} |
| 470 | + |
| 471 | +/// Path to the cargo binary |
| 472 | +pub fn cargo_exe() -> PathBuf { |
| 473 | + snapbox::cmd::cargo_bin!("cargo").to_path_buf() |
| 474 | +} |
0 commit comments