mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 07:05:47 +02:00
add tests
This commit is contained in:
@ -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)
|
||||
|
@ -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());
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user