forked from extern/nushell
29431e73c2
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.
76 lines
1.7 KiB
Rust
76 lines
1.7 KiB
Rust
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
use nu_test_support::nu;
|
|
use nu_test_support::{pipeline, playground::Playground};
|
|
|
|
#[test]
|
|
fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() {
|
|
Playground::setup("internal_to_external_pipe_test_1", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
"nu_times.csv",
|
|
r#"
|
|
name,rusty_luck,origin
|
|
Jason,1,Canada
|
|
Jonathan,1,New Zealand
|
|
Andrés,1,Ecuador
|
|
AndKitKatz,1,Estados Unidos
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(), pipeline(
|
|
r#"
|
|
open nu_times.csv
|
|
| get name
|
|
| chop
|
|
| lines
|
|
| nth 3
|
|
| echo $it
|
|
"#
|
|
));
|
|
|
|
assert_eq!(actual, "AndKitKat");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn can_process_one_row_from_internal_and_pipes_it_to_stdin_of_external() {
|
|
let actual = nu!(
|
|
cwd: ".",
|
|
r#"echo "nushelll" | chop"#
|
|
);
|
|
|
|
assert_eq!(actual, "nushell");
|
|
}
|
|
|
|
mod tilde_expansion {
|
|
use super::nu;
|
|
|
|
#[test]
|
|
#[should_panic]
|
|
fn as_home_directory_when_passed_as_argument_and_begins_with_tilde() {
|
|
let actual = nu!(
|
|
cwd: ".",
|
|
r#"
|
|
echo ~
|
|
"#
|
|
);
|
|
|
|
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#"
|
|
echo "1~1"
|
|
"#
|
|
);
|
|
|
|
assert_eq!(actual, "1~1");
|
|
}
|
|
}
|