use std::path::PathBuf;
use std::sync::OnceLock;
static SELF_EXE: OnceLock<Option<PathBuf>> = OnceLock::new();
pub(crate) fn self_exe() -> Option<&'static PathBuf> {
SELF_EXE.get_or_init(probe).as_ref()
}
fn probe() -> Option<PathBuf> {
std::env::current_exe().ok()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn returns_a_path_to_an_existing_file() {
let p = self_exe().expect("self_exe should resolve");
assert!(p.exists(), "self_exe path {p:?} should exist");
}
#[test]
fn cached_across_calls() {
let a = self_exe().cloned();
let b = self_exe().cloned();
assert_eq!(a, b);
}
}