From ec38383adb45e8ad12cd03601883792cbf3fd37b Mon Sep 17 00:00:00 2001
From: Justus Winter <justus@sequoia-pgp.org>
Date: Tue, 1 Apr 2025 09:18:52 +0200
Subject: [PATCH 5/5] tests: Rely on cargo building the binary, simplify
 locating it.

  - This should be more robust as we rely on cargo to build sq-git,
    and let cargo tell us where to find it.

  - Also, this now tests the release build, whereas previously we
    would build and test the debug build even if the tests were run in
    release mode.
---
 tests/common.rs | 21 +--------------------
 1 file changed, 1 insertion(+), 20 deletions(-)

diff --git a/tests/common.rs b/tests/common.rs
index 47ea017..8442705 100644
--- a/tests/common.rs
+++ b/tests/common.rs
@@ -515,26 +515,7 @@ impl Environment {
     }
 
     pub fn sq_git_path() -> Result<PathBuf> {
-        use std::sync::Once;
-        static BUILD: Once = Once::new();
-        BUILD.call_once(|| {
-            let o = Command::new("cargo")
-                .arg("build").arg("--quiet")
-                .arg("--bin").arg("sq-git")
-                .output()
-                .expect("running cargo failed");
-            if ! o.status.success() {
-                panic!("build failed:\n\nstdout:\n{}\n\n stderr:\n{}",
-                        String::from_utf8_lossy(&o.stdout),
-                        String::from_utf8_lossy(&o.stderr));
-            }
-        });
-
-        Ok(if let Ok(target) = std::env::var("CARGO_TARGET_DIR") {
-            PathBuf::from(target).canonicalize()?
-        } else {
-            std::env::current_dir()?.join("target")
-        }.join("debug/sq-git"))
+        Ok(env!("CARGO_BIN_EXE_sq-git").into())
     }
 
     pub fn sq_git<A: AsRef<str>>(&self, args: &[A]) -> std::result::Result<Output, Error> {
-- 
2.43.0

