From 3122d918bca5120033b59459092fea90b4bc3550 Mon Sep 17 00:00:00 2001 From: Zhenping Zhao Date: Thu, 19 Dec 2024 14:27:27 -0800 Subject: [PATCH] Test case for cd --- crates/nu-command/tests/commands/cd.rs | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/nu-command/tests/commands/cd.rs b/crates/nu-command/tests/commands/cd.rs index 1b8e2dad5a..20e41f946f 100644 --- a/crates/nu-command/tests/commands/cd.rs +++ b/crates/nu-command/tests/commands/cd.rs @@ -323,3 +323,39 @@ fn pwd_recovery() { assert_eq!(actual.out, "/"); } + +#[cfg(windows)] +#[test] +fn filesystem_from_non_root_change_to_another_drive_non_root_then_using_relative_path_go_back() { + Playground::setup("cd_test_22", |dirs, sandbox| { + sandbox.mkdir("test_folder"); + + let _actual = nu!( + cwd: dirs.test(), + r#" + touch test_folder/test_file.txt + "# + ); + assert!(dirs.test.exists()); + assert!(dirs.test.join("test_folder").exists()); + assert!(dirs.test.join("test_folder").join("test_file.txt").exists()); + let _actual = nu!( + cwd: dirs.test(), + r#" + subst X: /D | touch out + subst X: test_folder + cd x: + touch test_file_on_x.txt + echo $env.PWD + cd - + subst X: /D | touch out + echo $env.PWD + "# + ); + assert!(dirs.test.exists()); + assert!(dirs.test.join("test_folder").exists()); + assert!(_actual.out.ends_with(r"\cd_test_22")); + assert!(_actual.err.is_empty()); + assert!(dirs.test.join("test_folder").join("test_file_on_x.txt").exists()); + }) +}