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; use pretty_assertions::assert_eq;
#[test] #[test]
fn const_bool() { 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"); assert_eq!(actual.out, "false");
} }
#[test] #[test]
fn const_int() { 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"); assert_eq!(actual.out, "10");
} }
#[test] #[test]
fn const_float() { 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"); assert_eq!(actual.out, "1.234");
} }
#[test] #[test]
fn const_binary() { 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")); assert!(actual.out.contains("12"));
} }
#[test] #[test]
fn const_datetime() { 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")); assert!(actual.out.contains("Sat, 27 Feb 2021 13:55:40"));
} }
#[test] #[test]
fn const_list() { 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>"); assert_eq!(actual.out, "list<string>");
} }
#[test] #[test]
fn const_record() { 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>"); assert_eq!(actual.out, "record<a: int, b: int, c: int>");
} }
@ -67,38 +67,38 @@ fn const_record() {
#[test] #[test]
fn const_table() { fn const_table() {
let inp = &[ let inp = &[
r#"const x = [[a b c]; [10 20 30] [100 200 300]]"#, "const x = [[a b c]; [10 20 30] [100 200 300]]",
r#"$x | describe"#, "$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>"); assert_eq!(actual.out, "table<a: int, b: int, c: int>");
} }
#[test] #[test]
fn const_string() { 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"); assert_eq!(actual.out, "abc");
} }
#[test] #[test]
fn const_nothing() { 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"); assert_eq!(actual.out, "nothing");
} }
#[test] #[test]
fn const_unsupported() { 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")); assert!(actual.err.contains("not_a_constant"));
} }

View File

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

View File

