diff options
Diffstat (limited to 'crates/turtle/src/atuin_common')
| -rw-r--r-- | crates/turtle/src/atuin_common/utils.rs | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/crates/turtle/src/atuin_common/utils.rs b/crates/turtle/src/atuin_common/utils.rs index aa662979..92b4e781 100644 --- a/crates/turtle/src/atuin_common/utils.rs +++ b/crates/turtle/src/atuin_common/utils.rs @@ -102,13 +102,9 @@ pub(crate) fn logs_dir() -> PathBuf { pub(crate) fn get_current_dir() -> String { // Prefer PWD environment variable over cwd if available to better support symbolic links - match env::var("PWD") { - Ok(v) => v, - Err(_) => match env::current_dir() { - Ok(dir) => dir.display().to_string(), - Err(_) => String::new(), - }, - } + env::var("PWD").unwrap_or_else(|_| { + env::current_dir().map_or_else(|_| String::new(), |dir| dir.display().to_string()) + }) } pub(crate) fn broken_symlink<P: Into<PathBuf>>(path: P) -> bool { @@ -150,22 +146,11 @@ impl<T: AsRef<str>> Escapable for T {} #[cfg(test)] mod tests { - use pretty_assertions::assert_ne; use super::*; use std::collections::HashSet; - #[cfg(not(windows))] - #[test] - fn test_dirs() { - // these tests need to be run sequentially to prevent race condition - test_config_dir_xdg(); - test_config_dir(); - test_data_dir_xdg(); - test_data_dir(); - } - #[test] fn uuid_is_unique() { let how_many: usize = 1_000_000; @@ -216,7 +201,7 @@ mod tests { #[test] fn in_git_repo_regular() { // regular git repo should resolve to the directory containing .git - let tmp = std::env::temp_dir().join("atuin-test-regular-git"); + let tmp = env::temp_dir().join("atuin-test-regular-git"); drop(std::fs::remove_dir_all(&tmp)); let subdir = tmp.join("src").join("deep"); std::fs::create_dir_all(&subdir).unwrap(); @@ -233,7 +218,7 @@ mod tests { fn in_git_repo_worktree_resolves_to_main_repo() { // worktree .git is a file pointing back to the main repo — // in_git_repo should follow it so all worktrees share a workspace - let tmp = std::env::temp_dir().join("atuin-test-worktree-git"); + let tmp = env::temp_dir().join("atuin-test-worktree-git"); drop(std::fs::remove_dir_all(&tmp)); // main repo at tmp/main with a real .git directory |
