fix(tests): use CARGO_BIN_EXE to locate binary in integration tests

Signed-off-by: Jeremiah Russell <jerry@jrussell.ie>
This commit is contained in:
Jeremiah Russell
2026-03-13 09:04:49 +00:00
parent 27e915ca9e
commit 4c1eeed863

View File

@@ -29,43 +29,10 @@ mod test_utils {
let config_dir = temp_dir.path().join(".config").join("cull-gmail"); let config_dir = temp_dir.path().join(".config").join("cull-gmail");
fs::create_dir_all(&config_dir)?; fs::create_dir_all(&config_dir)?;
// Get the path to the compiled binary - try multiple locations // Use CARGO_BIN_EXE_cull-gmail, set by Cargo at compile time to the
let binary_path = if let Ok(manifest_dir) = std::env::var("CARGO_MANIFEST_DIR") { // actual binary path. Works correctly in workspaces and with tools
// Running under cargo test - binary is in workspace root target/ // that override the target directory (e.g. cargo llvm-cov).
// CARGO_MANIFEST_DIR = crates/cull-gmail, so go up two levels let binary_path = PathBuf::from(env!("CARGO_BIN_EXE_cull-gmail"));
let workspace_root = PathBuf::from(&manifest_dir).join("../..").canonicalize()?;
let release_binary = workspace_root
.join("target")
.join("release")
.join("cull-gmail");
if release_binary.exists() {
release_binary
} else {
workspace_root
.join("target")
.join("debug")
.join("cull-gmail")
}
} else if let Ok(target_dir) = std::env::var("CARGO_TARGET_DIR") {
// CI environments may set CARGO_TARGET_DIR
let release_binary = PathBuf::from(&target_dir)
.join("release")
.join("cull-gmail");
if release_binary.exists() {
release_binary
} else {
PathBuf::from(&target_dir).join("debug").join("cull-gmail")
}
} else {
// Fallback for other scenarios
std::env::current_exe()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.join("cull-gmail")
};
// Validate that the binary exists // Validate that the binary exists
if !binary_path.exists() { if !binary_path.exists() {