Skip to content

Commit d104e7f

Browse files
committed
simplify binary discovery
1 parent 9597ab8 commit d104e7f

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

cli/tests/cli_integration.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ use std::path::PathBuf;
55
use std::process::Command;
66

77
fn bin_path() -> PathBuf {
8-
// Prefer Cargo-provided env var for the built binary
8+
// Prefer Cargo-provided env var for the built binary. This is the most reliable.
99
if let Ok(p) = env::var("CARGO_BIN_EXE_reasonable") {
1010
return PathBuf::from(p);
1111
}
12-
// Fallback: derive workspace `target` from manifest dir (robust in workspaces)
13-
let target_dir = env::var("CARGO_TARGET_DIR").ok().map(PathBuf::from).unwrap_or_else(|| {
14-
// `CARGO_MANIFEST_DIR` points to the `cli/` crate; workspace root is one level up
15-
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
16-
manifest_dir.parent().unwrap_or(&manifest_dir).join("target")
17-
});
18-
let mut p = target_dir;
19-
p.push("debug");
20-
p.push("reasonable");
12+
13+
// Inspired by similar projects: derive target dir from the crate location and
14+
// probe debug then release (with Windows .exe suffix when applicable).
15+
let base = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..").join("target");
16+
let exe = if cfg!(windows) { "reasonable.exe" } else { "reasonable" };
17+
18+
let mut p = base.join("debug").join(exe);
2119
if !p.exists() {
22-
panic!("could not locate CLI binary at {}", p.display());
20+
p = base.join("release").join(exe);
2321
}
22+
assert!(p.exists(), "reasonable binary not found at {:?}", p);
2423
p
2524
}
2625

0 commit comments

Comments
 (0)