2020-05-16 09:25:18 +02:00
|
|
|
use nu_test_support::fs::Stub::EmptyFile;
|
2020-01-16 10:05:53 +01:00
|
|
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
|
|
use nu_test_support::nu;
|
2020-05-16 09:25:18 +02:00
|
|
|
use nu_test_support::pipeline;
|
|
|
|
use nu_test_support::playground::Playground;
|
2020-01-16 10:05:53 +01:00
|
|
|
|
|
|
|
#[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
|
2020-02-09 02:57:05 +01:00
|
|
|
| ^echo $it
|
2020-05-18 05:52:56 +02:00
|
|
|
| nu --testbin chop
|
2020-01-16 10:05:53 +01:00
|
|
|
| nth 3
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "AndKitKat");
|
2020-01-16 10:05:53 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-16 09:25:18 +02:00
|
|
|
#[test]
|
|
|
|
fn proper_it_expansion() {
|
|
|
|
Playground::setup("ls_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("andres.txt"),
|
|
|
|
EmptyFile("gedge.txt"),
|
|
|
|
EmptyFile("jonathan.txt"),
|
|
|
|
EmptyFile("yehuda.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
ls | sort-by name | group-by type | each { get File.name | echo $it } | to json
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual.out,
|
|
|
|
r#"["andres.txt","gedge.txt","jonathan.txt","yehuda.txt"]"#
|
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn argument_invocation() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
r#"
|
|
|
|
echo "foo" | echo $(echo $it)
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "foo");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invocation_handles_dot() {
|
|
|
|
Playground::setup("invocation_handles_dot", |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#"
|
|
|
|
echo $(open nu_times.csv)
|
|
|
|
| get name
|
|
|
|
| ^echo $it
|
2020-05-18 05:52:56 +02:00
|
|
|
| nu --testbin chop
|
2020-05-16 09:25:18 +02:00
|
|
|
| nth 3
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "AndKitKat");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-01-16 10:05:53 +01:00
|
|
|
#[test]
|
|
|
|
fn can_process_one_row_from_internal_and_pipes_it_to_stdin_of_external() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
2020-05-18 05:52:56 +02:00
|
|
|
r#"echo "nushelll" | nu --testbin chop"#
|
2020-01-16 10:05:53 +01:00
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "nushell");
|
2020-01-16 10:05:53 +01:00
|
|
|
}
|
|
|
|
|
2020-02-13 08:34:43 +01:00
|
|
|
mod parse {
|
2020-05-07 13:03:43 +02:00
|
|
|
use nu_test_support::nu;
|
2020-02-13 08:34:43 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
The debug command's signature is:
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
> debug {flags}
|
|
|
|
|
|
|
|
flags:
|
|
|
|
-h, --help: Display this help message
|
|
|
|
-r, --raw: Prints the raw value representation.
|
|
|
|
*/
|
|
|
|
|
2020-02-18 07:58:30 +01:00
|
|
|
#[test]
|
|
|
|
fn errors_if_flag_passed_is_not_exact() {
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(cwd: ".", "debug -ra");
|
2020-02-18 07:58:30 +01:00
|
|
|
|
|
|
|
assert!(
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err.contains("unexpected flag"),
|
2020-02-18 07:58:30 +01:00
|
|
|
format!(
|
|
|
|
"error message '{}' should contain 'unexpected flag'",
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err
|
2020-02-18 07:58:30 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(cwd: ".", "debug --rawx");
|
2020-02-18 07:58:30 +01:00
|
|
|
|
|
|
|
assert!(
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err.contains("unexpected flag"),
|
2020-02-18 07:58:30 +01:00
|
|
|
format!(
|
|
|
|
"error message '{}' should contain 'unexpected flag'",
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err
|
2020-02-18 07:58:30 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-13 08:34:43 +01:00
|
|
|
#[test]
|
|
|
|
fn errors_if_flag_is_not_supported() {
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(cwd: ".", "debug --ferris");
|
2020-02-13 08:34:43 +01:00
|
|
|
|
|
|
|
assert!(
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err.contains("unexpected flag"),
|
2020-02-13 08:34:43 +01:00
|
|
|
format!(
|
|
|
|
"error message '{}' should contain 'unexpected flag'",
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err
|
2020-02-13 08:34:43 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn errors_if_passed_an_unexpected_argument() {
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(cwd: ".", "debug ferris");
|
2020-02-13 08:34:43 +01:00
|
|
|
|
|
|
|
assert!(
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err.contains("unexpected argument"),
|
2020-02-13 08:34:43 +01:00
|
|
|
format!(
|
|
|
|
"error message '{}' should contain 'unexpected argument'",
|
2020-05-07 13:03:43 +02:00
|
|
|
actual.err
|
2020-02-13 08:34:43 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 10:05:53 +01:00
|
|
|
mod tilde_expansion {
|
2020-05-16 09:25:18 +02:00
|
|
|
use nu_test_support::nu;
|
2020-01-16 10:05:53 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn as_home_directory_when_passed_as_argument_and_begins_with_tilde() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
r#"
|
|
|
|
echo ~
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(
|
2020-05-07 13:03:43 +02:00
|
|
|
!actual.out.contains('~'),
|
|
|
|
format!("'{}' should not contain ~", actual.out)
|
2020-01-16 10:05:53 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn does_not_expand_when_passed_as_argument_and_does_not_start_with_tilde() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
r#"
|
|
|
|
echo "1~1"
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "1~1");
|
2020-01-16 10:05:53 +01:00
|
|
|
}
|
|
|
|
}
|