2020-05-07 13:03:43 +02:00
|
|
|
use nu_test_support::nu;
|
2020-01-16 10:05:53 +01:00
|
|
|
|
2020-07-18 03:59:23 +02:00
|
|
|
#[cfg(feature = "which")]
|
2020-01-16 10:05:53 +01:00
|
|
|
#[test]
|
|
|
|
fn shows_error_for_command_not_found() {
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(
|
2020-01-16 10:05:53 +01:00
|
|
|
cwd: ".",
|
|
|
|
"ferris_is_not_here.exe"
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert!(actual.err.contains("Command not found"));
|
2020-01-16 10:05:53 +01:00
|
|
|
}
|
|
|
|
|
2020-07-18 03:59:23 +02:00
|
|
|
#[cfg(feature = "which")]
|
2020-06-29 19:39:11 +02:00
|
|
|
#[test]
|
|
|
|
fn shows_error_for_command_not_found_in_pipeline() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
"ferris_is_not_here.exe | echo done"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(actual.err.contains("Command not found"));
|
|
|
|
}
|
|
|
|
|
2020-07-18 03:59:23 +02:00
|
|
|
#[cfg(feature = "which")]
|
2020-03-17 19:13:38 +01:00
|
|
|
#[test]
|
|
|
|
fn automatically_change_directory() {
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
|
|
|
|
Playground::setup("cd_test_5_1", |dirs, sandbox| {
|
2020-04-27 03:22:01 +02:00
|
|
|
sandbox.mkdir("autodir");
|
2020-03-17 19:13:38 +01:00
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
autodir
|
|
|
|
pwd | echo $it
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert!(actual.out.ends_with("autodir"));
|
2020-03-17 19:13:38 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-27 03:22:01 +02:00
|
|
|
#[test]
|
|
|
|
fn automatically_change_directory_with_trailing_slash_and_same_name_as_command() {
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
|
|
|
|
Playground::setup("cd_test_5_1", |dirs, sandbox| {
|
|
|
|
sandbox.mkdir("cd");
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
cd/
|
|
|
|
pwd | echo $it
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert!(actual.out.ends_with("cd"));
|
2020-04-27 03:22:01 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-30 06:54:07 +02:00
|
|
|
#[test]
|
|
|
|
fn correctly_escape_external_arguments() {
|
|
|
|
let actual = nu!(cwd: ".", r#"^echo '$0'"#);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "$0");
|
2020-04-30 06:54:07 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 10:05:53 +01:00
|
|
|
mod it_evaluation {
|
|
|
|
use super::nu;
|
2020-02-12 00:25:56 +01:00
|
|
|
use nu_test_support::fs::Stub::{EmptyFile, FileWithContent, FileWithContentToBeTrimmed};
|
2020-01-16 10:05:53 +01:00
|
|
|
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
|
2020-05-18 05:52:56 +02:00
|
|
|
| nu --testbin cococo $it
|
2020-01-16 10:05:53 +01:00
|
|
|
| lines
|
|
|
|
| nth 1
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "jonathan_likes_cake.txt");
|
2020-01-16 10:05:53 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
2020-05-18 05:52:56 +02:00
|
|
|
| nu --testbin chop $it
|
2020-01-16 10:05:53 +01:00
|
|
|
| lines
|
|
|
|
| nth 1
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "AndrásWithKitKat");
|
2020-01-16 10:05:53 +01:00
|
|
|
})
|
|
|
|
}
|
2020-02-12 00:25:56 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn supports_fetching_given_a_column_path_to_it() {
|
|
|
|
Playground::setup("it_argument_test_3", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
|
|
|
nu_party_venue = "zion"
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.toml
|
2020-05-18 06:07:10 +02:00
|
|
|
| nu --testbin cococo $it.nu_party_venue
|
2020-02-12 00:25:56 +01:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "zion");
|
2020-02-12 00:25:56 +01:00
|
|
|
})
|
|
|
|
}
|
2020-01-16 10:05:53 +01:00
|
|
|
}
|
|
|
|
|
2020-02-10 16:37:48 +01:00
|
|
|
mod stdin_evaluation {
|
2020-05-07 13:03:43 +02:00
|
|
|
use super::nu;
|
2020-02-10 16:37:48 +01:00
|
|
|
use nu_test_support::pipeline;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn does_not_panic_with_no_newline_in_stream() {
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(
|
2020-02-10 16:37:48 +01:00
|
|
|
cwd: ".",
|
|
|
|
pipeline(r#"
|
2020-05-18 05:52:56 +02:00
|
|
|
nu --testbin nonu "where's the nuline?"
|
2020-02-10 16:37:48 +01:00
|
|
|
| count
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.err, "");
|
2020-02-10 16:37:48 +01:00
|
|
|
}
|
2020-03-01 18:19:09 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn does_not_block_indefinitely() {
|
|
|
|
let stdout = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
pipeline(r#"
|
2020-05-18 05:52:56 +02:00
|
|
|
nu --testbin iecho yes
|
|
|
|
| nu --testbin chop
|
|
|
|
| nu --testbin chop
|
2020-03-06 17:06:39 +01:00
|
|
|
| lines
|
2020-03-01 18:19:09 +01:00
|
|
|
| first 1
|
|
|
|
"#
|
2020-05-07 13:03:43 +02:00
|
|
|
))
|
|
|
|
.out;
|
2020-03-01 18:19:09 +01:00
|
|
|
|
|
|
|
assert_eq!(stdout, "y");
|
|
|
|
}
|
2020-02-10 16:37:48 +01:00
|
|
|
}
|
|
|
|
|
2020-01-24 20:14:49 +01:00
|
|
|
mod external_words {
|
|
|
|
use super::nu;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn relaxed_external_words() {
|
|
|
|
let actual = nu!(cwd: ".", r#"
|
2020-05-18 05:52:56 +02:00
|
|
|
nu --testbin cococo joturner@foo.bar.baz
|
2020-01-24 20:14:49 +01:00
|
|
|
"#);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "joturner@foo.bar.baz");
|
2020-01-24 20:14:49 +01:00
|
|
|
}
|
2020-07-03 01:29:28 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_escaping_for_single_quoted_strings() {
|
|
|
|
let actual = nu!(cwd: ".", r#"
|
|
|
|
nu --testbin cococo 'test "things"'
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "test \"things\"");
|
|
|
|
}
|
2020-01-24 20:14:49 +01:00
|
|
|
}
|
|
|
|
|
2020-02-10 07:55:07 +01:00
|
|
|
mod nu_commands {
|
|
|
|
use super::nu;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn echo_internally_externally() {
|
|
|
|
let actual = nu!(cwd: ".", r#"
|
|
|
|
nu -c "echo 'foo'"
|
|
|
|
"#);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "foo");
|
2020-02-10 07:55:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 17:49:45 +01:00
|
|
|
mod nu_script {
|
|
|
|
use super::nu;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_nu_script() {
|
|
|
|
let actual = nu!(cwd: "tests/fixtures/formats", r#"
|
|
|
|
nu script.nu
|
|
|
|
"#);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "done");
|
2020-02-10 17:49:45 +01:00
|
|
|
}
|
2020-02-14 06:24:18 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_nu_script_multiline() {
|
|
|
|
let actual = nu!(cwd: "tests/fixtures/formats", r#"
|
|
|
|
nu script_multiline.nu
|
|
|
|
"#);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "23");
|
2020-02-14 06:24:18 +01:00
|
|
|
}
|
2020-02-10 17:49:45 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 10:05:53 +01:00
|
|
|
mod tilde_expansion {
|
|
|
|
use super::nu;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn as_home_directory_when_passed_as_argument_and_begins_with_tilde() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
r#"
|
2020-05-18 05:52:56 +02:00
|
|
|
nu --testbin cococo ~
|
2020-01-16 10:05:53 +01:00
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
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#"
|
2020-05-18 05:52:56 +02:00
|
|
|
nu --testbin cococo "1~1"
|
2020-01-16 10:05:53 +01:00
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "1~1");
|
2020-01-16 10:05:53 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-22 23:41:34 +02:00
|
|
|
|
|
|
|
mod external_command_arguments {
|
|
|
|
use super::nu;
|
|
|
|
use nu_test_support::fs::Stub::EmptyFile;
|
|
|
|
use nu_test_support::{pipeline, playground::Playground};
|
|
|
|
#[test]
|
|
|
|
fn expands_table_of_primitives_to_positional_arguments() {
|
|
|
|
Playground::setup(
|
|
|
|
"expands_table_of_primitives_to_positional_arguments",
|
|
|
|
|dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("jonathan_likes_cake.txt"),
|
|
|
|
EmptyFile("andres_likes_arepas.txt"),
|
|
|
|
EmptyFile("ferris_not_here.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
nu --testbin cococo $(ls | get name)
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual.out,
|
|
|
|
"andres_likes_arepas.txt ferris_not_here.txt jonathan_likes_cake.txt"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|