Comments, fix testcase problems found in 'toolkit check pr'

This commit is contained in:
Zhenping Zhao
2024-11-21 10:38:34 -08:00
parent e6b677392a
commit 0ba5efd43d
5 changed files with 25 additions and 3 deletions

View File

@ -159,7 +159,15 @@ mod tests {
assert_eq!(map.get_pwd('C'), Some("C:\\Users\\Example".to_string()));
// Get PWD for drive E (not set, should return E:\)
assert_eq!(map.get_pwd('E'), Some("E:\\".to_string()));
// 11-21-2024 happened to start nushell from drive E:,
// run toolkit test 'toolkit check pr' then this test failed
// since the singleton has its own state, so this type of test ('not set,
// should return ...') must be more careful to avoid accidentally fail.
if let Some(pwd_on_e) = get_full_path_name_w("E:") {
assert_eq!(map.get_pwd('E'), Some(pwd_on_e));
} else {
assert_eq!(map.get_pwd('E'), Some("E:\\".to_string()));
}
}
}
@ -200,7 +208,16 @@ mod tests {
assert_eq!(drive_map.get_pwd('D'), Some("D:\\Projects".to_string()));
// Get PWD for drive E (not set, should return E:\)
assert_eq!(drive_map.get_pwd('E'), Some("E:\\".to_string()));
// 11-21-2024 happened to start nushell from drive E:,
// run toolkit test 'toolkit check pr' then this test failed
// if a drive has not been set PWD, it will ask system to get
// current directory, so this type of test ('not set, should
// return ...') must be more careful to avoid accidentally fail.
if let Some(pwd_on_e) = get_full_path_name_w("E:") {
assert_eq!(drive_map.get_pwd('E'), Some(pwd_on_e));
} else {
assert_eq!(drive_map.get_pwd('E'), Some("E:\\".to_string()));
}
}
#[test]

View File

@ -21,6 +21,7 @@ fn expand_tilde_with_home(path: impl AsRef<Path>, home: Option<PathBuf>) -> Path
let path = path.as_ref();
if !path.starts_with("~") {
// Try to expand relative path by PWD-per-drive
if let Some(expanded_dir) = crate::expand_pwd_per_drive(path) {
return expanded_dir;
}