diff --git a/crates/cargo-test-support/Cargo.toml b/crates/cargo-test-support/Cargo.toml index c5e65d14b..b8ff77a29 100644 --- a/crates/cargo-test-support/Cargo.toml +++ b/crates/cargo-test-support/Cargo.toml @@ -11,6 +11,7 @@ doctest = false anyhow = "1.0.34" cargo-test-macro = { path = "../cargo-test-macro" } cargo-util = { path = "../cargo-util" } +snapbox = { version = "0.2.8", features = ["diff", "path"] } filetime = "0.2" flate2 = { version = "1.0", default-features = false, features = ["zlib"] } git2 = "0.14.2" diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index 97c9beedd..1ac21abcd 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -470,24 +470,8 @@ pub fn main_file(println: &str, deps: &[&str]) -> String { buf } -// Path to cargo executables -pub fn cargo_dir() -> PathBuf { - env::var_os("CARGO_BIN_PATH") - .map(PathBuf::from) - .or_else(|| { - env::current_exe().ok().map(|mut path| { - path.pop(); - if path.ends_with("deps") { - path.pop(); - } - path - }) - }) - .unwrap_or_else(|| panic!("CARGO_BIN_PATH wasn't set. Cannot continue running test")) -} - pub fn cargo_exe() -> PathBuf { - cargo_dir().join(format!("cargo{}", env::consts::EXE_SUFFIX)) + snapbox::cmd::cargo_bin("cargo") } /// This is the raw output from the process. diff --git a/tests/testsuite/cargo_add.rs b/tests/testsuite/cargo_add.rs index 4f7b5cd13..449f16638 100644 --- a/tests/testsuite/cargo_add.rs +++ b/tests/testsuite/cargo_add.rs @@ -1,6 +1,4 @@ -pub fn cargo_exe() -> &'static std::path::Path { - snapbox::cmd::cargo_bin!("cargo") -} +use cargo_test_support::cargo_exe; pub fn cargo_command() -> snapbox::cmd::Command { let mut cmd = snapbox::cmd::Command::new(cargo_exe()).with_assert(assert());