Skip to content

Commit bdf5376

Browse files
committed
uutests: extend the path detection
1 parent 354a2d2 commit bdf5376

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tests/uutests/src/lib/util.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,38 @@ static END_OF_TRANSMISSION_SEQUENCE: &[u8] = b"\n\x04";
6363
// we can't use
6464
// pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_coreutils");
6565
// as we are in a library, not a binary
66+
6667
pub fn get_tests_binary() -> String {
6768
std::env::var("CARGO_BIN_EXE_coreutils").unwrap_or_else(|_| {
68-
let manifest_dir = env!("CARGO_MANIFEST_DIR");
69+
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
70+
let mut target_dir = manifest_dir.to_path_buf();
71+
72+
// Check for target directory at different levels
73+
for _ in 0..3 {
74+
target_dir.push("target");
75+
if target_dir.exists() {
76+
let debug_or_release = if cfg!(debug_assertions) {
77+
"debug"
78+
} else {
79+
"release"
80+
};
81+
return format!("{}/{}/coreutils", target_dir.display(), debug_or_release);
82+
}
83+
target_dir.pop();
84+
target_dir.pop();
85+
}
86+
87+
// If target directory not found, fallback to the manifest directory
6988
let debug_or_release = if cfg!(debug_assertions) {
7089
"debug"
7190
} else {
7291
"release"
7392
};
74-
format!("{manifest_dir}/../../target/{debug_or_release}/coreutils")
93+
format!(
94+
"{}/target/{}/coreutils",
95+
manifest_dir.display(),
96+
debug_or_release
97+
)
7598
})
7699
}
77100

0 commit comments

Comments
 (0)