mirror of
https://github.com/nushell/nushell.git
synced 2025-02-26 23:42:03 +01:00
Comments, fix testcase problems found in 'toolkit check pr'
This commit is contained in:
parent
e6b677392a
commit
0ba5efd43d
@ -858,6 +858,7 @@ fn do_auto_cd(
|
|||||||
report_shell_error(engine_state, &err);
|
report_shell_error(engine_state, &err);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
// Let PWD-per-drive sync with auto_cd target
|
||||||
let _ = nu_path::set_pwd_per_drive(PathBuf::from(path.clone()).as_path());
|
let _ = nu_path::set_pwd_per_drive(PathBuf::from(path.clone()).as_path());
|
||||||
let cwd = Value::string(cwd, span);
|
let cwd = Value::string(cwd, span);
|
||||||
|
|
||||||
|
@ -114,6 +114,7 @@ impl Command for Cd {
|
|||||||
//FIXME: this only changes the current scope, but instead this environment variable
|
//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
|
//should probably be a block that loads the information from the state in the overlay
|
||||||
PermissionResult::PermissionOk => {
|
PermissionResult::PermissionOk => {
|
||||||
|
// Let PWD-per-drive sync with cd target
|
||||||
let _ = nu_path::set_pwd_per_drive(path.as_path());
|
let _ = nu_path::set_pwd_per_drive(path.as_path());
|
||||||
stack.set_cwd(path)?;
|
stack.set_cwd(path)?;
|
||||||
Ok(PipelineData::empty())
|
Ok(PipelineData::empty())
|
||||||
|
@ -159,7 +159,15 @@ mod tests {
|
|||||||
assert_eq!(map.get_pwd('C'), Some("C:\\Users\\Example".to_string()));
|
assert_eq!(map.get_pwd('C'), Some("C:\\Users\\Example".to_string()));
|
||||||
|
|
||||||
// Get PWD for drive E (not set, should return E:\)
|
// 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()));
|
assert_eq!(drive_map.get_pwd('D'), Some("D:\\Projects".to_string()));
|
||||||
|
|
||||||
// Get PWD for drive E (not set, should return E:\)
|
// 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]
|
#[test]
|
||||||
|
@ -21,6 +21,7 @@ fn expand_tilde_with_home(path: impl AsRef<Path>, home: Option<PathBuf>) -> Path
|
|||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
|
|
||||||
if !path.starts_with("~") {
|
if !path.starts_with("~") {
|
||||||
|
// Try to expand relative path by PWD-per-drive
|
||||||
if let Some(expanded_dir) = crate::expand_pwd_per_drive(path) {
|
if let Some(expanded_dir) = crate::expand_pwd_per_drive(path) {
|
||||||
return expanded_dir;
|
return expanded_dir;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ use log::{trace, Level};
|
|||||||
use miette::Result;
|
use miette::Result;
|
||||||
use nu_cli::gather_parent_env_vars;
|
use nu_cli::gather_parent_env_vars;
|
||||||
use nu_lsp::LanguageServer;
|
use nu_lsp::LanguageServer;
|
||||||
use nu_path::canonicalize_with;
|
use nu_path::{canonicalize_with, set_pwd_per_drive};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::EngineState, report_shell_error, ByteStream, PipelineData, ShellError, Span, Spanned,
|
engine::EngineState, report_shell_error, ByteStream, PipelineData, ShellError, Span, Spanned,
|
||||||
Value,
|
Value,
|
||||||
@ -78,6 +78,8 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
// Get the current working directory from the environment.
|
// Get the current working directory from the environment.
|
||||||
let init_cwd = current_dir_from_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
|
// Custom additions
|
||||||
let delta = {
|
let delta = {
|
||||||
|
Loading…
Reference in New Issue
Block a user