mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 10:36:00 +02:00
fix $env.FILE_PWD and $env.CURRENT_FILE inside overlay use (#15126)
# Description Fixes: #14540 The change is similar to #14101 User input can be a directory, in this case, we need to use the return value of find_in_dirs_env carefully, so in case, I renamed maybe_file_path to maybe_file_path_or_dir to emphasize it. # User-Facing Changes NaN # Tests + Formatting Added 2 test cases # After Submitting
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::fs::Stub::{FileWithContent, FileWithContentToBeTrimmed};
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, nu_repl_code};
|
||||
use pretty_assertions::assert_eq;
|
||||
@ -1408,3 +1408,50 @@ fn overlay_help_no_error() {
|
||||
let actual = nu!("overlay use -h");
|
||||
assert!(actual.err.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_overlay_use_with_printing_file_pwd() {
|
||||
Playground::setup("use_with_printing_file_pwd", |dirs, nu| {
|
||||
let file = dirs.test().join("foo").join("mod.nu");
|
||||
nu.mkdir("foo").with_files(&[FileWithContent(
|
||||
file.as_os_str().to_str().unwrap(),
|
||||
r#"
|
||||
export-env {
|
||||
print $env.FILE_PWD
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"overlay use foo"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, dirs.test().join("foo").to_string_lossy());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_overlay_use_with_printing_current_file() {
|
||||
Playground::setup("use_with_printing_current_file", |dirs, nu| {
|
||||
let file = dirs.test().join("foo").join("mod.nu");
|
||||
nu.mkdir("foo").with_files(&[FileWithContent(
|
||||
file.as_os_str().to_str().unwrap(),
|
||||
r#"
|
||||
export-env {
|
||||
print $env.CURRENT_FILE
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"overlay use foo"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
dirs.test().join("foo").join("mod.nu").to_string_lossy()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user