2020-05-07 13:03:43 +02:00
|
|
|
use nu_test_support::nu;
|
2020-01-16 10:05:53 +01:00
|
|
|
|
2022-03-29 13:10:43 +02:00
|
|
|
#[cfg(feature = "which-support")]
|
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"
|
|
|
|
);
|
|
|
|
|
2022-02-02 21:59:01 +01:00
|
|
|
assert!(!actual.err.is_empty());
|
2020-01-16 10:05:53 +01:00
|
|
|
}
|
|
|
|
|
2022-03-29 13:10:43 +02:00
|
|
|
#[cfg(feature = "which-support")]
|
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"
|
|
|
|
);
|
|
|
|
|
2022-02-02 21:59:01 +01:00
|
|
|
assert!(!actual.err.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ignore] // jt: we can't test this using the -c workaround currently
|
2022-03-29 13:10:43 +02:00
|
|
|
#[cfg(feature = "which-support")]
|
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
|
2021-05-12 03:01:48 +02:00
|
|
|
echo (pwd)
|
2020-03-17 19:13:38 +01:00
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert!(actual.out.ends_with("autodir"));
|
2020-03-17 19:13:38 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:59:01 +01:00
|
|
|
// FIXME: jt: we don't currently support autocd in testing
|
|
|
|
#[ignore]
|
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/
|
2020-10-26 07:55:52 +01:00
|
|
|
pwd
|
2020-04-27 03:22:01 +02:00
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
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() {
|
2022-04-11 20:18:46 +02:00
|
|
|
let actual = nu!(cwd: ".", r#"^nu --testbin cococo '$0'"#);
|
2020-04-30 06:54:07 +02:00
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "$0");
|
2020-04-30 06:54:07 +02:00
|
|
|
}
|
|
|
|
|
2021-06-14 02:20:07 +02:00
|
|
|
#[test]
|
|
|
|
fn execute_binary_in_string() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
r#"
|
2022-04-11 20:18:46 +02:00
|
|
|
let cmd = "nu"
|
|
|
|
^$"($cmd)" --testbin cococo "$0"
|
2021-06-14 02:20:07 +02:00
|
|
|
"#);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "$0");
|
|
|
|
}
|
|
|
|
|
2022-03-18 07:59:28 +01:00
|
|
|
#[test]
|
|
|
|
fn single_quote_dollar_external() {
|
|
|
|
let actual = nu!(cwd: ".", r#"let author = 'JT'; ^echo $'foo=($author)'"#);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "foo=JT");
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:59:01 +01:00
|
|
|
#[test]
|
|
|
|
fn redirects_custom_command_external() {
|
|
|
|
let actual = nu!(cwd: ".", r#"def foo [] { nu --testbin cococo foo bar }; foo | str length"#);
|
2021-04-21 22:54:34 +02:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "8");
|
|
|
|
}
|
|
|
|
|
2022-03-27 04:35:59 +02:00
|
|
|
#[test]
|
|
|
|
fn passes_binary_data_between_externals() {
|
|
|
|
let actual = nu!(cwd: "tests/fixtures/formats", r#"nu --testbin meowb sample.db | nu --testbin relay | hash sha256"#);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual.out,
|
|
|
|
"2f5050e7eea415c1f3d80b5d93355efd15043ec9157a2bb167a9e73f2ae651f2"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-08-07 20:40:41 +02:00
|
|
|
#[test]
|
|
|
|
fn command_not_found_error_suggests_search_term() {
|
|
|
|
// 'distinct' is not a command, but it is a search term for 'uniq'
|
|
|
|
let actual = nu!(cwd: ".", "ls | distinct");
|
|
|
|
assert!(actual.err.contains("uniq"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn command_not_found_error_suggests_typo_fix() {
|
|
|
|
let actual = nu!(cwd: ".", "benhcmark { echo 'foo'}");
|
|
|
|
assert!(actual.err.contains("benchmark"));
|
|
|
|
}
|
|
|
|
|
Make external command substitution works friendly(like fish shell, trailing ending newlines) (#7156)
# Description
As title, when execute external sub command, auto-trimming end
new-lines, like how fish shell does.
And if the command is executed directly like: `cat tmp`, the result
won't change.
Fixes: #6816
Fixes: #3980
Note that although nushell works correctly by directly replace output of
external command to variable(or other places like string interpolation),
it's not friendly to user, and users almost want to use `str trim` to
trim trailing newline, I think that's why fish shell do this
automatically.
If the pr is ok, as a result, no more `str trim -r` is required when
user is writing scripts which using external commands.
# User-Facing Changes
Before:
<img width="523" alt="img"
src="https://user-images.githubusercontent.com/22256154/202468810-86b04dbb-c147-459a-96a5-e0095eeaab3d.png">
After:
<img width="505" alt="img"
src="https://user-images.githubusercontent.com/22256154/202468599-7b537488-3d6b-458e-9d75-d85780826db0.png">
# Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace --features=extra -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect` to check that you're
using the standard code style
- `cargo test --workspace --features=extra` to check that all tests pass
# After Submitting
If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2022-11-23 04:51:57 +01:00
|
|
|
#[test]
|
|
|
|
fn command_substitution_wont_output_extra_newline() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
r#"
|
|
|
|
with-env [FOO "bar"] { echo $"prefix (nu --testbin echo_env FOO) suffix" }
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
assert_eq!(actual.out, "prefix bar suffix");
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
r#"
|
|
|
|
with-env [FOO "bar"] { (nu --testbin echo_env FOO) }
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
assert_eq!(actual.out, "bar");
|
|
|
|
}
|
|
|
|
|
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
|
2022-02-17 12:40:24 +01:00
|
|
|
| each { |it| nu --testbin cococo $it }
|
2022-02-02 21:59:01 +01:00
|
|
|
| get 1
|
2020-01-16 10:05:53 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
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
|
2022-02-17 12:40:24 +01:00
|
|
|
| each { |it| nu --testbin chop $it}
|
2022-02-02 21:59:01 +01:00
|
|
|
| get 1
|
2020-01-16 10:05:53 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
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]
|
2021-03-10 23:35:15 +01:00
|
|
|
fn can_properly_buffer_lines_externally() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
r#"
|
2021-03-13 22:46:40 +01:00
|
|
|
nu --testbin repeater c 8197 | lines | length
|
2021-03-10 23:35:15 +01:00
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1");
|
|
|
|
}
|
|
|
|
#[test]
|
2020-02-12 00:25:56 +01:00
|
|
|
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
|
2022-02-02 21:59:01 +01:00
|
|
|
| nu --testbin cococo $in.nu_party_venue
|
2020-02-12 00:25:56 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
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#"
|
2022-02-02 21:59:01 +01:00
|
|
|
nu --testbin nonu "wheres the nuline?" | length
|
2020-02-10 16:37:48 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
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#"
|
2022-02-02 21:59:01 +01:00
|
|
|
( nu --testbin iecho yes
|
|
|
|
| nu --testbin chop
|
|
|
|
| nu --testbin chop
|
|
|
|
| lines
|
2022-09-29 00:08:17 +02:00
|
|
|
| first )
|
2020-03-01 18:19:09 +01:00
|
|
|
"#
|
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;
|
2021-06-08 22:59:53 +02:00
|
|
|
use nu_test_support::fs::Stub::FileWithContent;
|
|
|
|
use nu_test_support::{pipeline, playground::Playground};
|
2020-01-24 20:14:49 +01:00
|
|
|
#[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
|
|
|
|
2022-02-02 21:59:01 +01:00
|
|
|
//FIXME: jt: limitation in testing - can't use single ticks currently
|
|
|
|
#[ignore]
|
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\"");
|
|
|
|
}
|
2021-06-08 22:59:53 +02:00
|
|
|
|
2021-06-28 12:16:03 +02:00
|
|
|
#[rstest::rstest]
|
|
|
|
#[case("sample.toml", r#""sample.toml""#)]
|
|
|
|
#[case("a sample file.toml", r#""a sample file.toml""#)]
|
2022-02-02 21:59:01 +01:00
|
|
|
//FIXME: jt: we don't currently support single ticks in tests
|
|
|
|
//#[case("quote'mark.toml", r#""quote'mark.toml""#)]
|
2021-06-28 12:16:03 +02:00
|
|
|
#[cfg_attr(
|
|
|
|
not(target_os = "windows"),
|
|
|
|
case(r#"quote"mark.toml"#, r#"$"quote(char double_quote)mark.toml""#)
|
|
|
|
)]
|
|
|
|
#[cfg_attr(not(target_os = "windows"), case("?mark.toml", r#""?mark.toml""#))]
|
|
|
|
#[cfg_attr(not(target_os = "windows"), case("*.toml", r#""*.toml""#))]
|
|
|
|
#[cfg_attr(not(target_os = "windows"), case("*.toml", "*.toml"))]
|
|
|
|
#[case("$ sign.toml", r#""$ sign.toml""#)]
|
|
|
|
fn external_arg_with_special_characters(#[case] path: &str, #[case] nu_path_argument: &str) {
|
2021-06-08 22:59:53 +02:00
|
|
|
Playground::setup("external_arg_with_quotes", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContent(
|
2021-06-28 12:16:03 +02:00
|
|
|
path,
|
2021-06-08 22:59:53 +02:00
|
|
|
r#"
|
|
|
|
nu_party_venue = "zion"
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2021-06-28 12:16:03 +02:00
|
|
|
&format!(r#"
|
|
|
|
nu --testbin meow {} | from toml | get nu_party_venue
|
|
|
|
"#, nu_path_argument)
|
2021-06-08 22:59:53 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "zion");
|
|
|
|
})
|
|
|
|
}
|
2020-01-24 20:14:49 +01:00
|
|
|
}
|
|
|
|
|
2020-02-10 07:55:07 +01:00
|
|
|
mod nu_commands {
|
2022-06-20 16:05:11 +02:00
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
|
2020-02-10 07:55:07 +01:00
|
|
|
use super::nu;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn echo_internally_externally() {
|
|
|
|
let actual = nu!(cwd: ".", r#"
|
|
|
|
nu -c "echo 'foo'"
|
|
|
|
"#);
|
|
|
|
|
2023-01-04 08:59:10 +01:00
|
|
|
assert_eq!(nu_utils::strip_ansi_string_likely(actual.out), "foo");
|
2020-02-10 07:55:07 +01:00
|
|
|
}
|
2022-04-21 05:31:52 +02:00
|
|
|
|
2022-06-20 16:05:11 +02:00
|
|
|
#[test]
|
|
|
|
fn failed_with_proper_exit_code() {
|
|
|
|
Playground::setup("external failed", |dirs, _sandbox| {
|
|
|
|
let actual = nu!(cwd: dirs.test(), r#"
|
2022-10-10 14:32:55 +02:00
|
|
|
nu -c "cargo build | complete | get exit_code"
|
2022-06-20 16:05:11 +02:00
|
|
|
"#);
|
|
|
|
|
|
|
|
// cargo for non rust project's exit code is 101.
|
2023-01-04 08:59:10 +01:00
|
|
|
assert_eq!(nu_utils::strip_ansi_string_likely(actual.out), "101")
|
2022-06-20 16:05:11 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-21 05:31:52 +02:00
|
|
|
#[test]
|
|
|
|
fn better_arg_quoting() {
|
|
|
|
let actual = nu!(cwd: ".", r#"
|
|
|
|
nu -c "\# '"
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "");
|
|
|
|
}
|
2022-06-06 12:19:06 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn command_list_arg_test() {
|
|
|
|
let actual = nu!(cwd: ".", r#"
|
|
|
|
nu ['-c' 'version']
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert!(actual.out.contains("version"));
|
|
|
|
assert!(actual.out.contains("rust_version"));
|
|
|
|
assert!(actual.out.contains("rust_channel"));
|
|
|
|
assert!(actual.out.contains("pkg_version"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn command_cell_path_arg_test() {
|
|
|
|
let actual = nu!(cwd: ".", r#"
|
|
|
|
nu ([ '-c' 'version' ])
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert!(actual.out.contains("version"));
|
|
|
|
assert!(actual.out.contains("rust_version"));
|
|
|
|
assert!(actual.out.contains("rust_channel"));
|
|
|
|
assert!(actual.out.contains("pkg_version"));
|
|
|
|
}
|
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
|
|
|
|
"#);
|
|
|
|
|
2023-01-04 08:59:10 +01:00
|
|
|
assert_eq!(nu_utils::strip_ansi_string_likely(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
|
|
|
|
"#);
|
|
|
|
|
2023-01-04 08:59:10 +01:00
|
|
|
assert_eq!(nu_utils::strip_ansi_string_likely(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
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2021-03-26 09:26:57 +01:00
|
|
|
assert!(!actual.out.contains('~'));
|
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#"
|
2021-05-12 03:01:48 +02:00
|
|
|
nu --testbin cococo (ls | get name)
|
2020-07-22 23:41:34 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual.out,
|
|
|
|
"andres_likes_arepas.txt ferris_not_here.txt jonathan_likes_cake.txt"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2021-06-17 21:59:58 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn proper_subexpression_paths_in_external_args() {
|
|
|
|
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 | sort-by name | get name).1
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "ferris_not_here.txt");
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2021-06-25 22:14:54 +02:00
|
|
|
|
2021-07-06 20:14:48 +02:00
|
|
|
#[cfg(not(windows))]
|
2021-06-25 22:14:54 +02:00
|
|
|
#[test]
|
|
|
|
fn string_interpolation_with_an_external_command() {
|
|
|
|
Playground::setup(
|
|
|
|
"string_interpolation_with_an_external_command",
|
|
|
|
|dirs, sandbox| {
|
|
|
|
sandbox.mkdir("cd");
|
|
|
|
|
2022-02-02 21:59:01 +01:00
|
|
|
sandbox.with_files(vec![EmptyFile("cd/jt_likes_cake.txt")]);
|
2021-06-25 22:14:54 +02:00
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
2022-02-02 21:59:01 +01:00
|
|
|
nu --testbin cococo $"(pwd)/cd"
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.out.contains("cd"));
|
2021-06-25 22:14:54 +02:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2021-11-29 16:46:42 +01:00
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
#[test]
|
|
|
|
fn semicolons_are_sanitized_before_passing_to_subshell() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
"^echo \"a;b\""
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "a;b");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
#[test]
|
|
|
|
fn ampersands_are_sanitized_before_passing_to_subshell() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
"^echo \"a&b\""
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "a&b");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
#[test]
|
|
|
|
fn subcommands_are_sanitized_before_passing_to_subshell() {
|
|
|
|
let actual = nu!(
|
2022-02-02 21:59:01 +01:00
|
|
|
cwd: ".",
|
|
|
|
"nu --testbin cococo \"$(ls)\""
|
2021-11-29 16:46:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "$(ls)");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
#[test]
|
|
|
|
fn shell_arguments_are_sanitized_even_if_coming_from_other_commands() {
|
|
|
|
let actual = nu!(
|
2022-02-02 21:59:01 +01:00
|
|
|
cwd: ".",
|
|
|
|
"nu --testbin cococo (echo \"a;&$(hello)\")"
|
2021-11-29 16:46:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "a;&$(hello)");
|
|
|
|
}
|
2020-07-22 23:41:34 +02:00
|
|
|
}
|