use std::path::PathBuf;
pub fn get_working_dir() -> Result<PathBuf, std::io::Error> {
let exe = std::env::current_exe()?;
exe.parent().map(|p| p.to_path_buf()).ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::NotFound,
"executable has no parent directory",
)
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_returns_existing_directory() {
let dir = get_working_dir().expect("get_working_dir failed");
assert!(dir.exists(), "directory should exist");
assert!(dir.is_dir(), "path should be a directory");
}
}