@ -11,7 +11,7 @@ fn env_change_hook_code_list(name: &str, code_list: &[&str]) -> String {
} }
format!( format!(
r#"$env.config = {{ "$env.config = {{
hooks: {{ hooks: {{
env_change: {{ env_change: {{
{name} : [ {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 { fn env_change_hook(name: &str, code: &str) -> String {
format!( format!(
r#"$env.config = {{ "$env.config = {{
hooks: {{ hooks: {{
env_change: {{ env_change: {{
{name} : {code} {name} : {code}
}} }}
}} }}
}}"# }}"
) )
} }
fn env_change_hook_code(name: &str, code: &str) -> String { fn env_change_hook_code(name: &str, code: &str) -> String {
format!( format!(
r#"$env.config = {{ "$env.config = {{
hooks: {{ hooks: {{
env_change: {{ env_change: {{
{name} : {{ {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 { fn env_change_hook_code_condition(name: &str, condition: &str, code: &str) -> String {
format!( format!(
r#"$env.config = {{ "$env.config = {{
hooks: {{ hooks: {{
env_change: {{ env_change: {{
{name} : {{ {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 { fn pre_prompt_hook(code: &str) -> String {
format!( format!(
r#"$env.config = {{ "$env.config = {{
hooks: {{ hooks: {{
pre_prompt: {code} pre_prompt: {code}
}} }}
}}"# }}"
) )
} }
fn pre_prompt_hook_code(code: &str) -> String { fn pre_prompt_hook_code(code: &str) -> String {
format!( format!(
r#"$env.config = {{ "$env.config = {{
hooks: {{ hooks: {{
pre_prompt: {{ pre_prompt: {{
code: {code} code: {code}
}} }}
}} }}
}}"# }}"
) )
} }
fn pre_execution_hook(code: &str) -> String { fn pre_execution_hook(code: &str) -> String {
format!( format!(
r#"$env.config = {{ "$env.config = {{
hooks: {{ hooks: {{
pre_execution: {code} pre_execution: {code}
}} }}
}}"# }}"
) )
} }
fn pre_execution_hook_code(code: &str) -> String { fn pre_execution_hook_code(code: &str) -> String {
format!( format!(
r#"$env.config = {{ "$env.config = {{
hooks: {{ hooks: {{
pre_execution: {{ pre_execution: {{
code: {code} code: {code}
}} }}
}} }}
}}"# }}"
) )
} }
@ -116,7 +116,7 @@ fn env_change_define_command() {
"foo", "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.err, "");
assert_eq!(actual_repl.out, "got foo!"); assert_eq!(actual_repl.out, "got foo!");
@ -130,7 +130,7 @@ fn env_change_define_variable() {
"$x", "$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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -144,7 +144,7 @@ fn env_change_define_env_var() {
"$env.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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -158,7 +158,7 @@ fn env_change_define_alias() {
"spam", "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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -172,7 +172,7 @@ fn env_change_simple_block_preserve_env_var() {
"$env.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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -192,7 +192,7 @@ fn env_change_simple_block_list_shadow_env_var() {
"$env.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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -206,7 +206,7 @@ fn env_change_block_preserve_env_var() {
"$env.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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -219,7 +219,7 @@ fn pre_prompt_define_command() {
"foo", "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.err, "");
assert_eq!(actual_repl.out, "got foo!"); assert_eq!(actual_repl.out, "got foo!");
@ -229,7 +229,7 @@ fn pre_prompt_define_command() {
fn pre_prompt_simple_block_preserve_env_var() { fn pre_prompt_simple_block_preserve_env_var() {
let inp = &[&pre_prompt_hook(r#"{|| $env.SPAM = "spam" }"#), "$env.SPAM"]; 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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -247,7 +247,7 @@ fn pre_prompt_simple_block_list_shadow_env_var() {
"$env.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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -260,7 +260,7 @@ fn pre_prompt_block_preserve_env_var() {
"$env.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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -273,7 +273,7 @@ fn pre_execution_define_command() {
"foo", "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.err, "");
assert_eq!(actual_repl.out, "got foo!"); assert_eq!(actual_repl.out, "got foo!");
@ -286,7 +286,7 @@ fn pre_execution_simple_block_preserve_env_var() {
"$env.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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -304,7 +304,7 @@ fn pre_execution_simple_block_list_shadow_env_var() {
"$env.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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -317,7 +317,7 @@ fn pre_execution_block_preserve_env_var() {
"$env.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.err, "");
assert_eq!(actual_repl.out, "spam"); assert_eq!(actual_repl.out, "spam");
@ -326,11 +326,11 @@ fn pre_execution_block_preserve_env_var() {
#[test] #[test]
fn pre_execution_commandline() { fn pre_execution_commandline() {
let inp = &[ let inp = &[
&pre_execution_hook_code(r#"{|| $env.repl_commandline = (commandline) }"#), &pre_execution_hook_code("{|| $env.repl_commandline = (commandline) }"),
"$env.repl_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.err, "");
assert_eq!(actual_repl.out, "$env.repl_commandline"); assert_eq!(actual_repl.out, "$env.repl_commandline");
@ -350,7 +350,7 @@ fn env_change_shadow_command() {
"foo", "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.err, "");
assert_eq!(actual_repl.out, "got foo!"); assert_eq!(actual_repl.out, "got foo!");
@ -364,7 +364,7 @@ fn env_change_block_dont_preserve_command() {
"foo", "foo",
]; ];
let actual_repl = nu!(cwd: "tests/hooks", nu_repl_code(inp)); let actual_repl = nu!(nu_repl_code(inp));
#[cfg(windows)] #[cfg(windows)]
assert_ne!(actual_repl.out, "foo"); assert_ne!(actual_repl.out, "foo");
@ -377,8 +377,8 @@ fn env_change_block_condition_pwd() {
let inp = &[ let inp = &[
&env_change_hook_code_condition( &env_change_hook_code_condition(
"PWD", "PWD",
r#"{|before, after| ($after | path basename) == samples }"#, "{|before, after| ($after | path basename) == samples }",
r#"'source-env .nu-env'"#, "'source-env .nu-env'",
), ),
"cd samples", "cd samples",
"$env.SPAM", "$env.SPAM",
@ -393,18 +393,18 @@ fn env_change_block_condition_pwd() {
#[test] #[test]
fn env_change_block_condition_correct_args() { fn env_change_block_condition_correct_args() {
let inp = &[ let inp = &[
r#"$env.FOO = 1"#, "$env.FOO = 1",
&env_change_hook_code_condition( &env_change_hook_code_condition(
"FOO", "FOO",
r#"{|before, after| $before == 1 and $after == 2}"#, "{|before, after| $before == 1 and $after == 2}",
r#"{|before, after| $env.SPAM = ($before == 1 and $after == 2) }"#, "{|before, after| $env.SPAM = ($before == 1 and $after == 2) }",
), ),
"", "",
r#"$env.FOO = 2"#, "$env.FOO = 2",
"$env.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.err, "");
assert_eq!(actual_repl.out, "true"); assert_eq!(actual_repl.out, "true");
@ -413,12 +413,12 @@ fn env_change_block_condition_correct_args() {
#[test] #[test]
fn env_change_dont_panic_with_many_args() { fn env_change_dont_panic_with_many_args() {
let inp = &[ 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", "$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!(actual_repl.err.contains("incompatible_parameters"));
assert_eq!(actual_repl.out, ""); assert_eq!(actual_repl.out, "");
@ -427,18 +427,18 @@ fn env_change_dont_panic_with_many_args() {
#[test] #[test]
fn err_hook_wrong_env_type_1() { fn err_hook_wrong_env_type_1() {
let inp = &[ let inp = &[
r#"$env.config = { "$env.config = {
hooks: { hooks: {
env_change: { env_change: {
FOO : 1 FOO : 1
} }
} }
}"#, }",
"$env.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); dbg!(&actual_repl.err);
assert!(actual_repl.err.contains("unsupported_config_value")); 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!(actual_repl.err.contains("type_mismatch"));
assert_eq!(actual_repl.out, ""); assert_eq!(actual_repl.out, "");
@ -465,7 +465,7 @@ fn err_hook_wrong_env_type_2() {
#[test] #[test]
fn err_hook_wrong_env_type_3() { fn err_hook_wrong_env_type_3() {
let inp = &[ let inp = &[
r#"$env.config = { "$env.config = {
hooks: { hooks: {
env_change: { env_change: {
FOO : { FOO : {
@ -473,12 +473,12 @@ fn err_hook_wrong_env_type_3() {
} }
} }
} }
}"#, }",
"$env.FOO = 1", "$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!(actual_repl.err.contains("unsupported_config_value"));
assert_eq!(actual_repl.out, ""); 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!(actual_repl.err.contains("unsupported_config_value"));
assert_eq!(actual_repl.out, ""); 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!(actual_repl.err.contains("unsupported_config_value"));
assert_eq!(actual_repl.out, ""); 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!(actual_repl.err.contains("unsupported_config_value"));
assert_eq!(actual_repl.out, ""); assert_eq!(actual_repl.out, "");
@ -556,7 +556,7 @@ fn err_hook_parse_error() {
fn err_hook_dont_allow_string() { fn err_hook_dont_allow_string() {
let inp = &[&pre_prompt_hook(r#"'def foo [] { "got foo!" }'"#), "foo"]; 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.out.is_empty());
assert!(actual_repl.err.contains("unsupported_config_value")); 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::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground; 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; use pretty_assertions::assert_eq;
#[test] #[test]
@ -9,11 +9,11 @@ fn module_private_import_decl() {
sandbox sandbox
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"main.nu", "main.nu",
r#" "
use spam.nu foo-helper use spam.nu foo-helper
export def foo [] { foo-helper } export def foo [] { foo-helper }
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "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"); assert_eq!(actual.out, "foo");
}) })
@ -37,11 +37,11 @@ fn module_private_import_alias() {
sandbox sandbox
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"main.nu", "main.nu",
r#" "
use spam.nu foo-helper use spam.nu foo-helper
export def foo [] { foo-helper } export def foo [] { foo-helper }
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "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"); assert_eq!(actual.out, "foo");
}) })
@ -64,9 +64,9 @@ fn module_private_import_decl_not_public() {
sandbox sandbox
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"main.nu", "main.nu",
r#" "
use spam.nu foo-helper use spam.nu foo-helper
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "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()); assert!(!actual.err.is_empty());
}) })
@ -90,9 +90,9 @@ fn module_public_import_decl() {
sandbox sandbox
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"main.nu", "main.nu",
r#" "
export use spam.nu foo export use spam.nu foo
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "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"); assert_eq!(actual.out, "foo");
}) })
@ -116,9 +116,9 @@ fn module_public_import_alias() {
sandbox sandbox
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"main.nu", "main.nu",
r#" "
export use spam.nu foo export use spam.nu foo
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "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"); assert_eq!(actual.out, "foo");
}) })
@ -141,21 +141,21 @@ fn module_nested_imports() {
sandbox sandbox
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"main.nu", "main.nu",
r#" "
export use spam.nu [ foo bar ] export use spam.nu [ foo bar ]
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "spam.nu",
r#" "
export use spam2.nu [ foo bar ] export use spam2.nu [ foo bar ]
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam2.nu", "spam2.nu",
r#" "
export use spam3.nu [ foo bar ] export use spam3.nu [ foo bar ]
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam3.nu", "spam3.nu",
@ -165,13 +165,13 @@ fn module_nested_imports() {
"#, "#,
)]); )]);
let inp1 = &[r#"use main.nu foo"#, r#"foo"#]; let inp1 = &["use main.nu foo", "foo"];
let inp2 = &[r#"use main.nu bar"#, r#"bar"#]; 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"); 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"); assert_eq!(actual.out, "bar");
}) })
} }
@ -185,21 +185,21 @@ fn module_nested_imports_in_dirs() {
.mkdir("spam/spam3") .mkdir("spam/spam3")
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"main.nu", "main.nu",
r#" "
export use spam/spam.nu [ foo bar ] export use spam/spam.nu [ foo bar ]
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam/spam.nu", "spam/spam.nu",
r#" "
export use spam2/spam2.nu [ foo bar ] export use spam2/spam2.nu [ foo bar ]
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam/spam2/spam2.nu", "spam/spam2/spam2.nu",
r#" "
export use ../spam3/spam3.nu [ foo bar ] export use ../spam3/spam3.nu [ foo bar ]
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam/spam3/spam3.nu", "spam/spam3/spam3.nu",
@ -209,13 +209,13 @@ fn module_nested_imports_in_dirs() {
"#, "#,
)]); )]);
let inp1 = &[r#"use main.nu foo"#, r#"foo"#]; let inp1 = &["use main.nu foo", "foo"];
let inp2 = &[r#"use main.nu bar"#, r#"bar"#]; 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"); 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"); assert_eq!(actual.out, "bar");
}) })
} }
@ -226,9 +226,9 @@ fn module_public_import_decl_prefixed() {
sandbox sandbox
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"main.nu", "main.nu",
r#" "
export use spam.nu export use spam.nu
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "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"); assert_eq!(actual.out, "foo");
}) })
@ -261,16 +261,16 @@ fn module_nested_imports_in_dirs_prefixed() {
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam/spam.nu", "spam/spam.nu",
r#" "
export use spam2/spam2.nu export use spam2/spam2.nu
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam/spam2/spam2.nu", "spam/spam2/spam2.nu",
r#" "
export use ../spam3/spam3.nu export use ../spam3/spam3.nu
export use ../spam3/spam3.nu foo export use ../spam3/spam3.nu foo
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam/spam3/spam3.nu", "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 inp1 = &["use main.nu", "main spam2 foo"];
let inp2 = &[r#"use main.nu "spam2 spam3 bar""#, r#"spam2 spam3 bar"#]; 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"); 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"); assert_eq!(actual.out, "bar");
}) })
} }
@ -297,11 +297,11 @@ fn module_import_env_1() {
sandbox sandbox
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"main.nu", "main.nu",
r#" "
export-env { source-env spam.nu } export-env { source-env spam.nu }
export def foo [] { $env.FOO_HELPER } export def foo [] { $env.FOO_HELPER }
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "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"); assert_eq!(actual.out, "foo");
}) })
@ -324,9 +324,9 @@ fn module_import_env_2() {
sandbox sandbox
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"main.nu", "main.nu",
r#" "
export-env { source-env spam.nu } export-env { source-env spam.nu }
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "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"); assert_eq!(actual.out, "foo");
}) })
@ -348,14 +348,14 @@ fn module_cyclical_imports_0() {
Playground::setup("module_cyclical_imports_0", |dirs, sandbox| { Playground::setup("module_cyclical_imports_0", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed( sandbox.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "spam.nu",
r#" "
use eggs.nu 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")); assert!(actual.err.contains("module not found"));
}) })
@ -366,14 +366,14 @@ fn module_cyclical_imports_1() {
Playground::setup("module_cyclical_imports_1", |dirs, sandbox| { Playground::setup("module_cyclical_imports_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed( sandbox.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "spam.nu",
r#" "
use spam.nu 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")); assert!(actual.err.contains("cyclical"));
}) })
@ -385,20 +385,20 @@ fn module_cyclical_imports_2() {
sandbox sandbox
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "spam.nu",
r#" "
use eggs.nu use eggs.nu
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"eggs.nu", "eggs.nu",
r#" "
use spam.nu 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")); assert!(actual.err.contains("cyclical"));
}) })
@ -410,26 +410,26 @@ fn module_cyclical_imports_3() {
sandbox sandbox
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"spam.nu", "spam.nu",
r#" "
use eggs.nu use eggs.nu
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"eggs.nu", "eggs.nu",
r#" "
use bacon.nu use bacon.nu
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"bacon.nu", "bacon.nu",
r#" "
use spam.nu 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")); 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"); assert_eq!(actual.out, "foo");
}) })
@ -465,12 +465,12 @@ fn module_import_const_module_name() {
let inp = &[ let inp = &[
r#"module spam { export def foo [] { "foo" } }"#, r#"module spam { export def foo [] { "foo" } }"#,
r#"const mod = 'spam'"#, "const mod = 'spam'",
r#"use $mod foo"#, "use $mod foo",
r#"foo"#, "foo",
]; ];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; "))); let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "foo"); assert_eq!(actual.out, "foo");
}) })
@ -480,7 +480,7 @@ fn module_import_const_module_name() {
fn module_valid_def_name() { fn module_valid_def_name() {
let inp = &[r#"module spam { def spam [] { "spam" } }"#]; let inp = &[r#"module spam { def spam [] { "spam" } }"#];
let actual = nu!(cwd: ".", pipeline(&inp.join("; "))); let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, ""); assert_eq!(actual.out, "");
} }
@ -489,7 +489,7 @@ fn module_valid_def_name() {
fn module_invalid_def_name() { fn module_invalid_def_name() {
let inp = &[r#"module spam { export def spam [] { "spam" } }"#]; 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")); assert!(actual.err.contains("named_as_module"));
} }
@ -498,7 +498,7 @@ fn module_invalid_def_name() {
fn module_valid_alias_name_1() { fn module_valid_alias_name_1() {
let inp = &[r#"module spam { alias spam = echo "spam" }"#]; 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, ""); assert_eq!(actual.out, "");
} }
@ -507,7 +507,7 @@ fn module_valid_alias_name_1() {
fn module_valid_alias_name_2() { fn module_valid_alias_name_2() {
let inp = &[r#"module spam { alias main = echo "spam" }"#]; 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, ""); assert_eq!(actual.out, "");
} }
@ -516,34 +516,34 @@ fn module_valid_alias_name_2() {
fn module_invalid_alias_name() { fn module_invalid_alias_name() {
let inp = &[r#"module spam { export alias spam = echo "spam" }"#]; 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")); assert!(actual.err.contains("named_as_module"));
} }
#[test] #[test]
fn module_main_alias_not_allowed() { 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")); assert!(actual.err.contains("export_main_alias_not_allowed"));
} }
#[test] #[test]
fn module_valid_known_external_name() { 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, ""); assert_eq!(actual.out, "");
} }
#[test] #[test]
fn module_invalid_known_external_name() { 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")); assert!(actual.err.contains("named_as_module"));
} }
@ -551,40 +551,40 @@ fn module_invalid_known_external_name() {
#[test] #[test]
fn main_inside_module_is_main() { fn main_inside_module_is_main() {
let inp = &[ let inp = &[
r#"module spam { "module spam {
export def main [] { 'foo' }; export def main [] { 'foo' };
export def foo [] { main } export def foo [] { main }
}"#, }",
"use spam foo", "use spam foo",
"foo", "foo",
]; ];
let actual = nu!(cwd: ".", pipeline(&inp.join("; "))); let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "foo"); assert_eq!(actual.out, "foo");
} }
#[test] #[test]
fn module_as_file() { 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"); assert_eq!(actual.out, "foo");
} }
#[test] #[test]
fn export_module_as_file() { 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"); assert_eq!(actual.out, "foo");
} }
#[test] #[test]
fn deep_import_patterns() { fn deep_import_patterns() {
let module_decl = r#" let module_decl = "
module spam { module spam {
export module eggs { export module eggs {
export module beans { export module beans {
@ -593,22 +593,22 @@ fn deep_import_patterns() {
}; };
}; };
} }
"#; ";
let inp = &[module_decl, "use spam", "spam eggs beans foo"]; 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"); assert_eq!(actual.out, "foo");
let inp = &[module_decl, "use spam eggs", "eggs beans 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"); assert_eq!(actual.out, "foo");
let inp = &[module_decl, "use spam eggs beans", "beans 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"); assert_eq!(actual.out, "foo");
let inp = &[module_decl, "use spam eggs beans foo", "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"); assert_eq!(actual.out, "foo");
} }
@ -617,27 +617,27 @@ fn module_dir() {
let import = "use samples/spam"; let import = "use samples/spam";
let inp = &[import, "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"); assert_eq!(actual.out, "spam");
let inp = &[import, "spam foo"]; 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"); assert_eq!(actual.out, "foo");
let inp = &[import, "spam bar"]; 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"); assert_eq!(actual.out, "bar");
let inp = &[import, "spam foo baz"]; 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"); assert_eq!(actual.out, "foobaz");
let inp = &[import, "spam bar baz"]; 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"); assert_eq!(actual.out, "barbaz");
let inp = &[import, "spam baz"]; 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"); assert_eq!(actual.out, "spambaz");
} }
@ -646,19 +646,19 @@ fn module_dir_deep() {
let import = "use samples/spam"; let import = "use samples/spam";
let inp = &[import, "spam bacon"]; 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"); assert_eq!(actual_repl.out, "bacon");
let inp = &[import, "spam bacon foo"]; 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"); assert_eq!(actual_repl.out, "bacon foo");
let inp = &[import, "spam bacon beans"]; 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"); assert_eq!(actual_repl.out, "beans");
let inp = &[import, "spam bacon beans foo"]; 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"); assert_eq!(actual_repl.out, "beans foo");
} }
@ -673,28 +673,28 @@ fn module_dir_import_twice_no_panic() {
#[test] #[test]
fn not_allowed_submodule_file() { fn not_allowed_submodule_file() {
let inp = &["use samples/not_allowed"]; 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")); assert!(actual.err.contains("invalid_module_file_name"));
} }
#[test] #[test]
fn module_dir_missing_mod_nu() { fn module_dir_missing_mod_nu() {
let inp = &["use samples/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")); assert!(actual.err.contains("module_missing_mod_nu_file"));
} }
#[test] #[test]
fn allowed_local_module() { fn allowed_local_module() {
let inp = &["module spam { module spam {} }"]; 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()); assert!(actual.err.is_empty());
} }
#[test] #[test]
fn not_allowed_submodule() { fn not_allowed_submodule() {
let inp = &["module spam { export module spam {} }"]; 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")); assert!(actual.err.contains("named_as_module"));
} }
@ -705,48 +705,48 @@ fn module_self_name() {
"use spam", "use spam",
"spam", "spam",
]; ];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; "))); let actual = nu!(&inp.join("; "));
assert_eq!(actual.out, "spam"); assert_eq!(actual.out, "spam");
} }
#[test] #[test]
fn module_self_name_main_not_allowed() { fn module_self_name_main_not_allowed() {
let inp = &[ let inp = &[
r#"module spam { "module spam {
export def main [] { 'main spam' }; export def main [] { 'main spam' };
export module mod { export module mod {
export def main [] { 'mod spam' } export def main [] { 'mod spam' }
} }
}"#, }",
"use spam", "use spam",
"spam", "spam",
]; ];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; "))); let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("module_double_main")); assert!(actual.err.contains("module_double_main"));
let inp = &[ let inp = &[
r#"module spam { "module spam {
export module mod { export module mod {
export def main [] { 'mod spam' } export def main [] { 'mod spam' }
}; };
export def main [] { 'main spam' } export def main [] { 'main spam' }
}"#, }",
"use spam", "use spam",
"spam", "spam",
]; ];
let actual = nu!(cwd: "tests/modules", pipeline(&inp.join("; "))); let actual = nu!(&inp.join("; "));
assert!(actual.err.contains("module_double_main")); assert!(actual.err.contains("module_double_main"));
} }
#[test] #[test]
fn module_main_not_found() { fn module_main_not_found() {
let inp = &["module spam {}", "use spam main"]; 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")); assert!(actual.err.contains("export_not_found"));
let inp = &["module spam {}", "use spam [ main ]"]; 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")); 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] #[test]
fn source_file_relative_to_file() { 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 nu source_file_relative.nu
"#); ");
assert_eq!(actual.out, "5"); assert_eq!(actual.out, "5");
} }
@ -15,55 +15,55 @@ fn source_file_relative_to_file() {
#[test] #[test]
fn source_const_file() { fn source_const_file() {
let actual = nu!(cwd: "tests/parsing/samples", let actual = nu!(cwd: "tests/parsing/samples",
r#" "
const file = 'single_line.nu' const file = 'single_line.nu'
source $file source $file
"#); ");
assert_eq!(actual.out, "5"); assert_eq!(actual.out, "5");
} }
#[test] #[test]
fn run_nu_script_single_line() { 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 nu single_line.nu
"#); ");
assert_eq!(actual.out, "5"); assert_eq!(actual.out, "5");
} }
#[test] #[test]
fn run_nu_script_multiline_start_pipe() { 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 nu multiline_start_pipe.nu
"#); ");
assert_eq!(actual.out, "4"); assert_eq!(actual.out, "4");
} }
#[test] #[test]
fn run_nu_script_multiline_start_pipe_win() { 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 nu multiline_start_pipe_win.nu
"#); ");
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
} }
#[test] #[test]
fn run_nu_script_multiline_end_pipe() { 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 nu multiline_end_pipe.nu
"#); ");
assert_eq!(actual.out, "2"); assert_eq!(actual.out, "2");
} }
#[test] #[test]
fn run_nu_script_multiline_end_pipe_win() { 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 nu multiline_end_pipe_win.nu
"#); ");
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
} }
@ -76,11 +76,11 @@ fn parse_file_relative_to_parsed_file_simple() {
.mkdir("lol/lol") .mkdir("lol/lol")
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"lol/lol/lol.nu", "lol/lol/lol.nu",
r#" "
use ../lol_shell.nu use ../lol_shell.nu
$env.LOL = (lol_shell ls) $env.LOL = (lol_shell ls)
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"lol/lol_shell.nu", "lol/lol_shell.nu",
@ -91,10 +91,10 @@ fn parse_file_relative_to_parsed_file_simple() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
source-env lol/lol/lol.nu; source-env lol/lol/lol.nu;
$env.LOL $env.LOL
"# "
)); ));
assert_eq!(actual.out, "lol"); assert_eq!(actual.out, "lol");
@ -110,13 +110,13 @@ fn parse_file_relative_to_parsed_file() {
.mkdir("lol/lol") .mkdir("lol/lol")
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"lol/lol/lol.nu", "lol/lol/lol.nu",
r#" "
source-env ../../foo.nu source-env ../../foo.nu
use ../lol_shell.nu use ../lol_shell.nu
overlay use ../../lol/lol_shell.nu overlay use ../../lol/lol_shell.nu
$env.LOL = $'($env.FOO) (lol_shell ls) (ls)' $env.LOL = $'($env.FOO) (lol_shell ls) (ls)'
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"lol/lol_shell.nu", "lol/lol_shell.nu",
@ -126,17 +126,17 @@ fn parse_file_relative_to_parsed_file() {
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"foo.nu", "foo.nu",
r#" "
$env.FOO = 'foo' $env.FOO = 'foo'
"#, ",
)]); )]);
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
source-env lol/lol/lol.nu; source-env lol/lol/lol.nu;
$env.LOL $env.LOL
"# "
)); ));
assert_eq!(actual.out, "foo lol 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") .mkdir("lol")
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"lol/lol.nu", "lol/lol.nu",
r#" "
source-env foo.nu source-env foo.nu
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"lol/foo.nu", "lol/foo.nu",
r#" "
$env.FOO = 'good' $env.FOO = 'good'
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"foo.nu", "foo.nu",
r#" "
$env.FOO = 'bad' $env.FOO = 'bad'
"#, ",
)]); )]);
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
source-env lol/lol.nu; source-env lol/lol.nu;
$env.FOO $env.FOO
"# "
)); ));
assert_eq!(actual.out, "good"); assert_eq!(actual.out, "good");
@ -186,22 +186,22 @@ fn parse_file_relative_to_parsed_file_dont_use_cwd_2() {
.mkdir("lol") .mkdir("lol")
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"lol/lol.nu", "lol/lol.nu",
r#" "
source-env foo.nu source-env foo.nu
"#, ",
)]) )])
.with_files(vec![FileWithContentToBeTrimmed( .with_files(vec![FileWithContentToBeTrimmed(
"foo.nu", "foo.nu",
r#" "
$env.FOO = 'bad' $env.FOO = 'bad'
"#, ",
)]); )]);
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
source-env lol/lol.nu source-env lol/lol.nu
"# "
)); ));
assert!(actual.err.contains("File not found")); assert!(actual.err.contains("File not found"));
@ -210,39 +210,35 @@ fn parse_file_relative_to_parsed_file_dont_use_cwd_2() {
#[test] #[test]
fn parse_export_env_in_module() { fn parse_export_env_in_module() {
let actual = nu!(cwd: "tests/parsing/samples", let actual = nu!("
r#"
module spam { export-env { } } module spam { export-env { } }
"#); ");
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
} }
#[test] #[test]
fn parse_export_env_missing_block() { fn parse_export_env_missing_block() {
let actual = nu!(cwd: "tests/parsing/samples", let actual = nu!("
r#"
module spam { export-env } module spam { export-env }
"#); ");
assert!(actual.err.contains("missing block")); assert!(actual.err.contains("missing block"));
} }
#[test] #[test]
fn call_command_with_non_ascii_argument() { fn call_command_with_non_ascii_argument() {
let actual = nu!(cwd: "tests/parsing/samples", let actual = nu!("
r#"
def nu-arg [--umlaut(-ö): int] {} def nu-arg [--umlaut(-ö): int] {}
nu-arg -ö 42 nu-arg -ö 42
"#); ");
assert_eq!(actual.err.len(), 0); assert_eq!(actual.err.len(), 0);
} }
#[test] #[test]
fn parse_long_duration() { fn parse_long_duration() {
let actual = nu!(cwd: "tests/parsing/samples", let actual = nu!(r#"
r#"
"78.797877879789789sec" | into duration "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"] #[ignore = "TODO: This shows old-style aliases. New aliases are under commands"]
#[test] #[test]
fn scope_shows_alias() { fn scope_shows_alias() {
let actual = nu!( let actual = nu!("alias xaz = echo alias1
cwd: ".",
r#"alias xaz = echo alias1
scope aliases | find xaz | length scope aliases | find xaz | length
"# ");
);
let length: i32 = actual.out.parse().unwrap(); let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 1); assert_eq!(length, 1);
@ -17,12 +14,9 @@ fn scope_shows_alias() {
#[test] #[test]
fn scope_shows_command() { fn scope_shows_command() {
let actual = nu!( let actual = nu!("def xaz [] { echo xaz }
cwd: ".",
r#"def xaz [] { echo xaz }
scope commands | find xaz | length scope commands | find xaz | length
"# ");
);
let length: i32 = actual.out.parse().unwrap(); let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 1); assert_eq!(length, 1);
@ -30,15 +24,12 @@ fn scope_shows_command() {
#[test] #[test]
fn scope_doesnt_show_scoped_hidden_alias() { fn scope_doesnt_show_scoped_hidden_alias() {
let actual = nu!( let actual = nu!("alias xaz = echo alias1
cwd: ".",
r#"alias xaz = echo alias1
do { do {
hide xaz hide xaz
scope aliases | find xaz | length scope aliases | find xaz | length
} }
"# ");
);
let length: i32 = actual.out.parse().unwrap(); let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 0); assert_eq!(length, 0);
@ -46,13 +37,10 @@ fn scope_doesnt_show_scoped_hidden_alias() {
#[test] #[test]
fn scope_doesnt_show_hidden_alias() { fn scope_doesnt_show_hidden_alias() {
let actual = nu!( let actual = nu!("alias xaz = echo alias1
cwd: ".",
r#"alias xaz = echo alias1
hide xaz hide xaz
scope aliases | find xaz | length scope aliases | find xaz | length
"# ");
);
let length: i32 = actual.out.parse().unwrap(); let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 0); assert_eq!(length, 0);
@ -60,15 +48,12 @@ fn scope_doesnt_show_hidden_alias() {
#[test] #[test]
fn scope_doesnt_show_scoped_hidden_command() { fn scope_doesnt_show_scoped_hidden_command() {
let actual = nu!( let actual = nu!("def xaz [] { echo xaz }
cwd: ".",
r#"def xaz [] { echo xaz }
do { do {
hide xaz hide xaz
scope commands | find xaz | length scope commands | find xaz | length
} }
"# ");
);
let length: i32 = actual.out.parse().unwrap(); let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 0); assert_eq!(length, 0);
@ -76,13 +61,10 @@ fn scope_doesnt_show_scoped_hidden_command() {
#[test] #[test]
fn scope_doesnt_show_hidden_command() { fn scope_doesnt_show_hidden_command() {
let actual = nu!( let actual = nu!("def xaz [] { echo xaz }
cwd: ".",
r#"def xaz [] { echo xaz }
hide xaz hide xaz
scope commands | find xaz | length scope commands | find xaz | length
"# ");
);
let length: i32 = actual.out.parse().unwrap(); let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 0); assert_eq!(length, 0);
@ -92,15 +74,12 @@ fn scope_doesnt_show_hidden_command() {
#[ignore] #[ignore]
#[test] #[test]
fn correctly_report_of_shadowed_alias() { fn correctly_report_of_shadowed_alias() {
let actual = nu!( let actual = nu!("alias xaz = echo alias1
cwd: ".",
r#"alias xaz = echo alias1
def helper [] { def helper [] {
alias xaz = echo alias2 alias xaz = echo alias2
scope aliases scope aliases
} }
helper | where alias == xaz | get expansion.0"# helper | where alias == xaz | get expansion.0");
);
assert_eq!(actual.out, "echo alias2"); assert_eq!(actual.out, "echo alias2");
} }

View File

@ -1,31 +1,30 @@
use super::support::Trusted; use super::support::Trusted;
use nu_test_support::fs::Stub::FileWithContent; use nu_test_support::fs::Stub::FileWithContent;
use nu_test_support::nu;
use nu_test_support::playground::Playground; 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 pretty_assertions::assert_eq;
use serial_test::serial; use serial_test::serial;
#[test] #[test]
fn env_shorthand() { fn env_shorthand() {
let actual = nu!(cwd: ".", r#" let actual = nu!("
FOO=bar echo $env.FOO FOO=bar echo $env.FOO
"#); ");
assert_eq!(actual.out, "bar"); assert_eq!(actual.out, "bar");
} }
#[test] #[test]
fn env_shorthand_with_equals() { fn env_shorthand_with_equals() {
let actual = nu!(cwd: ".", r#" let actual = nu!("
RUST_LOG=my_module=info $env.RUST_LOG RUST_LOG=my_module=info $env.RUST_LOG
"#); ");
assert_eq!(actual.out, "my_module=info"); assert_eq!(actual.out, "my_module=info");
} }
#[test] #[test]
fn env_shorthand_with_interpolation() { fn env_shorthand_with_interpolation() {
let actual = nu!(cwd: ".", r#" let actual = nu!(r#"
let num = 123 let num = 123
FOO=$"($num) bar" echo $env.FOO FOO=$"($num) bar" echo $env.FOO
"#); "#);
@ -34,25 +33,25 @@ fn env_shorthand_with_interpolation() {
#[test] #[test]
fn env_shorthand_with_comma_equals() { fn env_shorthand_with_comma_equals() {
let actual = nu!(cwd: ".", r#" let actual = nu!("
RUST_LOG=info,my_module=info $env.RUST_LOG RUST_LOG=info,my_module=info $env.RUST_LOG
"#); ");
assert_eq!(actual.out, "info,my_module=info"); assert_eq!(actual.out, "info,my_module=info");
} }
#[test] #[test]
fn env_shorthand_with_comma_colons_equals() { 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 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"); assert_eq!(actual.out, "info,my_module=info,lib_crate::lib_mod=trace");
} }
#[test] #[test]
fn env_shorthand_multi_second_with_comma_colons_equals() { 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 FOO=bar RUST_LOG=info,my_module=info,lib_crate::lib_mod=trace $env.FOO + $env.RUST_LOG
"#); ");
assert_eq!( assert_eq!(
actual.out, actual.out,
"barinfo,my_module=info,lib_crate::lib_mod=trace" "barinfo,my_module=info,lib_crate::lib_mod=trace"
@ -61,9 +60,9 @@ fn env_shorthand_multi_second_with_comma_colons_equals() {
#[test] #[test]
fn env_shorthand_multi_first_with_comma_colons_equals() { 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 RUST_LOG=info,my_module=info,lib_crate::lib_mod=trace FOO=bar $env.FOO + $env.RUST_LOG
"#); ");
assert_eq!( assert_eq!(
actual.out, actual.out,
"barinfo,my_module=info,lib_crate::lib_mod=trace" "barinfo,my_module=info,lib_crate::lib_mod=trace"
@ -72,15 +71,15 @@ fn env_shorthand_multi_first_with_comma_colons_equals() {
#[test] #[test]
fn env_shorthand_multi() { fn env_shorthand_multi() {
let actual = nu!(cwd: ".", r#" let actual = nu!("
FOO=bar BAR=baz $env.FOO + $env.BAR FOO=bar BAR=baz $env.FOO + $env.BAR
"#); ");
assert_eq!(actual.out, "barbaz"); assert_eq!(actual.out, "barbaz");
} }
#[test] #[test]
fn env_assignment() { fn env_assignment() {
let actual = nu!(cwd: ".", r#" let actual = nu!(r#"
$env.FOOBAR = "barbaz"; $env.FOOBAR $env.FOOBAR = "barbaz"; $env.FOOBAR
"#); "#);
assert_eq!(actual.out, "barbaz"); assert_eq!(actual.out, "barbaz");
@ -88,30 +87,30 @@ fn env_assignment() {
#[test] #[test]
fn mutate_env_file_pwd_env_var_fails() { 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")); assert!(actual.err.contains("automatic_env_var_set_manually"));
} }
#[test] #[test]
fn load_env_file_pwd_env_var_fails() { 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")); assert!(actual.err.contains("automatic_env_var_set_manually"));
} }
#[test] #[test]
fn load_env_pwd_env_var_fails() { 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")); assert!(actual.err.contains("automatic_env_var_set_manually"));
} }
#[test] #[test]
fn passes_with_env_env_var_to_external_process() { 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} with-env [FOO foo] {nu --testbin echo_env FOO}
"#); ");
assert_eq!(actual.out, "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, || { let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test(), r#" nu!(cwd: dirs.test(), "
nu --testbin echo_env FOO nu --testbin echo_env FOO
"#) ")
}); });
assert_eq!(actual.out, "foo"); assert_eq!(actual.out, "foo");
@ -169,8 +168,8 @@ fn hides_env_in_block() {
"do $b", "do $b",
]; ];
let actual = nu!(cwd: "tests/shell/environment", pipeline(&inp.join("; "))); let actual = nu!(&inp.join("; "));
let actual_repl = nu!(cwd: "tests/shell/environment", nu_repl_code(inp)); let actual_repl = nu!(nu_repl_code(inp));
assert!(actual.err.contains("column_not_found")); assert!(actual.err.contains("column_not_found"));
assert!(actual_repl.err.contains("column_not_found")); assert!(actual_repl.err.contains("column_not_found"));
@ -178,8 +177,8 @@ fn hides_env_in_block() {
#[test] #[test]
fn env_var_not_var() { fn env_var_not_var() {
let actual = nu!(cwd: ".", r#" let actual = nu!("
echo $CARGO echo $CARGO
"#); ");
assert!(actual.err.contains("use $env.CARGO instead of $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!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#" "
do {autoenv trust -q foo ; = null } do {autoenv trust -q foo ; = null }
foo foo
echo $env.testkey"# echo $env.testkey"
); );
assert_eq!(actual.out, "testvalue"); assert_eq!(actual.out, "testvalue");
//Assert testkey is gone when leaving foo //Assert testkey is gone when leaving foo
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#" "
do {autoenv trust -q foo; = null } ; do {autoenv trust -q foo; = null } ;
foo foo
.. ..
echo $env.testkey echo $env.testkey
"# "
); );
assert!(actual.err.contains("Unknown")); assert!(actual.err.contains("Unknown"));
//Assert testkey is present also when jumping over foo //Assert testkey is present also when jumping over foo
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#" "
do {autoenv trust -q foo; = null } ; do {autoenv trust -q foo; = null } ;
do {autoenv trust -q foo/bar; = null } ; do {autoenv trust -q foo/bar; = null } ;
foo/bar foo/bar
echo $env.testkey echo $env.testkey
echo $env.bar echo $env.bar
"# "
); );
assert_eq!(actual.out, "testvaluetrue"); assert_eq!(actual.out, "testvaluetrue");
//Assert bar removed after leaving bar //Assert bar removed after leaving bar
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"autoenv trust -q foo; "autoenv trust -q foo;
foo/bar foo/bar
../.. ../..
echo $env.bar"# echo $env.bar"
); );
assert!(actual.err.contains("Unknown")); 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 expected = "0.30.0";
let actual = Trusted::in_path(&dirs, || { let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test().join("crates"), r#" nu!(cwd: dirs.test().join("crates"), "
cd ../../autoenv_test_3 cd ../../autoenv_test_3
echo $env.nu-ver echo $env.nu-ver
"#) ")
}); });
assert_eq!(actual.out, expected); 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, || { 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 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 cd autoenv_test_9/nu_plugin_rb
echo $env.organization echo $env.organization
"#) ")
}); });
assert_eq!(actual.out, "nushell"); 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, || { 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 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 cd autoenv_test_10/nu_plugin_rb
echo $env.organization echo $env.organization
"#) ")
}); });
assert_eq!(actual.out, "Andrab"); assert_eq!(actual.out, "Andrab");
@ -385,16 +385,16 @@ fn local_config_should_not_be_added_when_running_scripts() {
), ),
FileWithContent( FileWithContent(
"script.nu", "script.nu",
r#"cd foo "cd foo
echo $env.organization"#, echo $env.organization",
), ),
]); ]);
let actual = Trusted::in_path(&dirs, || { 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 do { autoenv trust -q foo } # Silence autoenv trust message from output
nu script.nu nu script.nu
"#) ")
}); });
assert_eq!(actual.out, "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, || { 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 do { autoenv trust -q autoenv_test_11/nu_plugin_rb } # Silence autoenv trust message from output
cd autoenv_test_11 cd autoenv_test_11
cd nu_plugin_rb 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) 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 .. cd ..
echo $env.organization echo $env.organization
"#) ")
}); });
assert_eq!(actual.out, "nushell"); 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 //Assert testkey is not present before entering directory
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"autoenv trust -q foo; "autoenv trust -q foo;
echo $env.testkey"# echo $env.testkey"
); );
assert!(actual.err.contains("Unknown")); assert!(actual.err.contains("Unknown"));
//Assert testkey is present in foo //Assert testkey is present in foo
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"autoenv trust -q foo; cd foo "autoenv trust -q foo; cd foo
echo $env.testkey"# echo $env.testkey"
); );
assert_eq!(actual.out, "testvalue"); assert_eq!(actual.out, "testvalue");
//Assert testkey is present also in subdirectories //Assert testkey is present also in subdirectories
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"autoenv trust -q foo; cd foo "autoenv trust -q foo; cd foo
cd bar cd bar
echo $env.testkey"# echo $env.testkey"
); );
assert_eq!(actual.out, "testvalue"); assert_eq!(actual.out, "testvalue");
//Assert testkey is present also when jumping over foo //Assert testkey is present also when jumping over foo
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"autoenv trust -q foo; cd foo/bar "autoenv trust -q foo; cd foo/bar
echo $env.testkey"# echo $env.testkey"
); );
assert_eq!(actual.out, "testvalue"); assert_eq!(actual.out, "testvalue");
//Assert testkey removed after leaving foo //Assert testkey removed after leaving foo
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"autoenv trust -q foo; cd foo "autoenv trust -q foo; cd foo
cd .. cd ..
echo $env.testkey"# echo $env.testkey"
); );
assert!(actual.err.contains("Unknown")); 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 //Assert overwrite_me is not present before entering directory
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"autoenv trust -q foo; "autoenv trust -q foo;
echo $env.overwrite_me"# echo $env.overwrite_me"
); );
assert!(actual.err.contains("Unknown")); assert!(actual.err.contains("Unknown"));
//Assert overwrite_me is foo in foo //Assert overwrite_me is foo in foo
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"autoenv trust -q foo; cd foo "autoenv trust -q foo; cd foo
echo $env.overwrite_me"# echo $env.overwrite_me"
); );
assert_eq!(actual.out, "foo"); assert_eq!(actual.out, "foo");
//Assert overwrite_me is bar in bar //Assert overwrite_me is bar in bar
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"autoenv trust -q foo "autoenv trust -q foo
autoenv trust -q foo/bar autoenv trust -q foo/bar
cd foo cd foo
cd bar cd bar
echo $env.overwrite_me"# echo $env.overwrite_me"
); );
assert_eq!(actual.out, "bar"); assert_eq!(actual.out, "bar");
//Assert overwrite_me is present also when jumping over foo //Assert overwrite_me is present also when jumping over foo
let actual = nu!( let actual = nu!(
cwd: dirs.test(), 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 echo $env.overwrite_me
"# "
); );
assert_eq!(actual.out, "bar"); assert_eq!(actual.out, "bar");
//Assert overwrite_me removed after leaving bar //Assert overwrite_me removed after leaving bar
let actual = nu!( let actual = nu!(
cwd: dirs.test(), 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 bar
cd .. cd ..
echo $env.overwrite_me"# echo $env.overwrite_me"
); );
assert_eq!(actual.out, "foo"); assert_eq!(actual.out, "foo");
}); });

View File

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

View File

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