diff --git a/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs b/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs index 6590705c92..c8ad90e518 100644 --- a/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs +++ b/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs @@ -125,16 +125,6 @@ impl Command for OverlayUse { caller_stack, get_dirs_var_from_call(caller_stack, call), )?; - // module_arg_str maybe a directory, in this case - // find_in_dirs_env returns a directory. - let maybe_parent = maybe_file_path_or_dir.as_ref().and_then(|path| { - if path.is_dir() { - Some(path.to_path_buf()) - } else { - path.parent().map(|p| p.to_path_buf()) - } - }); - let block = engine_state.get_block(block_id); let mut callee_stack = caller_stack .gather_captures(engine_state, &block.captures) diff --git a/tests/overlays/mod.rs b/tests/overlays/mod.rs index f3126c8140..55ac5494ff 100644 --- a/tests/overlays/mod.rs +++ b/tests/overlays/mod.rs @@ -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,47 @@ 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("mod.nu"); + nu.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 ." + ); + + assert_eq!(actual.out, dirs.test().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("mod.nu"); + nu.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 ." + ); + + assert_eq!(actual.out, dirs.test().join("mod.nu").to_string_lossy()); + }); +}