From 4894657bcbd1c45a797391fc3580699bcddf8a9d Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Sat, 14 Feb 2026 16:01:45 +0100 Subject: [PATCH] cli-test: Simplify cargo path handling --- crates/radicle-cli-test/src/lib.rs | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/crates/radicle-cli-test/src/lib.rs b/crates/radicle-cli-test/src/lib.rs index 2f2a54b1..3cadfe4d 100644 --- a/crates/radicle-cli-test/src/lib.rs +++ b/crates/radicle-cli-test/src/lib.rs @@ -187,21 +187,6 @@ impl TestFormula { } pub fn build(&mut self, binaries: &[(&str, &str)]) -> &mut Self { - let manifest = env::var("CARGO_MANIFEST_DIR").expect( - "TestFormula::build: cannot build binaries: variable `CARGO_MANIFEST_DIR` is not set", - ); - let profile = if cfg!(debug_assertions) { - "debug" - } else { - "release" - }; - let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string()); - let manifest = Path::new(manifest.as_str()); - let bins = manifest.join(&target_dir).join(profile); - - // Add the target dir to the beginning of the list we will use as `PATH`. - self.bins.insert(0, bins); - // We don't need to re-build every time the `build` function is called. Once is enough. BUILD.call_once(|| { use escargot::format::Message; @@ -220,8 +205,6 @@ impl TestFormula { let results = escargot::CargoBuild::new() .package(package) .bin(binary) - .manifest_path(manifest.join("Cargo.toml")) - .target_dir(&target_dir) .exec() .unwrap(); @@ -539,6 +522,19 @@ fn bins(cwd: PathBuf) -> Vec { .map(|env_path| env_path.split(PATH_SEPARATOR).map(PathBuf::from).collect()) .unwrap_or_default(); + if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") { + let profile = cfg!(debug_assertions) + .then_some("debug") + .unwrap_or("release"); + let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string()); + + bins.push( + PathBuf::from(manifest_dir.as_str()) + .join(&target_dir) + .join(profile), + ) + } + // Add current working directory to `$PATH`, // this makes it more convenient to execute scripts during testing. bins.push(cwd);