2020-01-16 09:05:53 +00:00
|
|
|
use nu_test_support::{nu, nu_error};
|
|
|
|
|
2020-01-23 19:24:31 +00:00
|
|
|
// #[test]
|
|
|
|
// fn shows_error_for_command_that_fails() {
|
|
|
|
// let actual = nu_error!(
|
|
|
|
// cwd: ".",
|
|
|
|
// "fail"
|
|
|
|
// );
|
2020-01-16 09:05:53 +00:00
|
|
|
|
2020-01-23 19:24:31 +00:00
|
|
|
// assert!(actual.contains("External command failed"));
|
|
|
|
// }
|
2020-01-16 09:05:53 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn shows_error_for_command_not_found() {
|
|
|
|
let actual = nu_error!(
|
|
|
|
cwd: ".",
|
|
|
|
"ferris_is_not_here.exe"
|
|
|
|
);
|
|
|
|
|
2020-01-23 19:24:31 +00:00
|
|
|
assert!(actual.contains("Command not found"));
|
2020-01-16 09:05:53 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 18:13:38 +00:00
|
|
|
#[test]
|
|
|
|
fn automatically_change_directory() {
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
|
|
|
|
Playground::setup("cd_test_5_1", |dirs, sandbox| {
|
|
|
|
sandbox.within("autodir").mkdir("bar");
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
r#"
|
|
|
|
autodir
|
|
|
|
pwd | echo $it
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(actual.ends_with("autodir"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-01-16 09:05:53 +00:00
|
|
|
mod it_evaluation {
|
|
|
|
use super::nu;
|
2020-02-11 23:25:56 +00:00
|
|
|
use nu_test_support::fs::Stub::{EmptyFile, FileWithContent, FileWithContentToBeTrimmed};
|
2020-01-16 09:05:53 +00: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
|
|
|
|
| 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");
|
|
|
|
})
|
|
|
|
}
|
2020-02-11 23:25:56 +00: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
|
|
|
|
| cococo $it.nu_party_venue
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "zion");
|
|
|
|
})
|
|
|
|
}
|
2020-01-16 09:05:53 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 15:37:48 +00:00
|
|
|
mod stdin_evaluation {
|
2020-03-01 17:19:09 +00:00
|
|
|
use super::{nu, nu_error};
|
2020-02-10 15:37:48 +00:00
|
|
|
use nu_test_support::pipeline;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn does_not_panic_with_no_newline_in_stream() {
|
|
|
|
let stderr = nu_error!(
|
|
|
|
cwd: ".",
|
|
|
|
pipeline(r#"
|
|
|
|
nonu "where's the nuline?"
|
|
|
|
| count
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(stderr, "");
|
|
|
|
}
|
2020-03-01 17:19:09 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn does_not_block_indefinitely() {
|
|
|
|
let stdout = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
pipeline(r#"
|
|
|
|
iecho yes
|
|
|
|
| chop
|
|
|
|
| chop
|
2020-03-06 16:06:39 +00:00
|
|
|
| lines
|
2020-03-01 17:19:09 +00:00
|
|
|
| first 1
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(stdout, "y");
|
|
|
|
}
|
2020-02-10 15:37:48 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 19:14:49 +00:00
|
|
|
mod external_words {
|
|
|
|
use super::nu;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn relaxed_external_words() {
|
|
|
|
let actual = nu!(cwd: ".", r#"
|
|
|
|
cococo joturner@foo.bar.baz
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert_eq!(actual, "joturner@foo.bar.baz");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 06:55:07 +00:00
|
|
|
mod nu_commands {
|
|
|
|
use super::nu;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn echo_internally_externally() {
|
|
|
|
let actual = nu!(cwd: ".", r#"
|
|
|
|
nu -c "echo 'foo'"
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert_eq!(actual, "foo");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 16:49:45 +00:00
|
|
|
mod nu_script {
|
|
|
|
use super::nu;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_nu_script() {
|
|
|
|
let actual = nu!(cwd: "tests/fixtures/formats", r#"
|
|
|
|
nu script.nu
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert_eq!(actual, "done");
|
|
|
|
}
|
2020-02-14 05:24:18 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_nu_script_multiline() {
|
|
|
|
let actual = nu!(cwd: "tests/fixtures/formats", r#"
|
|
|
|
nu script_multiline.nu
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert_eq!(actual, "23");
|
|
|
|
}
|
2020-02-10 16:49:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 09:05:53 +00: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#"
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|