ghpascon_rust/utils/
path.rs1use std::path::PathBuf;
2
3pub fn get_working_dir() -> Result<PathBuf, std::io::Error> {
19 let exe = std::env::current_exe()?;
20 exe.parent().map(|p| p.to_path_buf()).ok_or_else(|| {
21 std::io::Error::new(
22 std::io::ErrorKind::NotFound,
23 "executable has no parent directory",
24 )
25 })
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31
32 #[test]
33 fn test_returns_existing_directory() {
34 let dir = get_working_dir().expect("get_working_dir failed");
35 assert!(dir.exists(), "directory should exist");
36 assert!(dir.is_dir(), "path should be a directory");
37 }
38}