forked from extern/nushell
Externals now spawn independently. (#1230)
This commit changes the way we shell out externals when using the `"$it"` argument. Also pipes per row to an external's stdin if no `"$it"` argument is present for external commands. Further separation of logic (preparing the external's command arguments, getting the data for piping, emitting values, spawning processes) will give us a better idea for lower level details regarding external commands until we can find the right abstractions for making them more generic and unify within the pipeline calling logic of Nu internal's and external's.
This commit is contained in:
committed by
GitHub
parent
d29fe6f6de
commit
29431e73c2
110
tests/shell/pipeline/commands/external.rs
Normal file
110
tests/shell/pipeline/commands/external.rs
Normal file
@ -0,0 +1,110 @@
|
||||
use nu_test_support::{nu, nu_error};
|
||||
|
||||
#[test]
|
||||
fn shows_error_for_command_that_fails() {
|
||||
let actual = nu_error!(
|
||||
cwd: ".",
|
||||
"fail"
|
||||
);
|
||||
|
||||
assert!(actual.contains("External command failed"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shows_error_for_command_not_found() {
|
||||
let actual = nu_error!(
|
||||
cwd: ".",
|
||||
"ferris_is_not_here.exe"
|
||||
);
|
||||
|
||||
assert!(actual.contains("Command not found"));
|
||||
}
|
||||
|
||||
mod it_evaluation {
|
||||
use super::nu;
|
||||
use nu_test_support::fs::Stub::{EmptyFile, FileWithContentToBeTrimmed};
|
||||
use nu_test_support::{pipeline, playground::Playground};
|
||||
|
||||
#[test]
|
||||
fn takes_rows_of_nu_value_strings() {
|
||||
Playground::setup("it_argument_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("jonathan_likes_cake.txt"),
|
||||
EmptyFile("andres_likes_arepas.txt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| sort-by name
|
||||
| get name
|
||||
| cococo $it
|
||||
| lines
|
||||
| nth 1
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual, "jonathan_likes_cake.txt");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn takes_rows_of_nu_value_lines() {
|
||||
Playground::setup("it_argument_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"nu_candies.txt",
|
||||
r#"
|
||||
AndrásWithKitKatzz
|
||||
AndrásWithKitKatz
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open nu_candies.txt
|
||||
| lines
|
||||
| chop $it
|
||||
| lines
|
||||
| nth 1
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual, "AndrásWithKitKat");
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
mod tilde_expansion {
|
||||
use super::nu;
|
||||
|
||||
#[test]
|
||||
fn as_home_directory_when_passed_as_argument_and_begins_with_tilde() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
r#"
|
||||
cococo ~
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
!actual.contains('~'),
|
||||
format!("'{}' should not contain ~", actual)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_not_expand_when_passed_as_argument_and_does_not_start_with_tilde() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
r#"
|
||||
cococo "1~1"
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(actual, "1~1");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user