Remove unnecessary cwd, pipeline(), r# from various tests (#9645)

<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.

Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->
This PR cleans up tests in the `tests/` directory by removing
unnecessary code.
Part of #8670.

- [x]  const_/mod.rs
- [x]  eval/mod.rs
- [x]  hooks/mod.rs
- [x]  modules/mod.rs
- [x]  overlays/mod.rs
- [x]  parsing/mod.rs
- [x]  scope/mod.rs
- [x]  shell/environment/env.rs
- [x]  shell/environment/nu_env.rs
- [x]  shell/mod.rs
- [x]  shell/pipeline/commands/external.rs
- [x]  shell/pipeline/commands/internal.rs
- [x]  shell/pipeline/mod.rs

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# 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 -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# 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.
-->
This commit is contained in:
Han Junghyuk 2023-07-13 02:07:20 +09:00 committed by GitHub
parent ca794f6adb
commit 556852ded4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 1085 additions and 1419 deletions

View File

@ -1,65 +1,65 @@
use nu_test_support::{nu, pipeline};
use nu_test_support::nu;
use pretty_assertions::assert_eq;
#[test]
fn const_bool() {
let inp = &[r#"const x = false"#, r#"$x"#];
let inp = &["const x = false", "$x"];
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "false");
}
#[test]
fn const_int() {
let inp = &[r#"const x = 10"#, r#"$x"#];
let inp = &["const x = 10", "$x"];
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "10");
}
#[test]
fn const_float() {
let inp = &[r#"const x = 1.234"#, r#"$x"#];
let inp = &["const x = 1.234", "$x"];
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "1.234");
}
#[test]
fn const_binary() {
let inp = &[r#"const x = 0x[12]"#, r#"$x"#];
let inp = &["const x = 0x[12]", "$x"];
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.out.contains("12"));
}
#[test]
fn const_datetime() {
let inp = &[r#"const x = 2021-02-27T13:55:40+00:00"#, r#"$x"#];
let inp = &["const x = 2021-02-27T13:55:40+00:00", "$x"];
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.out.contains("Sat, 27 Feb 2021 13:55:40"));
}
#[test]
fn const_list() {
let inp = &[r#"const x = [ a b c ]"#, r#"$x | describe"#];
let inp = &["const x = [ a b c ]", "$x | describe"];
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "list<string>");
}
#[test]
fn const_record() {
let inp = &[r#"const x = { a: 10, b: 20, c: 30 }"#, r#"$x | describe"#];
let inp = &["const x = { a: 10, b: 20, c: 30 }", "$x | describe"];
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "record<a: int, b: int, c: int>");
}
@ -67,38 +67,38 @@ fn const_record() {
#[test]
fn const_table() {
let inp = &[
r#"const x = [[a b c]; [10 20 30] [100 200 300]]"#,
r#"$x | describe"#,
"const x = [[a b c]; [10 20 30] [100 200 300]]",
"$x | describe",
];
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "table<a: int, b: int, c: int>");
}
#[test]
fn const_string() {
let inp = &[r#"const x = "abc""#, r#"$x"#];
let inp = &[r#"const x = "abc""#, "$x"];
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "abc");
}
#[test]
fn const_nothing() {
let inp = &[r#"const x = $nothing"#, r#"$x | describe"#];
let inp = &["const x = $nothing", "$x | describe"];
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "nothing");
}
#[test]
fn const_unsupported() {
let inp = &[r#"const x = ('abc' | str length)"#];
let inp = &["const x = ('abc' | str length)"];
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("not_a_constant"));
}

View File

@ -2,9 +2,7 @@ use nu_test_support::nu;
#[test]
fn source_file_relative_to_file() {
let actual = nu!(cwd: "tests/eval", r#"
{x: 1, x: 2}
"#);
let actual = nu!("{x: 1, x: 2}");
assert!(actual.err.contains("redefined"));
}

View File

@ -11,7 +11,7 @@ fn env_change_hook_code_list(name: &str, code_list: &[&str]) -> String {
}
format!(
r#"$env.config = {{
"$env.config = {{
hooks: {{
env_change: {{
{name} : [
@ -19,25 +19,25 @@ fn env_change_hook_code_list(name: &str, code_list: &[&str]) -> String {
]
}}
}}
}}"#
}}"
)
}
fn env_change_hook(name: &str, code: &str) -> String {
format!(
r#"$env.config = {{
"$env.config = {{
hooks: {{
env_change: {{
{name} : {code}
}}
}}
}}"#
}}"
)
}
fn env_change_hook_code(name: &str, code: &str) -> String {
format!(
r#"$env.config = {{
"$env.config = {{
hooks: {{
env_change: {{
{name} : {{
@ -45,13 +45,13 @@ fn env_change_hook_code(name: &str, code: &str) -> String {
}}
}}
}}
}}"#
}}"
)
}
fn env_change_hook_code_condition(name: &str, condition: &str, code: &str) -> String {
format!(
r#"$env.config = {{
"$env.config = {{
hooks: {{
env_change: {{
{name} : {{
@ -60,51 +60,51 @@ fn env_change_hook_code_condition(name: &str, condition: &str, code: &str) -> St
}}
}}
}}
}}"#
}}"
)
}
fn pre_prompt_hook(code: &str) -> String {
format!(
r#"$env.config = {{
"$env.config = {{
hooks: {{
pre_prompt: {code}
}}
}}"#
}}"
)
}
fn pre_prompt_hook_code(code: &str) -> String {
format!(
r#"$env.config = {{
"$env.config = {{
hooks: {{
pre_prompt: {{
code: {code}
}}
}}
}}"#
}}"
)
}
fn pre_execution_hook(code: &str) -> String {
format!(
r#"$env.config = {{
"$env.config = {{
hooks: {{
pre_execution: {code}
}}
}}"#
}}"
)
}
fn pre_execution_hook_code(code: &str) -> String {
format!(
r#"$env.config = {{
"$env.config = {{
hooks: {{
pre_execution: {{
code: {code}
}}
}}
}}"#
}}"
)
}
@ -116,7 +116,7 @@ fn env_change_define_command() {
"foo",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "got foo!");
@ -130,7 +130,7 @@ fn env_change_define_variable() {
"$x",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -144,7 +144,7 @@ fn env_change_define_env_var() {
"$env.SPAM",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -158,7 +158,7 @@ fn env_change_define_alias() {
"spam",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -172,7 +172,7 @@ fn env_change_simple_block_preserve_env_var() {
"$env.SPAM",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -192,7 +192,7 @@ fn env_change_simple_block_list_shadow_env_var() {
"$env.SPAM",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -206,7 +206,7 @@ fn env_change_block_preserve_env_var() {
"$env.SPAM",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -219,7 +219,7 @@ fn pre_prompt_define_command() {
"foo",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "got foo!");
@ -229,7 +229,7 @@ fn pre_prompt_define_command() {
fn pre_prompt_simple_block_preserve_env_var() {
let inp = &[&pre_prompt_hook(r#"{|| $env.SPAM = "spam" }"#), "$env.SPAM"];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -247,7 +247,7 @@ fn pre_prompt_simple_block_list_shadow_env_var() {
"$env.SPAM",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -260,7 +260,7 @@ fn pre_prompt_block_preserve_env_var() {
"$env.SPAM",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -273,7 +273,7 @@ fn pre_execution_define_command() {
"foo",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "got foo!");
@ -286,7 +286,7 @@ fn pre_execution_simple_block_preserve_env_var() {
"$env.SPAM",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -304,7 +304,7 @@ fn pre_execution_simple_block_list_shadow_env_var() {
"$env.SPAM",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -317,7 +317,7 @@ fn pre_execution_block_preserve_env_var() {
"$env.SPAM",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "spam");
@ -326,11 +326,11 @@ fn pre_execution_block_preserve_env_var() {
#[test]
fn pre_execution_commandline() {
let inp = &[
&pre_execution_hook_code(r#"{|| $env.repl_commandline = (commandline) }"#),
&pre_execution_hook_code("{|| $env.repl_commandline = (commandline) }"),
"$env.repl_commandline",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "$env.repl_commandline");
@ -350,7 +350,7 @@ fn env_change_shadow_command() {
"foo",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "got foo!");
@ -364,7 +364,7 @@ fn env_change_block_dont_preserve_command() {
"foo",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
#[cfg(windows)]
assert_ne!(actual_repl.out, "foo");
@ -377,8 +377,8 @@ fn env_change_block_condition_pwd() {
let inp = &[
&env_change_hook_code_condition(
"PWD",
r#"{|before, after| ($after | path basename) == samples }"#,
r#"'source-env .nu-env'"#,
"{|before, after| ($after | path basename) == samples }",
"'source-env .nu-env'",
),
"cd samples",
"$env.SPAM",
@ -393,18 +393,18 @@ fn env_change_block_condition_pwd() {
#[test]
fn env_change_block_condition_correct_args() {
let inp = &[
r#"$env.FOO = 1"#,
"$env.FOO = 1",
&env_change_hook_code_condition(
"FOO",
r#"{|before, after| $before == 1 and $after == 2}"#,
r#"{|before, after| $env.SPAM = ($before == 1 and $after == 2) }"#,
"{|before, after| $before == 1 and $after == 2}",
"{|before, after| $env.SPAM = ($before == 1 and $after == 2) }",
),
"",
r#"$env.FOO = 2"#,
"$env.FOO = 2",
"$env.SPAM",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual_repl.err, "");
assert_eq!(actual_repl.out, "true");
@ -413,12 +413,12 @@ fn env_change_block_condition_correct_args() {
#[test]
fn env_change_dont_panic_with_many_args() {
let inp = &[
&env_change_hook_code("FOO", r#"{ |a, b, c| $env.SPAM = 'spam' }"#),
&env_change_hook_code("FOO", "{ |a, b, c| $env.SPAM = 'spam' }"),
"$env.FOO = 1",
"",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert!(actual_repl.err.contains("incompatible_parameters"));
assert_eq!(actual_repl.out, "");
@ -427,18 +427,18 @@ fn env_change_dont_panic_with_many_args() {
#[test]
fn err_hook_wrong_env_type_1() {
let inp = &[
r#"$env.config = {
"$env.config = {
hooks: {
env_change: {
FOO : 1
}
}
}"#,
}",
"$env.FOO = 1",
"",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
dbg!(&actual_repl.err);
assert!(actual_repl.err.contains("unsupported_config_value"));
@ -456,7 +456,7 @@ fn err_hook_wrong_env_type_2() {
"",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert!(actual_repl.err.contains("type_mismatch"));
assert_eq!(actual_repl.out, "");
@ -465,7 +465,7 @@ fn err_hook_wrong_env_type_2() {
#[test]
fn err_hook_wrong_env_type_3() {
let inp = &[
r#"$env.config = {
"$env.config = {
hooks: {
env_change: {
FOO : {
@ -473,12 +473,12 @@ fn err_hook_wrong_env_type_3() {
}
}
}
}"#,
}",
"$env.FOO = 1",
"",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert!(actual_repl.err.contains("unsupported_config_value"));
assert_eq!(actual_repl.out, "");
@ -501,7 +501,7 @@ fn err_hook_non_boolean_condition_output() {
"",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert!(actual_repl.err.contains("unsupported_config_value"));
assert_eq!(actual_repl.out, "");
@ -524,7 +524,7 @@ fn err_hook_non_condition_not_a_block() {
"",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert!(actual_repl.err.contains("unsupported_config_value"));
assert_eq!(actual_repl.out, "");
@ -546,7 +546,7 @@ fn err_hook_parse_error() {
"",
];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert!(actual_repl.err.contains("unsupported_config_value"));
assert_eq!(actual_repl.out, "");
@ -556,7 +556,7 @@ fn err_hook_parse_error() {
fn err_hook_dont_allow_string() {
let inp = &[&pre_prompt_hook(r#"'def foo [] { "got foo!" }'"#), "foo"];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp));
let actual_repl = nu!(nu_repl_code(inp));
assert!(actual_repl.out.is_empty());
assert!(actual_repl.err.contains("unsupported_config_value"));

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground;
use nu_test_support::{nu, nu_repl_code, pipeline};
use nu_test_support::{nu, nu_repl_code};
use pretty_assertions::assert_eq;
#[test]
@ -9,11 +9,11 @@ fn module_private_import_decl() {
sandbox
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
use spam.nu foo-helper
export def foo [] { foo-helper }
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
@ -23,9 +23,9 @@ fn module_private_import_decl() {
"#,
)]);
let inp = &[r#"use main.nu foo"#, r#"foo"#];
let inp = &["use main.nu foo", "foo"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "foo");
})
@ -37,11 +37,11 @@ fn module_private_import_alias() {
sandbox
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
use spam.nu foo-helper
export def foo [] { foo-helper }
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
@ -50,9 +50,9 @@ fn module_private_import_alias() {
"#,
)]);
let inp = &[r#"use main.nu foo"#, r#"foo"#];
let inp = &["use main.nu foo", "foo"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "foo");
})
@ -64,9 +64,9 @@ fn module_private_import_decl_not_public() {
sandbox
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
use spam.nu foo-helper
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
@ -76,9 +76,9 @@ fn module_private_import_decl_not_public() {
"#,
)]);
let inp = &[r#"use main.nu foo"#, r#"foo-helper"#];
let inp = &["use main.nu foo", "foo-helper"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert!(!actual.err.is_empty());
})
@ -90,9 +90,9 @@ fn module_public_import_decl() {
sandbox
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
export use spam.nu foo
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
@ -102,9 +102,9 @@ fn module_public_import_decl() {
"#,
)]);
let inp = &[r#"use main.nu foo"#, r#"foo"#];
let inp = &["use main.nu foo", "foo"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "foo");
})
@ -116,9 +116,9 @@ fn module_public_import_alias() {
sandbox
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
export use spam.nu foo
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
@ -127,9 +127,9 @@ fn module_public_import_alias() {
"#,
)]);
let inp = &[r#"use main.nu foo"#, r#"foo"#];
let inp = &["use main.nu foo", "foo"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "foo");
})
@ -141,21 +141,21 @@ fn module_nested_imports() {
sandbox
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
export use spam.nu [ foo bar ]
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
r#"
"
export use spam2.nu [ foo bar ]
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam2.nu",
r#"
"
export use spam3.nu [ foo bar ]
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam3.nu",
@ -165,13 +165,13 @@ fn module_nested_imports() {
"#,
)]);
let inp1 = &[r#"use main.nu foo"#, r#"foo"#];
let inp2 = &[r#"use main.nu bar"#, r#"bar"#];
let inp1 = &["use main.nu foo", "foo"];
let inp2 = &["use main.nu bar", "bar"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp1.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp1.join("; "));
assert_eq!(actual.out, "foo");
let actual = nu!(cwd: dirs.test(), pipeline(&inp2.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp2.join("; "));
assert_eq!(actual.out, "bar");
})
}
@ -185,21 +185,21 @@ fn module_nested_imports_in_dirs() {
.mkdir("spam/spam3")
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
export use spam/spam.nu [ foo bar ]
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam/spam.nu",
r#"
"
export use spam2/spam2.nu [ foo bar ]
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam/spam2/spam2.nu",
r#"
"
export use ../spam3/spam3.nu [ foo bar ]
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam/spam3/spam3.nu",
@ -209,13 +209,13 @@ fn module_nested_imports_in_dirs() {
"#,
)]);
let inp1 = &[r#"use main.nu foo"#, r#"foo"#];
let inp2 = &[r#"use main.nu bar"#, r#"bar"#];
let inp1 = &["use main.nu foo", "foo"];
let inp2 = &["use main.nu bar", "bar"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp1.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp1.join("; "));
assert_eq!(actual.out, "foo");
let actual = nu!(cwd: dirs.test(), pipeline(&inp2.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp2.join("; "));
assert_eq!(actual.out, "bar");
})
}
@ -226,9 +226,9 @@ fn module_public_import_decl_prefixed() {
sandbox
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
export use spam.nu
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
@ -238,9 +238,9 @@ fn module_public_import_decl_prefixed() {
"#,
)]);
let inp = &[r#"use main.nu"#, r#"main spam foo"#];
let inp = &["use main.nu", "main spam foo"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "foo");
})
@ -261,16 +261,16 @@ fn module_nested_imports_in_dirs_prefixed() {
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam/spam.nu",
r#"
"
export use spam2/spam2.nu
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam/spam2/spam2.nu",
r#"
"
export use ../spam3/spam3.nu
export use ../spam3/spam3.nu foo
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam/spam3/spam3.nu",
@ -280,13 +280,13 @@ fn module_nested_imports_in_dirs_prefixed() {
"#,
)]);
let inp1 = &[r#"use main.nu"#, r#"main spam2 foo"#];
let inp2 = &[r#"use main.nu "spam2 spam3 bar""#, r#"spam2 spam3 bar"#];
let inp1 = &["use main.nu", "main spam2 foo"];
let inp2 = &[r#"use main.nu "spam2 spam3 bar""#, "spam2 spam3 bar"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp1.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp1.join("; "));
assert_eq!(actual.out, "foo");
let actual = nu!(cwd: dirs.test(), pipeline(&inp2.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp2.join("; "));
assert_eq!(actual.out, "bar");
})
}
@ -297,11 +297,11 @@ fn module_import_env_1() {
sandbox
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
export-env { source-env spam.nu }
export def foo [] { $env.FOO_HELPER }
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
@ -310,9 +310,9 @@ fn module_import_env_1() {
"#,
)]);
let inp = &[r#"source-env main.nu"#, r#"use main.nu foo"#, r#"foo"#];
let inp = &["source-env main.nu", "use main.nu foo", "foo"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "foo");
})
@ -324,9 +324,9 @@ fn module_import_env_2() {
sandbox
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
export-env { source-env spam.nu }
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
@ -335,9 +335,9 @@ fn module_import_env_2() {
"#,
)]);
let inp = &[r#"source-env main.nu"#, r#"$env.FOO"#];
let inp = &["source-env main.nu", "$env.FOO"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "foo");
})
@ -348,14 +348,14 @@ fn module_cyclical_imports_0() {
Playground::setup("module_cyclical_imports_0", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
r#"
"
use eggs.nu
"#,
",
)]);
let inp = &[r#"module eggs { use spam.nu }"#];
let inp = &["module eggs { use spam.nu }"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert!(actual.err.contains("module not found"));
})
@ -366,14 +366,14 @@ fn module_cyclical_imports_1() {
Playground::setup("module_cyclical_imports_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
r#"
"
use spam.nu
"#,
",
)]);
let inp = &[r#"use spam.nu"#];
let inp = &["use spam.nu"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert!(actual.err.contains("cyclical"));
})
@ -385,20 +385,20 @@ fn module_cyclical_imports_2() {
sandbox
.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
r#"
"
use eggs.nu
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"eggs.nu",
r#"
"
use spam.nu
"#,
",
)]);
let inp = &[r#"use spam.nu"#];
let inp = &["use spam.nu"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert!(actual.err.contains("cyclical"));
})
@ -410,26 +410,26 @@ fn module_cyclical_imports_3() {
sandbox
.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
r#"
"
use eggs.nu
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"eggs.nu",
r#"
"
use bacon.nu
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"bacon.nu",
r#"
"
use spam.nu
"#,
",
)]);
let inp = &[r#"use spam.nu"#];
let inp = &["use spam.nu"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert!(actual.err.contains("cyclical"));
})
@ -445,9 +445,9 @@ fn module_import_const_file() {
"#,
)]);
let inp = &[r#"const file = 'spam.nu'"#, r#"use $file foo"#, r#"foo"#];
let inp = &["const file = 'spam.nu'", "use $file foo", "foo"];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "foo");
})
@ -465,12 +465,12 @@ fn module_import_const_module_name() {
let inp = &[
r#"module spam { export def foo [] { "foo" } }"#,
r#"const mod = 'spam'"#,
r#"use $mod foo"#,
r#"foo"#,
"const mod = 'spam'",
"use $mod foo",
"foo",
];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "foo");
})
@ -480,7 +480,7 @@ fn module_import_const_module_name() {
fn module_valid_def_name() {
let inp = &[r#"module spam { def spam [] { "spam" } }"#];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "");
}
@ -489,7 +489,7 @@ fn module_valid_def_name() {
fn module_invalid_def_name() {
let inp = &[r#"module spam { export def spam [] { "spam" } }"#];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("named_as_module"));
}
@ -498,7 +498,7 @@ fn module_invalid_def_name() {
fn module_valid_alias_name_1() {
let inp = &[r#"module spam { alias spam = echo "spam" }"#];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "");
}
@ -507,7 +507,7 @@ fn module_valid_alias_name_1() {
fn module_valid_alias_name_2() {
let inp = &[r#"module spam { alias main = echo "spam" }"#];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "");
}
@ -516,34 +516,34 @@ fn module_valid_alias_name_2() {
fn module_invalid_alias_name() {
let inp = &[r#"module spam { export alias spam = echo "spam" }"#];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("named_as_module"));
}
#[test]
fn module_main_alias_not_allowed() {
let inp = &[r#"module spam { export alias main = echo 'spam' }"#];
let inp = &["module spam { export alias main = echo 'spam' }"];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("export_main_alias_not_allowed"));
}
#[test]
fn module_valid_known_external_name() {
let inp = &[r#"module spam { extern spam [] }"#];
let inp = &["module spam { extern spam [] }"];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "");
}
#[test]
fn module_invalid_known_external_name() {
let inp = &[r#"module spam { export extern spam [] }"#];
let inp = &["module spam { export extern spam [] }"];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("named_as_module"));
}
@ -551,40 +551,40 @@ fn module_invalid_known_external_name() {
#[test]
fn main_inside_module_is_main() {
let inp = &[
r#"module spam {
"module spam {
export def main [] { 'foo' };
export def foo [] { main }
}"#,
}",
"use spam foo",
"foo",
];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "foo");
}
#[test]
fn module_as_file() {
let inp = &[r#"module samples/spam.nu"#, "use spam foo", "foo"];
let inp = &["module samples/spam.nu", "use spam foo", "foo"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual.out, "foo");
}
#[test]
fn export_module_as_file() {
let inp = &[r#"export module samples/spam.nu"#, "use spam foo", "foo"];
let inp = &["export module samples/spam.nu", "use spam foo", "foo"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual.out, "foo");
}
#[test]
fn deep_import_patterns() {
let module_decl = r#"
let module_decl = "
module spam {
export module eggs {
export module beans {
@ -593,22 +593,22 @@ fn deep_import_patterns() {
};
};
}
"#;
";
let inp = &[module_decl, "use spam", "spam eggs beans foo"];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "foo");
let inp = &[module_decl, "use spam eggs", "eggs beans foo"];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "foo");
let inp = &[module_decl, "use spam eggs beans", "beans foo"];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "foo");
let inp = &[module_decl, "use spam eggs beans foo", "foo"];
let actual = nu!(cwd: ".", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "foo");
}
@ -617,27 +617,27 @@ fn module_dir() {
let import = "use samples/spam";
let inp = &[import, "spam"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual.out, "spam");
let inp = &[import, "spam foo"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual.out, "foo");
let inp = &[import, "spam bar"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual.out, "bar");
let inp = &[import, "spam foo baz"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual.out, "foobaz");
let inp = &[import, "spam bar baz"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual.out, "barbaz");
let inp = &[import, "spam baz"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual.out, "spambaz");
}
@ -646,19 +646,19 @@ fn module_dir_deep() {
let import = "use samples/spam";
let inp = &[import, "spam bacon"];
let actual_repl = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual_repl = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual_repl.out, "bacon");
let inp = &[import, "spam bacon foo"];
let actual_repl = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual_repl = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual_repl.out, "bacon foo");
let inp = &[import, "spam bacon beans"];
let actual_repl = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual_repl = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual_repl.out, "beans");
let inp = &[import, "spam bacon beans foo"];
let actual_repl = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual_repl = nu!(cwd: "tests/modules", &inp.join("; "));
assert_eq!(actual_repl.out, "beans foo");
}
@ -673,28 +673,28 @@ fn module_dir_import_twice_no_panic() {
#[test]
fn not_allowed_submodule_file() {
let inp = &["use samples/not_allowed"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(cwd: "tests/modules", &inp.join("; "));
assert!(actual.err.contains("invalid_module_file_name"));
}
#[test]
fn module_dir_missing_mod_nu() {
let inp = &["use samples/missing_mod_nu"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(cwd: "tests/modules", &inp.join("; "));
assert!(actual.err.contains("module_missing_mod_nu_file"));
}
#[test]
fn allowed_local_module() {
let inp = &["module spam { module spam {} }"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.err.is_empty());
}
#[test]
fn not_allowed_submodule() {
let inp = &["module spam { export module spam {} }"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("named_as_module"));
}
@ -705,48 +705,48 @@ fn module_self_name() {
"use spam",
"spam",
];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "spam");
}
#[test]
fn module_self_name_main_not_allowed() {
let inp = &[
r#"module spam {
"module spam {
export def main [] { 'main spam' };
export module mod {
export def main [] { 'mod spam' }
}
}"#,
}",
"use spam",
"spam",
];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("module_double_main"));
let inp = &[
r#"module spam {
"module spam {
export module mod {
export def main [] { 'mod spam' }
};
export def main [] { 'main spam' }
}"#,
}",
"use spam",
"spam",
];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("module_double_main"));
}
#[test]
fn module_main_not_found() {
let inp = &["module spam {}", "use spam main"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("export_not_found"));
let inp = &["module spam {}", "use spam [ main ]"];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; ")));
let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("export_not_found"));
}

File diff suppressed because it is too large Load Diff

View File

@ -5,9 +5,9 @@ use pretty_assertions::assert_eq;
#[test]
fn source_file_relative_to_file() {
let actual = nu!(cwd: "tests/parsing/samples", r#"
let actual = nu!(cwd: "tests/parsing/samples", "
nu source_file_relative.nu
"#);
");
assert_eq!(actual.out, "5");
}
@ -15,55 +15,55 @@ fn source_file_relative_to_file() {
#[test]
fn source_const_file() {
let actual = nu!(cwd: "tests/parsing/samples",
r#"
"
const file = 'single_line.nu'
source $file
"#);
");
assert_eq!(actual.out, "5");
}
#[test]
fn run_nu_script_single_line() {
let actual = nu!(cwd: "tests/parsing/samples", r#"
let actual = nu!(cwd: "tests/parsing/samples", "
nu single_line.nu
"#);
");
assert_eq!(actual.out, "5");
}
#[test]
fn run_nu_script_multiline_start_pipe() {
let actual = nu!(cwd: "tests/parsing/samples", r#"
let actual = nu!(cwd: "tests/parsing/samples", "
nu multiline_start_pipe.nu
"#);
");
assert_eq!(actual.out, "4");
}
#[test]
fn run_nu_script_multiline_start_pipe_win() {
let actual = nu!(cwd: "tests/parsing/samples", r#"
let actual = nu!(cwd: "tests/parsing/samples", "
nu multiline_start_pipe_win.nu
"#);
");
assert_eq!(actual.out, "3");
}
#[test]
fn run_nu_script_multiline_end_pipe() {
let actual = nu!(cwd: "tests/parsing/samples", r#"
let actual = nu!(cwd: "tests/parsing/samples", "
nu multiline_end_pipe.nu
"#);
");
assert_eq!(actual.out, "2");
}
#[test]
fn run_nu_script_multiline_end_pipe_win() {
let actual = nu!(cwd: "tests/parsing/samples", r#"
let actual = nu!(cwd: "tests/parsing/samples", "
nu multiline_end_pipe_win.nu
"#);
");
assert_eq!(actual.out, "3");
}
@ -76,11 +76,11 @@ fn parse_file_relative_to_parsed_file_simple() {
.mkdir("lol/lol")
.with_files(vec![FileWithContentToBeTrimmed(
"lol/lol/lol.nu",
r#"
"
use ../lol_shell.nu
$env.LOL = (lol_shell ls)
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"lol/lol_shell.nu",
@ -91,10 +91,10 @@ fn parse_file_relative_to_parsed_file_simple() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
source-env lol/lol/lol.nu;
$env.LOL
"#
"
));
assert_eq!(actual.out, "lol");
@ -110,13 +110,13 @@ fn parse_file_relative_to_parsed_file() {
.mkdir("lol/lol")
.with_files(vec![FileWithContentToBeTrimmed(
"lol/lol/lol.nu",
r#"
"
source-env ../../foo.nu
use ../lol_shell.nu
overlay use ../../lol/lol_shell.nu
$env.LOL = $'($env.FOO) (lol_shell ls) (ls)'
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"lol/lol_shell.nu",
@ -126,17 +126,17 @@ fn parse_file_relative_to_parsed_file() {
)])
.with_files(vec![FileWithContentToBeTrimmed(
"foo.nu",
r#"
"
$env.FOO = 'foo'
"#,
",
)]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
source-env lol/lol/lol.nu;
$env.LOL
"#
"
));
assert_eq!(actual.out, "foo lol lol");
@ -150,29 +150,29 @@ fn parse_file_relative_to_parsed_file_dont_use_cwd_1() {
.mkdir("lol")
.with_files(vec![FileWithContentToBeTrimmed(
"lol/lol.nu",
r#"
"
source-env foo.nu
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"lol/foo.nu",
r#"
"
$env.FOO = 'good'
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"foo.nu",
r#"
"
$env.FOO = 'bad'
"#,
",
)]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
source-env lol/lol.nu;
$env.FOO
"#
"
));
assert_eq!(actual.out, "good");
@ -186,22 +186,22 @@ fn parse_file_relative_to_parsed_file_dont_use_cwd_2() {
.mkdir("lol")
.with_files(vec![FileWithContentToBeTrimmed(
"lol/lol.nu",
r#"
"
source-env foo.nu
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"foo.nu",
r#"
"
$env.FOO = 'bad'
"#,
",
)]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
source-env lol/lol.nu
"#
"
));
assert!(actual.err.contains("File not found"));
@ -210,39 +210,35 @@ fn parse_file_relative_to_parsed_file_dont_use_cwd_2() {
#[test]
fn parse_export_env_in_module() {
let actual = nu!(cwd: "tests/parsing/samples",
r#"
let actual = nu!("
module spam { export-env { } }
"#);
");
assert!(actual.err.is_empty());
}
#[test]
fn parse_export_env_missing_block() {
let actual = nu!(cwd: "tests/parsing/samples",
r#"
let actual = nu!("
module spam { export-env }
"#);
");
assert!(actual.err.contains("missing block"));
}
#[test]
fn call_command_with_non_ascii_argument() {
let actual = nu!(cwd: "tests/parsing/samples",
r#"
let actual = nu!("
def nu-arg [--umlaut(-ö): int] {}
nu-arg -ö 42
"#);
");
assert_eq!(actual.err.len(), 0);
}
#[test]
fn parse_long_duration() {
let actual = nu!(cwd: "tests/parsing/samples",
r#"
let actual = nu!(r#"
"78.797877879789789sec" | into duration
"#);

View File

@ -4,12 +4,9 @@ use pretty_assertions::assert_eq;
#[ignore = "TODO: This shows old-style aliases. New aliases are under commands"]
#[test]
fn scope_shows_alias() {
let actual = nu!(
cwd: ".",
r#"alias xaz = echo alias1
let actual = nu!("alias xaz = echo alias1
scope aliases | find xaz | length
"#
);
");
let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 1);
@ -17,12 +14,9 @@ fn scope_shows_alias() {
#[test]
fn scope_shows_command() {
let actual = nu!(
cwd: ".",
r#"def xaz [] { echo xaz }
let actual = nu!("def xaz [] { echo xaz }
scope commands | find xaz | length
"#
);
");
let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 1);
@ -30,15 +24,12 @@ fn scope_shows_command() {
#[test]
fn scope_doesnt_show_scoped_hidden_alias() {
let actual = nu!(
cwd: ".",
r#"alias xaz = echo alias1
let actual = nu!("alias xaz = echo alias1
do {
hide xaz
scope aliases | find xaz | length
}
"#
);
");
let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 0);
@ -46,13 +37,10 @@ fn scope_doesnt_show_scoped_hidden_alias() {
#[test]
fn scope_doesnt_show_hidden_alias() {
let actual = nu!(
cwd: ".",
r#"alias xaz = echo alias1
let actual = nu!("alias xaz = echo alias1
hide xaz
scope aliases | find xaz | length
"#
);
");
let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 0);
@ -60,15 +48,12 @@ fn scope_doesnt_show_hidden_alias() {
#[test]
fn scope_doesnt_show_scoped_hidden_command() {
let actual = nu!(
cwd: ".",
r#"def xaz [] { echo xaz }
let actual = nu!("def xaz [] { echo xaz }
do {
hide xaz
scope commands | find xaz | length
}
"#
);
");
let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 0);
@ -76,13 +61,10 @@ fn scope_doesnt_show_scoped_hidden_command() {
#[test]
fn scope_doesnt_show_hidden_command() {
let actual = nu!(
cwd: ".",
r#"def xaz [] { echo xaz }
let actual = nu!("def xaz [] { echo xaz }
hide xaz
scope commands | find xaz | length
"#
);
");
let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 0);
@ -92,15 +74,12 @@ fn scope_doesnt_show_hidden_command() {
#[ignore]
#[test]
fn correctly_report_of_shadowed_alias() {
let actual = nu!(
cwd: ".",
r#"alias xaz = echo alias1
let actual = nu!("alias xaz = echo alias1
def helper [] {
alias xaz = echo alias2
scope aliases
}
helper | where alias == xaz | get expansion.0"#
);
helper | where alias == xaz | get expansion.0");
assert_eq!(actual.out, "echo alias2");
}

View File

@ -1,31 +1,30 @@
use super::support::Trusted;
use nu_test_support::fs::Stub::FileWithContent;
use nu_test_support::nu;
use nu_test_support::playground::Playground;
use nu_test_support::{nu_repl_code, pipeline};
use nu_test_support::{nu, nu_repl_code};
use pretty_assertions::assert_eq;
use serial_test::serial;
#[test]
fn env_shorthand() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
FOO=bar echo $env.FOO
"#);
");
assert_eq!(actual.out, "bar");
}
#[test]
fn env_shorthand_with_equals() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
RUST_LOG=my_module=info $env.RUST_LOG
"#);
");
assert_eq!(actual.out, "my_module=info");
}
#[test]
fn env_shorthand_with_interpolation() {
let actual = nu!(cwd: ".", r#"
let actual = nu!(r#"
let num = 123
FOO=$"($num) bar" echo $env.FOO
"#);
@ -34,25 +33,25 @@ fn env_shorthand_with_interpolation() {
#[test]
fn env_shorthand_with_comma_equals() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
RUST_LOG=info,my_module=info $env.RUST_LOG
"#);
");
assert_eq!(actual.out, "info,my_module=info");
}
#[test]
fn env_shorthand_with_comma_colons_equals() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
RUST_LOG=info,my_module=info,lib_crate::lib_mod=trace $env.RUST_LOG
"#);
");
assert_eq!(actual.out, "info,my_module=info,lib_crate::lib_mod=trace");
}
#[test]
fn env_shorthand_multi_second_with_comma_colons_equals() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
FOO=bar RUST_LOG=info,my_module=info,lib_crate::lib_mod=trace $env.FOO + $env.RUST_LOG
"#);
");
assert_eq!(
actual.out,
"barinfo,my_module=info,lib_crate::lib_mod=trace"
@ -61,9 +60,9 @@ fn env_shorthand_multi_second_with_comma_colons_equals() {
#[test]
fn env_shorthand_multi_first_with_comma_colons_equals() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
RUST_LOG=info,my_module=info,lib_crate::lib_mod=trace FOO=bar $env.FOO + $env.RUST_LOG
"#);
");
assert_eq!(
actual.out,
"barinfo,my_module=info,lib_crate::lib_mod=trace"
@ -72,15 +71,15 @@ fn env_shorthand_multi_first_with_comma_colons_equals() {
#[test]
fn env_shorthand_multi() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
FOO=bar BAR=baz $env.FOO + $env.BAR
"#);
");
assert_eq!(actual.out, "barbaz");
}
#[test]
fn env_assignment() {
let actual = nu!(cwd: ".", r#"
let actual = nu!(r#"
$env.FOOBAR = "barbaz"; $env.FOOBAR
"#);
assert_eq!(actual.out, "barbaz");
@ -88,30 +87,30 @@ fn env_assignment() {
#[test]
fn mutate_env_file_pwd_env_var_fails() {
let actual = nu!(cwd: ".", r#"$env.FILE_PWD = 'foo'"#);
let actual = nu!("$env.FILE_PWD = 'foo'");
assert!(actual.err.contains("automatic_env_var_set_manually"));
}
#[test]
fn load_env_file_pwd_env_var_fails() {
let actual = nu!(cwd: ".", r#"load-env { FILE_PWD : 'foo' }"#);
let actual = nu!("load-env { FILE_PWD : 'foo' }");
assert!(actual.err.contains("automatic_env_var_set_manually"));
}
#[test]
fn load_env_pwd_env_var_fails() {
let actual = nu!(cwd: ".", r#"load-env { PWD : 'foo' }"#);
let actual = nu!("load-env { PWD : 'foo' }");
assert!(actual.err.contains("automatic_env_var_set_manually"));
}
#[test]
fn passes_with_env_env_var_to_external_process() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
with-env [FOO foo] {nu --testbin echo_env FOO}
"#);
");
assert_eq!(actual.out, "foo");
}
@ -151,9 +150,9 @@ fn passes_env_from_local_cfg_to_external_process() {
)]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test(), r#"
nu!(cwd: dirs.test(), "
nu --testbin echo_env FOO
"#)
")
});
assert_eq!(actual.out, "foo");
@ -169,8 +168,8 @@ fn hides_env_in_block() {
"do $b",
];
let actual = nu!(cwd: "tests/shell/environment", pipeline(&inp.join("; ")));
let actual_repl = nu!(cwd: "tests/shell/environment", nu_repl_code(inp));
let actual = nu!(&inp.join("; "));
let actual_repl = nu!(nu_repl_code(inp));
assert!(actual.err.contains("column_not_found"));
assert!(actual_repl.err.contains("column_not_found"));
@ -178,8 +177,8 @@ fn hides_env_in_block() {
#[test]
fn env_var_not_var() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
echo $CARGO
"#);
");
assert!(actual.err.contains("use $env.CARGO instead of $CARGO"));
}

View File

@ -61,42 +61,42 @@ fn picks_up_and_lets_go_env_keys_when_entering_trusted_directory_with_implied_cd
]);
let actual = nu!(
cwd: dirs.test(),
r#"
"
do {autoenv trust -q foo ; = null }
foo
echo $env.testkey"#
echo $env.testkey"
);
assert_eq!(actual.out, "testvalue");
//Assert testkey is gone when leaving foo
let actual = nu!(
cwd: dirs.test(),
r#"
"
do {autoenv trust -q foo; = null } ;
foo
..
echo $env.testkey
"#
"
);
assert!(actual.err.contains("Unknown"));
//Assert testkey is present also when jumping over foo
let actual = nu!(
cwd: dirs.test(),
r#"
"
do {autoenv trust -q foo; = null } ;
do {autoenv trust -q foo/bar; = null } ;
foo/bar
echo $env.testkey
echo $env.bar
"#
"
);
assert_eq!(actual.out, "testvaluetrue");
//Assert bar removed after leaving bar
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust -q foo;
"autoenv trust -q foo;
foo/bar
../..
echo $env.bar"#
echo $env.bar"
);
assert!(actual.err.contains("Unknown"));
});
@ -145,10 +145,10 @@ fn picks_up_env_keys_when_entering_trusted_directory_indirectly() {
let expected = "0.30.0";
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test().join("crates"), r#"
nu!(cwd: dirs.test().join("crates"), "
cd ../../autoenv_test_3
echo $env.nu-ver
"#)
")
});
assert_eq!(actual.out, expected);
@ -324,11 +324,11 @@ fn given_a_hierarchy_of_trusted_directories_when_entering_in_any_nested_ones_sho
]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test().parent().unwrap(), r#"
nu!(cwd: dirs.test().parent().unwrap(), "
do { autoenv trust -q autoenv_test_9/nu_plugin_rb ; = null } # Silence autoenv trust -q message from output
cd autoenv_test_9/nu_plugin_rb
echo $env.organization
"#)
")
});
assert_eq!(actual.out, "nushell");
@ -355,11 +355,11 @@ fn given_a_hierarchy_of_trusted_directories_nested_ones_should_overwrite_variabl
]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test().parent().unwrap(), r#"
nu!(cwd: dirs.test().parent().unwrap(), "
do { autoenv trust -q autoenv_test_10/nu_plugin_rb ; = null } # Silence autoenv trust -q message from output
cd autoenv_test_10/nu_plugin_rb
echo $env.organization
"#)
")
});
assert_eq!(actual.out, "Andrab");
@ -385,16 +385,16 @@ fn local_config_should_not_be_added_when_running_scripts() {
),
FileWithContent(
"script.nu",
r#"cd foo
echo $env.organization"#,
"cd foo
echo $env.organization",
),
]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test(), r#"
nu!(cwd: dirs.test(), "
do { autoenv trust -q foo } # Silence autoenv trust message from output
nu script.nu
"#)
")
});
assert_eq!(actual.out, "nu");
@ -419,14 +419,14 @@ fn given_a_hierarchy_of_trusted_directories_going_back_restores_overwritten_vari
]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test().parent().unwrap(), r#"
nu!(cwd: dirs.test().parent().unwrap(), "
do { autoenv trust -q autoenv_test_11/nu_plugin_rb } # Silence autoenv trust message from output
cd autoenv_test_11
cd nu_plugin_rb
do { rm ../.nu-env | ignore } # By deleting the root nu-env we have guarantees that the variable gets restored (not by autoenv when re-entering)
cd ..
echo $env.organization
"#)
")
});
assert_eq!(actual.out, "nushell");
@ -450,38 +450,38 @@ fn local_config_env_var_present_and_removed_correctly() {
//Assert testkey is not present before entering directory
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust -q foo;
echo $env.testkey"#
"autoenv trust -q foo;
echo $env.testkey"
);
assert!(actual.err.contains("Unknown"));
//Assert testkey is present in foo
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust -q foo; cd foo
echo $env.testkey"#
"autoenv trust -q foo; cd foo
echo $env.testkey"
);
assert_eq!(actual.out, "testvalue");
//Assert testkey is present also in subdirectories
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust -q foo; cd foo
"autoenv trust -q foo; cd foo
cd bar
echo $env.testkey"#
echo $env.testkey"
);
assert_eq!(actual.out, "testvalue");
//Assert testkey is present also when jumping over foo
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust -q foo; cd foo/bar
echo $env.testkey"#
"autoenv trust -q foo; cd foo/bar
echo $env.testkey"
);
assert_eq!(actual.out, "testvalue");
//Assert testkey removed after leaving foo
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust -q foo; cd foo
"autoenv trust -q foo; cd foo
cd ..
echo $env.testkey"#
echo $env.testkey"
);
assert!(actual.err.contains("Unknown"));
});
@ -512,42 +512,42 @@ fn local_config_env_var_gets_overwritten() {
//Assert overwrite_me is not present before entering directory
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust -q foo;
echo $env.overwrite_me"#
"autoenv trust -q foo;
echo $env.overwrite_me"
);
assert!(actual.err.contains("Unknown"));
//Assert overwrite_me is foo in foo
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust -q foo; cd foo
echo $env.overwrite_me"#
"autoenv trust -q foo; cd foo
echo $env.overwrite_me"
);
assert_eq!(actual.out, "foo");
//Assert overwrite_me is bar in bar
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust -q foo
"autoenv trust -q foo
autoenv trust -q foo/bar
cd foo
cd bar
echo $env.overwrite_me"#
echo $env.overwrite_me"
);
assert_eq!(actual.out, "bar");
//Assert overwrite_me is present also when jumping over foo
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust -q foo; autoenv trust -q foo/bar; cd foo/bar
"autoenv trust -q foo; autoenv trust -q foo/bar; cd foo/bar
echo $env.overwrite_me
"#
"
);
assert_eq!(actual.out, "bar");
//Assert overwrite_me removed after leaving bar
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust -q foo; autoenv trust -q foo/bar; cd foo
"autoenv trust -q foo; autoenv trust -q foo/bar; cd foo
cd bar
cd ..
echo $env.overwrite_me"#
echo $env.overwrite_me"
);
assert_eq!(actual.out, "foo");
});

View File

@ -12,8 +12,7 @@ mod pipeline;
#[ignore]
#[test]
fn plugins_are_declared_with_wix() {
let actual = nu!(
cwd: ".", pipeline(
let actual = nu!(pipeline(
r#"
open Cargo.toml
| get bin.name
@ -73,9 +72,9 @@ fn nu_lib_dirs_repl() {
)]);
let inp_lines = &[
r#"$env.NU_LIB_DIRS = [ ('scripts' | path expand) ]"#,
r#"source-env foo.nu"#,
r#"$env.FOO"#,
"$env.NU_LIB_DIRS = [ ('scripts' | path expand) ]",
"source-env foo.nu",
"$env.FOO",
];
let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(inp_lines));
@ -98,15 +97,15 @@ fn nu_lib_dirs_script() {
)])
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
source-env foo.nu
"#,
",
)]);
let inp_lines = &[
r#"$env.NU_LIB_DIRS = [ ('scripts' | path expand) ]"#,
r#"source-env main.nu"#,
r#"$env.FOO"#,
"$env.NU_LIB_DIRS = [ ('scripts' | path expand) ]",
"source-env main.nu",
"$env.FOO",
];
let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(inp_lines));
@ -129,9 +128,9 @@ fn nu_lib_dirs_relative_repl() {
)]);
let inp_lines = &[
r#"$env.NU_LIB_DIRS = [ 'scripts' ]"#,
r#"source-env foo.nu"#,
r#"$env.FOO"#,
"$env.NU_LIB_DIRS = [ 'scripts' ]",
"source-env foo.nu",
"$env.FOO",
];
let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(inp_lines));
@ -155,11 +154,11 @@ fn const_nu_lib_dirs_relative() {
)])
.with_files(vec![FileWithContentToBeTrimmed(
"main.nu",
r#"
"
const NU_LIB_DIRS = [ 'scripts' ]
source-env foo.nu
$env.FOO
"#,
",
)]);
let outcome = nu!(cwd: dirs.test(), "source main.nu");
@ -176,9 +175,9 @@ fn nu_lib_dirs_relative_script() {
.mkdir("scripts")
.with_files(vec![FileWithContentToBeTrimmed(
"scripts/main.nu",
r#"
"
source-env ../foo.nu
"#,
",
)])
.with_files(vec![FileWithContentToBeTrimmed(
"foo.nu",
@ -188,9 +187,9 @@ fn nu_lib_dirs_relative_script() {
)]);
let inp_lines = &[
r#"$env.NU_LIB_DIRS = [ 'scripts' ]"#,
r#"source-env scripts/main.nu"#,
r#"$env.FOO"#,
"$env.NU_LIB_DIRS = [ 'scripts' ]",
"source-env scripts/main.nu",
"$env.FOO",
];
let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(inp_lines));
@ -204,12 +203,12 @@ fn nu_lib_dirs_relative_script() {
fn run_script_that_looks_like_module() {
Playground::setup("run_script_that_looks_like_module", |dirs, _| {
let inp_lines = &[
r#"module spam { export def eggs [] { 'eggs' } }"#,
r#"export use spam eggs"#,
r#"export def foo [] { eggs }"#,
r#"export alias bar = foo"#,
r#"export def-env baz [] { bar }"#,
r#"baz"#,
"module spam { export def eggs [] { 'eggs' } }",
"export use spam eggs",
"export def foo [] { eggs }",
"export alias bar = foo",
"export def-env baz [] { bar }",
"baz",
];
let actual = nu!(cwd: dirs.test(), inp_lines.join("; "));
@ -221,7 +220,7 @@ fn run_script_that_looks_like_module() {
#[test]
fn run_export_extern() {
Playground::setup("run_script_that_looks_like_module", |dirs, _| {
let inp_lines = &[r#"export extern foo []"#, r#"help foo"#];
let inp_lines = &["export extern foo []", "help foo"];
let actual = nu!(cwd: dirs.test(), inp_lines.join("; "));

View File

@ -4,10 +4,7 @@ use pretty_assertions::assert_eq;
#[cfg(feature = "which-support")]
#[test]
fn shows_error_for_command_not_found() {
let actual = nu!(
cwd: ".",
"ferris_is_not_here.exe"
);
let actual = nu!("ferris_is_not_here.exe");
assert!(!actual.err.is_empty());
}
@ -15,10 +12,7 @@ fn shows_error_for_command_not_found() {
#[cfg(feature = "which-support")]
#[test]
fn shows_error_for_command_not_found_in_pipeline() {
let actual = nu!(
cwd: ".",
"ferris_is_not_here.exe | echo done"
);
let actual = nu!("ferris_is_not_here.exe | echo done");
assert!(!actual.err.is_empty());
}
@ -34,10 +28,10 @@ fn automatically_change_directory() {
let actual = nu!(
cwd: dirs.test(),
r#"
"
autodir
echo (pwd)
"#
"
);
assert!(actual.out.ends_with("autodir"));
@ -55,10 +49,10 @@ fn automatically_change_directory_with_trailing_slash_and_same_name_as_command()
let actual = nu!(
cwd: dirs.test(),
r#"
"
cd/
pwd
"#
"
);
assert!(actual.out.ends_with("cd"));
@ -67,23 +61,21 @@ fn automatically_change_directory_with_trailing_slash_and_same_name_as_command()
#[test]
fn correctly_escape_external_arguments() {
let actual = nu!(cwd: ".", r#"^nu --testbin cococo '$0'"#);
let actual = nu!("^nu --testbin cococo '$0'");
assert_eq!(actual.out, "$0");
}
#[test]
fn escape_also_escapes_equals() {
let actual = nu!(cwd: ".", r#"^MYFOONAME=MYBARVALUE"#);
let actual = nu!("^MYFOONAME=MYBARVALUE");
assert!(actual.err.contains("executable was not found"));
}
#[test]
fn execute_binary_in_string() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
let cmd = "nu"
^$"($cmd)" --testbin cococo "$0"
"#);
@ -93,21 +85,21 @@ fn execute_binary_in_string() {
#[test]
fn single_quote_dollar_external() {
let actual = nu!(cwd: ".", r#"let author = 'JT'; ^echo $'foo=($author)'"#);
let actual = nu!("let author = 'JT'; ^echo $'foo=($author)'");
assert_eq!(actual.out, "foo=JT");
}
#[test]
fn redirects_custom_command_external() {
let actual = nu!(cwd: ".", r#"def foo [] { nu --testbin cococo foo bar }; foo | str length"#);
let actual = nu!("def foo [] { nu --testbin cococo foo bar }; foo | str length");
assert_eq!(actual.out, "8");
}
#[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"#);
let actual = nu!(cwd: "tests/fixtures/formats", "nu --testbin meowb sample.db | nu --testbin relay | hash sha256");
assert_eq!(
actual.out,
@ -118,44 +110,35 @@ fn passes_binary_data_between_externals() {
#[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");
let actual = nu!("ls | distinct");
assert!(actual.err.contains("uniq"));
}
#[test]
fn command_not_found_error_suggests_typo_fix() {
let actual = nu!(cwd: ".", "benchmark { echo 'foo'}");
let actual = nu!("benchmark { echo 'foo'}");
assert!(actual.err.contains("timeit"));
}
#[test]
fn command_not_found_error_shows_not_found() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
export extern "foo" [];
foo
"#
);
"#);
assert!(actual.err.contains("'foo' was not found"));
}
#[test]
fn command_substitution_wont_output_extra_newline() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(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#"
let actual = nu!(r#"
with-env [FOO "bar"] { (nu --testbin echo_env FOO) }
"#
);
"#);
assert_eq!(actual.out, "bar");
}
@ -174,13 +157,13 @@ mod it_evaluation {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
ls
| sort-by name
| get name
| each { |it| nu --testbin cococo $it }
| get 1
"#
"
));
assert_eq!(actual.out, "jt_likes_cake.txt");
@ -192,20 +175,20 @@ mod it_evaluation {
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
| each { |it| nu --testbin chop $it}
| get 1
"#
"
));
assert_eq!(actual.out, "AndrásWithKitKat");
@ -214,12 +197,9 @@ mod it_evaluation {
#[test]
fn can_properly_buffer_lines_externally() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!("
nu --testbin repeater c 8197 | lines | length
"#
);
");
assert_eq!(actual.out, "1");
}
@ -235,10 +215,10 @@ mod it_evaluation {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
open sample.toml
| nu --testbin cococo $in.nu_party_venue
"#
"
));
assert_eq!(actual.out, "zion");
@ -252,9 +232,8 @@ mod stdin_evaluation {
#[test]
fn does_not_panic_with_no_newline_in_stream() {
let actual = nu!(
cwd: ".",
pipeline(r#"
let actual = nu!(pipeline(
r#"
nu --testbin nonu "wheres the nuline?" | length
"#
));
@ -264,15 +243,14 @@ mod stdin_evaluation {
#[test]
fn does_not_block_indefinitely() {
let stdout = nu!(
cwd: ".",
pipeline(r#"
let stdout = nu!(pipeline(
"
( nu --testbin iecho yes
| nu --testbin chop
| nu --testbin chop
| lines
| first )
"#
"
))
.out;
@ -286,9 +264,9 @@ mod external_words {
use nu_test_support::{pipeline, playground::Playground};
#[test]
fn relaxed_external_words() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
nu --testbin cococo joturner@foo.bar.baz
"#);
");
assert_eq!(actual.out, "joturner@foo.bar.baz");
}
@ -297,7 +275,7 @@ mod external_words {
#[ignore]
#[test]
fn no_escaping_for_single_quoted_strings() {
let actual = nu!(cwd: ".", r#"
let actual = nu!(r#"
nu --testbin cococo 'test "things"'
"#);
@ -328,9 +306,9 @@ mod external_words {
let actual = nu!(
cwd: dirs.test(), pipeline(
&format!(r#"
&format!("
nu --testbin meow {nu_path_argument} | from toml | get nu_party_venue
"#)
")
));
assert_eq!(actual.out, "zion");
@ -345,7 +323,7 @@ mod nu_commands {
#[test]
fn echo_internally_externally() {
let actual = nu!(cwd: ".", r#"
let actual = nu!(r#"
nu -c "echo 'foo'"
"#);
@ -366,7 +344,7 @@ mod nu_commands {
#[test]
fn better_arg_quoting() {
let actual = nu!(cwd: ".", r#"
let actual = nu!(r#"
nu -c "\# '"
"#);
@ -375,9 +353,9 @@ mod nu_commands {
#[test]
fn command_list_arg_test() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
nu ['-c' 'version']
"#);
");
assert!(actual.out.contains("version"));
assert!(actual.out.contains("rust_version"));
@ -386,9 +364,9 @@ mod nu_commands {
#[test]
fn command_cell_path_arg_test() {
let actual = nu!(cwd: ".", r#"
let actual = nu!("
nu ([ '-c' 'version' ])
"#);
");
assert!(actual.out.contains("version"));
assert!(actual.out.contains("rust_version"));
@ -401,18 +379,18 @@ mod nu_script {
#[test]
fn run_nu_script() {
let actual = nu!(cwd: "tests/fixtures/formats", r#"
let actual = nu!(cwd: "tests/fixtures/formats", "
nu script.nu
"#);
");
assert_eq!(actual.out, "done");
}
#[test]
fn run_nu_script_multiline() {
let actual = nu!(cwd: "tests/fixtures/formats", r#"
let actual = nu!(cwd: "tests/fixtures/formats", "
nu script_multiline.nu
"#);
");
assert_eq!(actual.out, "23");
}
@ -423,24 +401,18 @@ mod tilde_expansion {
#[test]
fn as_home_directory_when_passed_as_argument_and_begins_with_tilde() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!("
nu --testbin cococo ~
"#
);
");
assert!(!actual.out.contains('~'));
}
#[test]
fn does_not_expand_when_passed_as_argument_and_does_not_start_with_tilde() {
let actual = nu!(
cwd: ".",
r#"
let actual = nu!(r#"
nu --testbin cococo "1~1"
"#
);
"#);
assert_eq!(actual.out, "1~1");
}
@ -463,9 +435,9 @@ mod external_command_arguments {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
"
nu --testbin cococo (ls | get name)
"#
"
));
assert_eq!(
@ -489,9 +461,9 @@ mod external_command_arguments {
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");
@ -524,10 +496,7 @@ mod external_command_arguments {
#[cfg(not(windows))]
#[test]
fn semicolons_are_sanitized_before_passing_to_subshell() {
let actual = nu!(
cwd: ".",
"^echo \"a;b\""
);
let actual = nu!("^echo \"a;b\"");
assert_eq!(actual.out, "a;b");
}
@ -535,10 +504,7 @@ mod external_command_arguments {
#[cfg(not(windows))]
#[test]
fn ampersands_are_sanitized_before_passing_to_subshell() {
let actual = nu!(
cwd: ".",
"^echo \"a&b\""
);
let actual = nu!("^echo \"a&b\"");
assert_eq!(actual.out, "a&b");
}
@ -546,10 +512,7 @@ mod external_command_arguments {
#[cfg(not(windows))]
#[test]
fn subcommands_are_sanitized_before_passing_to_subshell() {
let actual = nu!(
cwd: ".",
"nu --testbin cococo \"$(ls)\""
);
let actual = nu!("nu --testbin cococo \"$(ls)\"");
assert_eq!(actual.out, "$(ls)");
}
@ -557,10 +520,7 @@ mod external_command_arguments {
#[cfg(not(windows))]
#[test]
fn shell_arguments_are_sanitized_even_if_coming_from_other_commands() {
let actual = nu!(
cwd: ".",
"nu --testbin cococo (echo \"a;&$(hello)\")"
);
let actual = nu!("nu --testbin cococo (echo \"a;&$(hello)\")");
assert_eq!(actual.out, "a;&$(hello)");
}

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ use pretty_assertions::assert_eq;
#[test]
fn doesnt_break_on_utf8() {
let actual = nu!(cwd: ".", "echo ö");
let actual = nu!("echo ö");
assert_eq!(actual.out, "ö", "'{}' should contain ö", actual.out);
}