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

@ -858,6 +858,7 @@ fn do_auto_cd(
report_shell_error(engine_state, &err);
return;
};
// Let PWD-per-drive sync with auto_cd target
let _ = nu_path::set_pwd_per_drive(PathBuf::from(path.clone()).as_path());
let cwd = Value::string(cwd, span);

View File

@ -114,6 +114,7 @@ impl Command for Cd {
//FIXME: this only changes the current scope, but instead this environment variable
//should probably be a block that loads the information from the state in the overlay
PermissionResult::PermissionOk => {
// Let PWD-per-drive sync with cd target
let _ = nu_path::set_pwd_per_drive(path.as_path());
stack.set_cwd(path)?;
Ok(PipelineData::empty())

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;
}

View File

@ -22,7 +22,7 @@ use log::{trace, Level};
use miette::Result;
use nu_cli::gather_parent_env_vars;
use nu_lsp::LanguageServer;
use nu_path::canonicalize_with;
use nu_path::{canonicalize_with, set_pwd_per_drive};
use nu_protocol::{
engine::EngineState, report_shell_error, ByteStream, PipelineData, ShellError, Span, Spanned,
Value,
@ -78,6 +78,8 @@ fn main() -> Result<()> {
// Get the current working directory from the environment.
let init_cwd = current_dir_from_environment();
// Let PWD-per-drive sync from startup
let _ = set_pwd_per_drive(init_cwd.as_ref());
// Custom additions
let delta = {