use std::path::Path;
#[must_use]
pub fn binary_on_path(binary: &str) -> bool {
let Ok(path) = std::env::var("PATH") else {
return false;
};
for dir in path.split(':') {
let candidate = Path::new(dir).join(binary);
if candidate.is_file() {
return true;
}
}
false
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
#[test]
fn finds_existing_binary() {
assert!(binary_on_path("sh"));
}
#[test]
fn misses_nonexistent_binary() {
assert!(!binary_on_path("definitely-not-a-binary-xyz-common-12345"));
}
}