Fix: remove unnecessary r#"..."# (#8670) (#9764)

<!--
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 is related to **Tests: clean up unnecessary use of cwd,
pipeline(), etc.
[#8670](https://github.com/nushell/nushell/issues/8670)**

- Removed the `r#"..."#` raw string literal syntax, which is unnecessary
when there are no special characters that need quoting from the tests
that use the `nu!` macro.
- `cwd:` and `pipeline()` has not changed


# 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 -- -c "use std testing; testing run-tests --path
crates/nu-std"` 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:
Vikrant A P 2023-07-21 21:02:37 +05:30 committed by GitHub
parent cdc4fb1011
commit 75180d07de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 341 additions and 418 deletions

View File

@ -109,7 +109,7 @@ fn def_fails_with_invalid_name() {
let actual = nu!(r#"def 5gib = echo "test""#); let actual = nu!(r#"def 5gib = echo "test""#);
assert!(actual.err.contains(err_msg)); assert!(actual.err.contains(err_msg));
let actual = nu!(r#"def ^foo [] {}"#); let actual = nu!("def ^foo [] {}");
assert!(actual.err.contains(err_msg)); assert!(actual.err.contains(err_msg));
} }

View File

@ -136,17 +136,13 @@ fn capture_error_with_both_stdout_stderr_messages_not_hang_nushell() {
// check for stdout // check for stdout
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "do -c {bash test.sh} | complete | get stdout | str trim",
do -c {bash test.sh} | complete | get stdout | str trim
"#,
)); ));
assert_eq!(actual.out, expect_body); assert_eq!(actual.out, expect_body);
// check for stderr // check for stderr
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "do -c {bash test.sh} | complete | get stderr | str trim",
do -c {bash test.sh} | complete | get stderr | str trim
"#,
)); ));
assert_eq!(actual.out, expect_body); assert_eq!(actual.out, expect_body);
}, },

View File

@ -35,9 +35,7 @@ fn flatten_nested_tables_that_have_many_columns() {
#[test] #[test]
fn flatten_nested_tables() { fn flatten_nested_tables() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "echo [[Andrés, Nicolás, Robalino]] | flatten | get 1"
echo [[Andrés, Nicolás, Robalino]] | flatten | get 1
"#
)); ));
assert_eq!(actual.out, "Nicolás"); assert_eq!(actual.out, "Nicolás");

View File

@ -2,10 +2,10 @@ use nu_test_support::nu;
#[test] #[test]
fn for_doesnt_auto_print_in_each_iteration() { fn for_doesnt_auto_print_in_each_iteration() {
let actual = nu!(r#" let actual = nu!("
for i in 1..2 { for i in 1..2 {
echo 1 echo 1
}"#); }");
// Make sure we don't see any of these values in the output // Make sure we don't see any of these values in the output
// As we do not auto-print loops anymore // As we do not auto-print loops anymore
assert!(!actual.out.contains('1')); assert!(!actual.out.contains('1'));
@ -13,11 +13,11 @@ fn for_doesnt_auto_print_in_each_iteration() {
#[test] #[test]
fn for_break_on_external_failed() { fn for_break_on_external_failed() {
let actual = nu!(r#" let actual = nu!("
for i in 1..2 { for i in 1..2 {
print 1; print 1;
nu --testbin fail nu --testbin fail
}"#); }");
// Note: nu! macro auto replace "\n" and "\r\n" with "" // Note: nu! macro auto replace "\n" and "\r\n" with ""
// so our output will be `1` // so our output will be `1`
assert_eq!(actual.out, "1"); assert_eq!(actual.out, "1");
@ -25,18 +25,18 @@ fn for_break_on_external_failed() {
#[test] #[test]
fn failed_for_should_break_running() { fn failed_for_should_break_running() {
let actual = nu!(r#" let actual = nu!("
for i in 1..2 { for i in 1..2 {
nu --testbin fail nu --testbin fail
} }
print 3"#); print 3");
assert!(!actual.out.contains('3')); assert!(!actual.out.contains('3'));
let actual = nu!(r#" let actual = nu!("
let x = [1 2] let x = [1 2]
for i in $x { for i in $x {
nu --testbin fail nu --testbin fail
} }
print 3"#); print 3");
assert!(!actual.out.contains('3')); assert!(!actual.out.contains('3'));
} }

View File

@ -66,12 +66,12 @@ fn format_filesize_works() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| format filesize KB size | format filesize KB size
| get size | get size
| first | first
"# "
)); ));
assert_eq!(actual.out, "0.0 KB"); assert_eq!(actual.out, "0.0 KB");

View File

@ -189,7 +189,7 @@ fn quoted_column_access() {
#[test] #[test]
fn get_does_not_delve_too_deep_in_nested_lists() { fn get_does_not_delve_too_deep_in_nested_lists() {
let actual = nu!(r#"[[{foo: bar}]] | get foo"#); let actual = nu!("[[{foo: bar}]] | get foo");
assert!(actual.err.contains("cannot find column")); assert!(actual.err.contains("cannot find column"));
} }

View File

@ -86,10 +86,10 @@ fn errors_if_column_not_found() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open los_tres_caballeros.csv open los_tres_caballeros.csv
| group-by ttype | group-by ttype
"# "
)); ));
assert!(actual.err.contains("did you mean 'type'"),); assert!(actual.err.contains("did you mean 'type'"),);

View File

@ -4,12 +4,12 @@ use nu_test_support::{nu, pipeline};
fn headers_uses_first_row_as_header() { fn headers_uses_first_row_as_header() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample_headers.xlsx open sample_headers.xlsx
| get Sheet1 | get Sheet1
| headers | headers
| get header0 | get header0
| to json --raw"# | to json --raw"
)); ));
assert_eq!(actual.out, r#"["r1c0","r2c0"]"#) assert_eq!(actual.out, r#"["r1c0","r2c0"]"#)
@ -19,12 +19,12 @@ fn headers_uses_first_row_as_header() {
fn headers_adds_missing_column_name() { fn headers_adds_missing_column_name() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample_headers.xlsx open sample_headers.xlsx
| get Sheet1 | get Sheet1
| headers | headers
| get column1 | get column1
| to json --raw"# | to json --raw"
)); ));
assert_eq!(actual.out, r#"["r1c1","r2c1"]"#) assert_eq!(actual.out, r#"["r1c1","r2c1"]"#)
@ -33,11 +33,11 @@ fn headers_adds_missing_column_name() {
#[test] #[test]
fn headers_handles_missing_values() { fn headers_handles_missing_values() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[{x: a, y: b}, {x: 1, y: 2}, {x: 1, z: 3}] [{x: a, y: b}, {x: 1, y: 2}, {x: 1, z: 3}]
| headers | headers
| to nuon --raw | to nuon --raw
"# "
)); ));
assert_eq!(actual.out, "[{a: 1, b: 2}, {a: 1}]") assert_eq!(actual.out, "[{a: 1, b: 2}, {a: 1}]")
@ -46,9 +46,9 @@ fn headers_handles_missing_values() {
#[test] #[test]
fn headers_invalid_column_type_empty_record() { fn headers_invalid_column_type_empty_record() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[[a b]; [{}, 2], [3,4] ] [[a b]; [{}, 2], [3,4] ]
| headers"# | headers"
)); ));
assert!(actual assert!(actual
@ -59,9 +59,9 @@ fn headers_invalid_column_type_empty_record() {
#[test] #[test]
fn headers_invalid_column_type_record() { fn headers_invalid_column_type_record() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[[a b]; [1 (scope aliases)] [2 2]] [[a b]; [1 (scope aliases)] [2 2]]
| headers"# | headers"
)); ));
assert!(actual assert!(actual
@ -72,9 +72,9 @@ fn headers_invalid_column_type_record() {
#[test] #[test]
fn headers_invalid_column_type_array() { fn headers_invalid_column_type_array() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[[a b]; [[f,g], 2], [3,4] ] [[a b]; [[f,g], 2], [3,4] ]
| headers"# | headers"
)); ));
assert!(actual assert!(actual
@ -85,9 +85,9 @@ fn headers_invalid_column_type_array() {
#[test] #[test]
fn headers_invalid_column_type_range() { fn headers_invalid_column_type_range() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[[a b]; [(1..5), 2], [3,4] ] [[a b]; [(1..5), 2], [3,4] ]
| headers"# | headers"
)); ));
assert!(actual assert!(actual
@ -98,9 +98,9 @@ fn headers_invalid_column_type_range() {
#[test] #[test]
fn headers_invalid_column_type_duration() { fn headers_invalid_column_type_duration() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[[a b]; [((date now) - (date now)), 2], [3,4] ] [[a b]; [((date now) - (date now)), 2], [3,4] ]
| headers"# | headers"
)); ));
assert!(actual assert!(actual

View File

@ -105,13 +105,13 @@ fn help() {
#[test] #[test]
fn count() { fn count() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
echo [[bit]; [1] [0] [0] [0] [0] [0] [0] [1] [1]] echo [[bit]; [1] [0] [0] [0] [0] [0] [0] [1] [1]]
| histogram bit --percentage-type relative | histogram bit --percentage-type relative
| sort-by count | sort-by count
| reject frequency | reject frequency
| to json | to json
"# "
)); ));
let bit_json = r#"[ { "bit": 1, "count": 3, "quantile": 0.5, "percentage": "50.00%" }, { "bit": 0, "count": 6, "quantile": 1, "percentage": "100.00%" }]"#; let bit_json = r#"[ { "bit": 1, "count": 3, "quantile": 0.5, "percentage": "50.00%" }, { "bit": 0, "count": 6, "quantile": 1, "percentage": "100.00%" }]"#;
@ -122,13 +122,13 @@ fn count() {
#[test] #[test]
fn count_with_normalize_percentage() { fn count_with_normalize_percentage() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
echo [[bit]; [1] [0] [0] [0] [0] [0] [0] [1]] echo [[bit]; [1] [0] [0] [0] [0] [0] [0] [1]]
| histogram bit --percentage-type normalize | histogram bit --percentage-type normalize
| sort-by count | sort-by count
| reject frequency | reject frequency
| to json | to json
"# "
)); ));
let bit_json = r#"[ { "bit": 1, "count": 2, "quantile": 0.25, "percentage": "25.00%" }, { "bit": 0, "count": 6, "quantile": 0.75, "percentage": "75.00%" }]"#; let bit_json = r#"[ { "bit": 1, "count": 2, "quantile": 0.25, "percentage": "25.00%" }, { "bit": 0, "count": 6, "quantile": 0.75, "percentage": "75.00%" }]"#;

View File

@ -16,7 +16,7 @@ fn insert_the_column() {
#[test] #[test]
fn doesnt_convert_record_to_table() { fn doesnt_convert_record_to_table() {
let actual = nu!(r#"{a:1} | insert b 2 | to nuon"#); let actual = nu!("{a:1} | insert b 2 | to nuon");
assert_eq!(actual.out, "{a: 1, b: 2}"); assert_eq!(actual.out, "{a: 1, b: 2}");
} }
@ -38,36 +38,28 @@ fn insert_the_column_conflict() {
#[test] #[test]
fn insert_into_list() { fn insert_into_list() {
let actual = nu!(r#" let actual = nu!("[1, 2, 3] | insert 1 abc | to json -r");
[1, 2, 3] | insert 1 abc | to json -r
"#);
assert_eq!(actual.out, r#"[1,"abc",2,3]"#); assert_eq!(actual.out, r#"[1,"abc",2,3]"#);
} }
#[test] #[test]
fn insert_into_list_begin() { fn insert_into_list_begin() {
let actual = nu!(r#" let actual = nu!("[1, 2, 3] | insert 0 abc | to json -r");
[1, 2, 3] | insert 0 abc | to json -r
"#);
assert_eq!(actual.out, r#"["abc",1,2,3]"#); assert_eq!(actual.out, r#"["abc",1,2,3]"#);
} }
#[test] #[test]
fn insert_into_list_end() { fn insert_into_list_end() {
let actual = nu!(r#" let actual = nu!("[1, 2, 3] | insert 3 abc | to json -r");
[1, 2, 3] | insert 3 abc | to json -r
"#);
assert_eq!(actual.out, r#"[1,2,3,"abc"]"#); assert_eq!(actual.out, r#"[1,2,3,"abc"]"#);
} }
#[test] #[test]
fn insert_past_end_list() { fn insert_past_end_list() {
let actual = nu!(r#" let actual = nu!("[1, 2, 3] | insert 5 abc | to json -r");
[1, 2, 3] | insert 5 abc | to json -r
"#);
assert_eq!(actual.out, r#"[1,2,3,null,null,"abc"]"#); assert_eq!(actual.out, r#"[1,2,3,null,null,"abc"]"#);
} }
@ -75,7 +67,7 @@ fn insert_past_end_list() {
#[test] #[test]
fn insert_uses_enumerate_index() { fn insert_uses_enumerate_index() {
let actual = nu!( let actual = nu!(
r#"[[a]; [7] [6]] | enumerate | insert b {|el| $el.index + 1 + $el.item.a } | flatten | to nuon"# "[[a]; [7] [6]] | enumerate | insert b {|el| $el.index + 1 + $el.item.a } | flatten | to nuon"
); );
assert_eq!(actual.out, "[[index, a, b]; [0, 7, 8], [1, 6, 8]]"); assert_eq!(actual.out, "[[index, a, b]; [0, 7, 8], [1, 6, 8]]");

View File

@ -2,18 +2,14 @@ use nu_test_support::{nu, pipeline};
#[test] #[test]
fn into_filesize_int() { fn into_filesize_int() {
let actual = nu!(r#" let actual = nu!("1 | into filesize");
1 | into filesize
"#);
assert!(actual.out.contains("1 B")); assert!(actual.out.contains("1 B"));
} }
#[test] #[test]
fn into_filesize_decimal() { fn into_filesize_decimal() {
let actual = nu!(r#" let actual = nu!("1.2 | into filesize");
1.2 | into filesize
"#);
assert!(actual.out.contains("1 B")); assert!(actual.out.contains("1 B"));
} }
@ -54,18 +50,14 @@ fn into_filesize_str_many_newlines() {
#[test] #[test]
fn into_filesize_filesize() { fn into_filesize_filesize() {
let actual = nu!(r#" let actual = nu!("3kib | into filesize");
3kib | into filesize
"#);
assert!(actual.out.contains("3.0 KiB")); assert!(actual.out.contains("3.0 KiB"));
} }
#[test] #[test]
fn into_filesize_negative_filesize() { fn into_filesize_negative_filesize() {
let actual = nu!(r#" let actual = nu!("-3kib | into filesize");
-3kib | into filesize
"#);
assert!(actual.out.contains("-3.0 KiB")); assert!(actual.out.contains("-3.0 KiB"));
} }

View File

@ -5,36 +5,28 @@ use nu_test_support::nu;
#[test] #[test]
fn into_int_filesize() { fn into_int_filesize() {
let actual = nu!(r#" let actual = nu!("echo 1kb | into int | each { |it| $it / 1000 }");
echo 1kb | into int | each { |it| $it / 1000 }
"#);
assert!(actual.out.contains('1')); assert!(actual.out.contains('1'));
} }
#[test] #[test]
fn into_int_filesize2() { fn into_int_filesize2() {
let actual = nu!(r#" let actual = nu!("echo 1kib | into int | each { |it| $it / 1024 }");
echo 1kib | into int | each { |it| $it / 1024 }
"#);
assert!(actual.out.contains('1')); assert!(actual.out.contains('1'));
} }
#[test] #[test]
fn into_int_int() { fn into_int_int() {
let actual = nu!(r#" let actual = nu!("echo 1024 | into int | each { |it| $it / 1024 }");
echo 1024 | into int | each { |it| $it / 1024 }
"#);
assert!(actual.out.contains('1')); assert!(actual.out.contains('1'));
} }
#[test] #[test]
fn into_int_binary() { fn into_int_binary() {
let actual = nu!(r#" let actual = nu!("echo 0x[01010101] | into int");
echo 0x[01010101] | into int
"#);
assert!(actual.out.contains("16843009")); assert!(actual.out.contains("16843009"));
} }

View File

@ -23,12 +23,12 @@ fn lines() {
fn lines_proper_buffering() { fn lines_proper_buffering() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open lines_test.txt -r open lines_test.txt -r
| lines | lines
| str length | str length
| to json -r | to json -r
"# "
)); ));
assert_eq!(actual.out, "[8193,3]"); assert_eq!(actual.out, "[8193,3]");
@ -38,12 +38,12 @@ fn lines_proper_buffering() {
fn lines_multi_value_split() { fn lines_multi_value_split() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample-simple.json open sample-simple.json
| get first second | get first second
| lines | lines
| length | length
"# "
)); ));
assert_eq!(actual.out, "6"); assert_eq!(actual.out, "6");

View File

@ -2,7 +2,7 @@ use nu_test_support::nu;
#[test] #[test]
fn loop_doesnt_auto_print_in_each_iteration() { fn loop_doesnt_auto_print_in_each_iteration() {
let actual = nu!(r#" let actual = nu!("
mut total = 0; mut total = 0;
loop { loop {
if $total == 3 { if $total == 3 {
@ -11,7 +11,7 @@ fn loop_doesnt_auto_print_in_each_iteration() {
$total += 1; $total += 1;
} }
echo 1 echo 1
}"#); }");
// Make sure we don't see any of these values in the output // Make sure we don't see any of these values in the output
// As we do not auto-print loops anymore // As we do not auto-print loops anymore
assert!(!actual.out.contains('1')); assert!(!actual.out.contains('1'));
@ -19,7 +19,7 @@ fn loop_doesnt_auto_print_in_each_iteration() {
#[test] #[test]
fn loop_break_on_external_failed() { fn loop_break_on_external_failed() {
let actual = nu!(r#" let actual = nu!("
mut total = 0; mut total = 0;
loop { loop {
if $total == 3 { if $total == 3 {
@ -29,7 +29,7 @@ fn loop_break_on_external_failed() {
} }
print 1; print 1;
nu --testbin fail; nu --testbin fail;
}"#); }");
// Note: nu! macro auto replace "\n" and "\r\n" with "" // Note: nu! macro auto replace "\n" and "\r\n" with ""
// so our output will be `1`. // so our output will be `1`.
assert_eq!(actual.out, "1"); assert_eq!(actual.out, "1");
@ -37,7 +37,7 @@ fn loop_break_on_external_failed() {
#[test] #[test]
fn failed_loop_should_break_running() { fn failed_loop_should_break_running() {
let actual = nu!(r#" let actual = nu!("
mut total = 0; mut total = 0;
loop { loop {
if $total == 3 { if $total == 3 {
@ -47,6 +47,6 @@ fn failed_loop_should_break_running() {
} }
nu --testbin fail; nu --testbin fail;
} }
print 3"#); print 3");
assert!(!actual.out.contains('3')); assert!(!actual.out.contains('3'));
} }

View File

@ -13,10 +13,10 @@ fn lists_regular_files() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| length | length
"# "
)); ));
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
@ -35,10 +35,10 @@ fn lists_regular_files_using_asterisk_wildcard() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls *.txt ls *.txt
| length | length
"# "
)); ));
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
@ -57,10 +57,10 @@ fn lists_regular_files_using_question_mark_wildcard() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls *.??.txt ls *.??.txt
| length | length
"# "
)); ));
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
@ -82,11 +82,11 @@ fn lists_all_files_in_directories_from_stream() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
echo dir_a dir_b echo dir_a dir_b
| each { |it| ls $it } | each { |it| ls $it }
| flatten | length | flatten | length
"# "
)); ));
assert_eq!(actual.out, "4"); assert_eq!(actual.out, "4");
@ -100,10 +100,10 @@ fn does_not_fail_if_glob_matches_empty_directory() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls dir_a ls dir_a
| length | length
"# "
)); ));
assert_eq!(actual.out, "0"); assert_eq!(actual.out, "0");
@ -138,9 +138,9 @@ fn list_files_from_two_parents_up_using_multiple_dots() {
let actual = nu!( let actual = nu!(
cwd: dirs.test().join("foo/bar"), cwd: dirs.test().join("foo/bar"),
r#" "
ls ... | length ls ... | length
"# "
); );
assert_eq!(actual.out, "5"); assert_eq!(actual.out, "5");
@ -160,10 +160,10 @@ fn lists_hidden_file_when_explicitly_specified() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls .testdotfile ls .testdotfile
| length | length
"# "
)); ));
assert_eq!(actual.out, "1"); assert_eq!(actual.out, "1");
@ -194,10 +194,10 @@ fn lists_all_hidden_files_when_glob_contains_dot() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls **/.* ls **/.*
| length | length
"# "
)); ));
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
@ -231,10 +231,10 @@ fn lists_all_hidden_files_when_glob_does_not_contain_dot() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls **/* ls **/*
| length | length
"# "
)); ));
assert_eq!(actual.out, "5"); assert_eq!(actual.out, "5");
@ -255,10 +255,10 @@ fn glob_with_hidden_directory() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls **/* ls **/*
| length | length
"# "
)); ));
assert_eq!(actual.out, ""); assert_eq!(actual.out, "");
@ -267,10 +267,10 @@ fn glob_with_hidden_directory() {
// will list files if provide `-a` flag. // will list files if provide `-a` flag.
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls -a **/* ls -a **/*
| length | length
"# "
)); ));
assert_eq!(actual.out, "4"); assert_eq!(actual.out, "4");
@ -287,16 +287,16 @@ fn fails_with_ls_to_dir_without_permission() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
chmod 000 dir_a; ls dir_a chmod 000 dir_a; ls dir_a
"# "
)); ));
let check_not_root = nu!( let check_not_root = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
id -u id -u
"# "
)); ));
assert!( assert!(
@ -321,10 +321,10 @@ fn lists_files_including_starting_with_dot() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls -a ls -a
| length | length
"# "
)); ));
assert_eq!(actual.out, "5"); assert_eq!(actual.out, "5");
@ -426,12 +426,12 @@ fn lists_with_directory_flag_without_argument() {
// Test if there are some files in the current directory // Test if there are some files in the current directory
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
cd dir_files; cd dir_files;
ls --directory ls --directory
| get name | get name
| to text | to text
"# "
)); ));
let expected = "."; let expected = ".";
assert_eq!( assert_eq!(
@ -441,12 +441,12 @@ fn lists_with_directory_flag_without_argument() {
// Test if there is no file in the current directory // Test if there is no file in the current directory
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
cd dir_empty; cd dir_empty;
ls -D ls -D
| get name | get name
| to text | to text
"# "
)); ));
let expected = "."; let expected = ".";
assert_eq!( assert_eq!(
@ -497,7 +497,7 @@ fn can_list_system_folder() {
let ls_with_filter = nu!( let ls_with_filter = nu!(
cwd: "C:\\Windows\\System32", pipeline( cwd: "C:\\Windows\\System32", pipeline(
r#"ls | where size > 10mb"# "ls | where size > 10mb"
)); ));
assert_eq!(ls_with_filter.err, ""); assert_eq!(ls_with_filter.err, "");
} }
@ -547,9 +547,9 @@ fn list_ignores_ansi() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls | find .txt | each {|| ls $in.name } ls | find .txt | each {|| ls $in.name }
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());

View File

@ -18,7 +18,7 @@ fn match_for_range_unmatched() {
#[test] #[test]
fn match_for_record() { fn match_for_record() {
let actual = nu!(r#"match {a: 11} { {a: $b} => { print $b }}"#); let actual = nu!("match {a: 11} { {a: $b} => { print $b }}");
// Make sure we don't see any of these values in the output // Make sure we don't see any of these values in the output
// As we do not auto-print loops anymore // As we do not auto-print loops anymore
assert_eq!(actual.out, "11"); assert_eq!(actual.out, "11");
@ -26,7 +26,7 @@ fn match_for_record() {
#[test] #[test]
fn match_for_record_shorthand() { fn match_for_record_shorthand() {
let actual = nu!(r#"match {a: 12} { {$a} => { print $a }}"#); let actual = nu!("match {a: 12} { {$a} => { print $a }}");
// Make sure we don't see any of these values in the output // Make sure we don't see any of these values in the output
// As we do not auto-print loops anymore // As we do not auto-print loops anymore
assert_eq!(actual.out, "12"); assert_eq!(actual.out, "12");
@ -164,7 +164,7 @@ fn match_or_pattern_overlap_2() {
#[test] #[test]
fn match_doesnt_overwrite_variable() { fn match_doesnt_overwrite_variable() {
let actual = nu!(r#"let b = 100; match 55 { $b => {} }; print $b"#); let actual = nu!("let b = 100; match 55 { $b => {} }; print $b");
// Make sure we don't see any of these values in the output // Make sure we don't see any of these values in the output
// As we do not auto-print loops anymore // As we do not auto-print loops anymore
assert_eq!(actual.out, "100"); assert_eq!(actual.out, "100");

View File

@ -44,9 +44,9 @@ fn row() {
#[test] #[test]
fn single_record_no_overwrite() { fn single_record_no_overwrite() {
assert_eq!( assert_eq!(
nu!(r#" nu!("
{a: 1, b: 5} | merge {c: 2} | to nuon {a: 1, b: 5} | merge {c: 2} | to nuon
"#) ")
.out, .out,
"{a: 1, b: 5, c: 2}" "{a: 1, b: 5, c: 2}"
); );
@ -55,9 +55,9 @@ fn single_record_no_overwrite() {
#[test] #[test]
fn single_record_overwrite() { fn single_record_overwrite() {
assert_eq!( assert_eq!(
nu!(r#" nu!("
{a: 1, b: 2} | merge {a: 2} | to nuon {a: 1, b: 2} | merge {a: 2} | to nuon
"#) ")
.out, .out,
"{a: 2, b: 2}" "{a: 2, b: 2}"
); );
@ -66,9 +66,9 @@ fn single_record_overwrite() {
#[test] #[test]
fn single_row_table_overwrite() { fn single_row_table_overwrite() {
assert_eq!( assert_eq!(
nu!(r#" nu!("
[[a b]; [1 4]] | merge [[a b]; [2 4]] | to nuon [[a b]; [1 4]] | merge [[a b]; [2 4]] | to nuon
"#) ")
.out, .out,
"[[a, b]; [2, 4]]" "[[a, b]; [2, 4]]"
); );
@ -77,9 +77,9 @@ fn single_row_table_overwrite() {
#[test] #[test]
fn single_row_table_no_overwrite() { fn single_row_table_no_overwrite() {
assert_eq!( assert_eq!(
nu!(r#" nu!("
[[a b]; [1 4]] | merge [[c d]; [2 4]] | to nuon [[a b]; [1 4]] | merge [[c d]; [2 4]] | to nuon
"#) ")
.out, .out,
"[[a, b, c, d]; [1, 4, 2, 4]]" "[[a, b, c, d]; [1, 4, 2, 4]]"
); );
@ -88,9 +88,9 @@ fn single_row_table_no_overwrite() {
#[test] #[test]
fn multi_row_table_no_overwrite() { fn multi_row_table_no_overwrite() {
assert_eq!( assert_eq!(
nu!(r#" nu!("
[[a b]; [1 4] [8 9] [9 9]] | merge [[c d]; [2 4]] | to nuon [[a b]; [1 4] [8 9] [9 9]] | merge [[c d]; [2 4]] | to nuon
"#) ")
.out, .out,
"[{a: 1, b: 4, c: 2, d: 4}, {a: 8, b: 9}, {a: 9, b: 9}]" "[{a: 1, b: 4, c: 2, d: 4}, {a: 8, b: 9}, {a: 9, b: 9}]"
); );
@ -99,9 +99,9 @@ fn multi_row_table_no_overwrite() {
#[test] #[test]
fn multi_row_table_overwrite() { fn multi_row_table_overwrite() {
assert_eq!( assert_eq!(
nu!(r#" nu!("
[[a b]; [1 4] [8 9] [9 9]] | merge [[a b]; [7 7]] | to nuon [[a b]; [1 4] [8 9] [9 9]] | merge [[a b]; [7 7]] | to nuon
"#) ")
.out, .out,
"[[a, b]; [7, 7], [8, 9], [9, 9]]" "[[a, b]; [7, 7], [8, 9], [9, 9]]"
); );

View File

@ -68,9 +68,7 @@ fn print_created_paths() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
pipeline( pipeline(
r#" "mkdir -v dir_1 dir_2 dir_3"
mkdir -v dir_1 dir_2 dir_3
"#
)); ));
assert!(files_exist_at( assert!(files_exist_at(

View File

@ -2,18 +2,14 @@ use nu_test_support::nu;
#[test] #[test]
fn mut_variable() { fn mut_variable() {
let actual = nu!(r#" let actual = nu!("mut x = 3; $x = $x + 1; $x");
mut x = 3; $x = $x + 1; $x
"#);
assert_eq!(actual.out, "4"); assert_eq!(actual.out, "4");
} }
#[test] #[test]
fn mut_name_builtin_var() { fn mut_name_builtin_var() {
let actual = nu!(r#" let actual = nu!("mut in = 3");
mut in = 3
"#);
assert!(actual assert!(actual
.err .err
@ -22,9 +18,7 @@ fn mut_name_builtin_var() {
#[test] #[test]
fn mut_name_builtin_var_with_dollar() { fn mut_name_builtin_var_with_dollar() {
let actual = nu!(r#" let actual = nu!("mut $env = 3");
mut $env = 3
"#);
assert!(actual assert!(actual
.err .err
@ -33,99 +27,77 @@ fn mut_name_builtin_var_with_dollar() {
#[test] #[test]
fn mut_variable_in_loop() { fn mut_variable_in_loop() {
let actual = nu!(r#" let actual = nu!("mut x = 1; for i in 1..10 { $x = $x + $i}; $x");
mut x = 1; for i in 1..10 { $x = $x + $i}; $x
"#);
assert_eq!(actual.out, "56"); assert_eq!(actual.out, "56");
} }
#[test] #[test]
fn capture_of_mutable_var() { fn capture_of_mutable_var() {
let actual = nu!(r#" let actual = nu!("mut x = 123; {|| $x }");
mut x = 123; {|| $x }
"#);
assert!(actual.err.contains("capture of mutable variable")); assert!(actual.err.contains("capture of mutable variable"));
} }
#[test] #[test]
fn mut_add_assign() { fn mut_add_assign() {
let actual = nu!(r#" let actual = nu!("mut y = 3; $y += 2; $y");
mut y = 3; $y += 2; $y
"#);
assert_eq!(actual.out, "5"); assert_eq!(actual.out, "5");
} }
#[test] #[test]
fn mut_minus_assign() { fn mut_minus_assign() {
let actual = nu!(r#" let actual = nu!("mut y = 3; $y -= 2; $y");
mut y = 3; $y -= 2; $y
"#);
assert_eq!(actual.out, "1"); assert_eq!(actual.out, "1");
} }
#[test] #[test]
fn mut_multiply_assign() { fn mut_multiply_assign() {
let actual = nu!(r#" let actual = nu!("mut y = 3; $y *= 2; $y");
mut y = 3; $y *= 2; $y
"#);
assert_eq!(actual.out, "6"); assert_eq!(actual.out, "6");
} }
#[test] #[test]
fn mut_divide_assign() { fn mut_divide_assign() {
let actual = nu!(r#" let actual = nu!("mut y = 8; $y /= 2; $y");
mut y = 8; $y /= 2; $y
"#);
assert_eq!(actual.out, "4"); assert_eq!(actual.out, "4");
} }
#[test] #[test]
fn mut_path_insert() { fn mut_path_insert() {
let actual = nu!(r#" let actual = nu!("mut y = {abc: 123}; $y.abc = 456; $y.abc");
mut y = {abc: 123}; $y.abc = 456; $y.abc
"#);
assert_eq!(actual.out, "456"); assert_eq!(actual.out, "456");
} }
#[test] #[test]
fn mut_path_insert_list() { fn mut_path_insert_list() {
let actual = nu!(r#" let actual = nu!("mut a = [0 1 2]; $a.3 = 3; $a | to nuon");
mut a = [0 1 2]; $a.3 = 3; $a | to nuon
"#);
assert_eq!(actual.out, "[0, 1, 2, 3]"); assert_eq!(actual.out, "[0, 1, 2, 3]");
} }
#[test] #[test]
fn mut_path_upsert() { fn mut_path_upsert() {
let actual = nu!(r#" let actual = nu!("mut a = {b:[{c:1}]}; $a.b.0.d = 11; $a.b.0.d");
mut a = {b:[{c:1}]}; $a.b.0.d = 11; $a.b.0.d
"#);
assert_eq!(actual.out, "11"); assert_eq!(actual.out, "11");
} }
#[test] #[test]
fn mut_path_upsert_list() { fn mut_path_upsert_list() {
let actual = nu!(r#" let actual = nu!("mut a = [[[3] 2] 1]; $a.0.0.1 = 0; $a.0.2 = 0; $a.2 = 0; $a | to nuon");
mut a = [[[3] 2] 1]; $a.0.0.1 = 0; $a.0.2 = 0; $a.2 = 0; $a | to nuon
"#);
assert_eq!(actual.out, "[[[3, 0], 2, 0], 1, 0]"); assert_eq!(actual.out, "[[[3, 0], 2, 0], 1, 0]");
} }
#[test] #[test]
fn mut_path_operator_assign() { fn mut_path_operator_assign() {
let actual = nu!(r#" let actual = nu!("mut a = {b:1}; $a.b += 3; $a.b -= 2; $a.b *= 10; $a.b /= 4; $a.b");
mut a = {b:1}; $a.b += 3; $a.b -= 2; $a.b *= 10; $a.b /= 4; $a.b
"#);
assert_eq!(actual.out, "5"); assert_eq!(actual.out, "5");
} }

View File

@ -18,9 +18,9 @@ fn parse_script_success() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check script.nu nu-check script.nu
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
@ -43,9 +43,9 @@ fn parse_script_with_wrong_type() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check -d --as-module script.nu nu-check -d --as-module script.nu
"# "
)); ));
assert!(actual.err.contains("Failed to parse content")); assert!(actual.err.contains("Failed to parse content"));
@ -67,9 +67,9 @@ fn parse_script_failure() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check -d script.nu nu-check -d script.nu
"# "
)); ));
assert!(actual.err.contains("Unexpected end of code")); assert!(actual.err.contains("Unexpected end of code"));
@ -96,9 +96,9 @@ fn parse_module_success() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check --as-module foo.nu nu-check --as-module foo.nu
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
@ -125,9 +125,9 @@ fn parse_module_with_wrong_type() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check -d foo.nu nu-check -d foo.nu
"# "
)); ));
assert!(actual.err.contains("Failed to parse content")); assert!(actual.err.contains("Failed to parse content"));
@ -153,9 +153,9 @@ fn parse_module_failure() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check -d --as-module foo.nu nu-check -d --as-module foo.nu
"# "
)); ));
assert!(actual.err.contains("Unexpected end of code")); assert!(actual.err.contains("Unexpected end of code"));
@ -167,9 +167,9 @@ fn file_not_exist() {
Playground::setup("nu_check_test_7", |dirs, _sandbox| { Playground::setup("nu_check_test_7", |dirs, _sandbox| {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check --as-module foo.nu nu-check --as-module foo.nu
"# "
)); ));
assert!(actual.err.contains("file not found")); assert!(actual.err.contains("file not found"));
@ -196,9 +196,9 @@ fn parse_unsupported_file() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check --as-module foo.txt nu-check --as-module foo.txt
"# "
)); ));
assert!(actual assert!(actual
@ -211,9 +211,9 @@ fn parse_dir_failure() {
Playground::setup("nu_check_test_9", |dirs, _sandbox| { Playground::setup("nu_check_test_9", |dirs, _sandbox| {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check --as-module ~ nu-check --as-module ~
"# "
)); ));
assert!(actual assert!(actual
@ -236,9 +236,9 @@ fn parse_module_success_2() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check --as-module foo.nu nu-check --as-module foo.nu
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
@ -261,9 +261,9 @@ fn parse_script_success_with_raw_stream() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open script.nu | nu-check open script.nu | nu-check
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
@ -290,9 +290,9 @@ fn parse_module_success_with_raw_stream() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open foo.nu | nu-check --as-module open foo.nu | nu-check --as-module
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
@ -348,9 +348,9 @@ fn parse_module_success_with_internal_stream() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open foo.nu | lines | nu-check --as-module open foo.nu | lines | nu-check --as-module
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
@ -397,9 +397,9 @@ fn parse_script_success_with_complex_internal_stream() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open grep.nu | lines | nu-check open grep.nu | lines | nu-check
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
@ -446,9 +446,9 @@ fn parse_script_failure_with_complex_internal_stream() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open grep.nu | lines | nu-check open grep.nu | lines | nu-check
"# "
)); ));
assert_eq!(actual.out, "false".to_string()); assert_eq!(actual.out, "false".to_string());
@ -495,9 +495,9 @@ fn parse_script_success_with_complex_external_stream() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open grep.nu | nu-check open grep.nu | nu-check
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
@ -544,9 +544,9 @@ fn parse_module_success_with_complex_external_stream() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open grep.nu | nu-check -d --as-module open grep.nu | nu-check -d --as-module
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
@ -593,9 +593,9 @@ fn parse_with_flag_all_success_for_complex_external_stream() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open grep.nu | nu-check -ad open grep.nu | nu-check -ad
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
@ -642,9 +642,9 @@ fn parse_with_flag_all_failure_for_complex_external_stream() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open grep.nu | nu-check -ad open grep.nu | nu-check -ad
"# "
)); ));
assert!(actual.err.contains("syntax error")); assert!(actual.err.contains("syntax error"));
@ -691,9 +691,9 @@ fn parse_with_flag_all_failure_for_complex_list_stream() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open grep.nu | lines | nu-check -ad open grep.nu | lines | nu-check -ad
"# "
)); ));
assert!(actual.err.contains("syntax error")); assert!(actual.err.contains("syntax error"));
@ -716,9 +716,9 @@ fn parse_failure_due_conflicted_flags() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check -a --as-module script.nu nu-check -a --as-module script.nu
"# "
)); ));
assert!(actual assert!(actual
@ -755,9 +755,9 @@ fn parse_script_with_nested_scripts_success() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
nu-check lol/lol.nu nu-check lol/lol.nu
"# "
)); ));
assert_eq!(actual.out, "true"); assert_eq!(actual.out, "true");
@ -784,10 +784,10 @@ fn nu_check_respects_file_pwd() {
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.RETURN $env.RETURN
"# "
)); ));
assert_eq!(actual.out, "true"); assert_eq!(actual.out, "true");

View File

@ -113,11 +113,11 @@ fn parses_more_bson_complexity() {
fn parses_sqlite() { fn parses_sqlite() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample.db open sample.db
| columns | columns
| length | length
"# "
)); ));
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
@ -128,11 +128,11 @@ fn parses_sqlite() {
fn parses_sqlite_get_column_name() { fn parses_sqlite_get_column_name() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample.db open sample.db
| get strings | get strings
| get x.0 | get x.0
"# "
)); ));
assert_eq!(actual.out, "hello"); assert_eq!(actual.out, "hello");
@ -152,11 +152,11 @@ fn parses_toml() {
fn parses_tsv() { fn parses_tsv() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open caco3_plastics.tsv open caco3_plastics.tsv
| first | first
| get origin | get origin
"# "
)); ));
assert_eq!(actual.out, "SPAIN") assert_eq!(actual.out, "SPAIN")
@ -166,10 +166,10 @@ fn parses_tsv() {
fn parses_json() { fn parses_json() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sgml_description.json open sgml_description.json
| get glossary.GlossDiv.GlossList.GlossEntry.GlossSee | get glossary.GlossDiv.GlossList.GlossEntry.GlossSee
"# "
)); ));
assert_eq!(actual.out, "markup") assert_eq!(actual.out, "markup")
@ -179,7 +179,7 @@ fn parses_json() {
fn parses_xml() { fn parses_xml() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", cwd: "tests/fixtures/formats",
pipeline(r#" pipeline("
open jt.xml open jt.xml
| get content | get content
| where tag == channel | where tag == channel
@ -190,7 +190,7 @@ fn parses_xml() {
| flatten | flatten
| where tag == guid | where tag == guid
| get content.0.content.0 | get content.0.content.0
"#) ")
); );
assert_eq!(actual.out, "https://www.jntrnr.com/off-to-new-adventures/") assert_eq!(actual.out, "https://www.jntrnr.com/off-to-new-adventures/")
@ -201,12 +201,12 @@ fn parses_xml() {
fn parses_arrow_ipc() { fn parses_arrow_ipc() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
dfr open caco3_plastics.arrow dfr open caco3_plastics.arrow
| dfr into-nu | dfr into-nu
| first | first
| get origin | get origin
"# "
)); ));
assert_eq!(actual.out, "SPAIN") assert_eq!(actual.out, "SPAIN")
@ -236,9 +236,9 @@ fn errors_if_file_not_found() {
fn open_wildcard() { fn open_wildcard() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open *.nu | where $it =~ echo | length open *.nu | where $it =~ echo | length
"# "
)); ));
assert_eq!(actual.out, "3") assert_eq!(actual.out, "3")
@ -248,9 +248,9 @@ fn open_wildcard() {
fn open_multiple_files() { fn open_multiple_files() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open caco3_plastics.csv caco3_plastics.tsv | get tariff_item | math sum open caco3_plastics.csv caco3_plastics.tsv | get tariff_item | math sum
"# "
)); ));
assert_eq!(actual.out, "58309279992") assert_eq!(actual.out, "58309279992")
@ -280,9 +280,9 @@ fn open_ignore_ansi() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls | find nu.zion | get 0 | get name | open $in ls | find nu.zion | get 0 | get name | open $in
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
@ -291,9 +291,7 @@ fn open_ignore_ansi() {
#[test] #[test]
fn open_no_parameter() { fn open_no_parameter() {
let actual = nu!(r#" let actual = nu!("open");
open
"#);
assert!(actual.err.contains("needs filename")); assert!(actual.err.contains("needs filename"));
} }

View File

@ -3,7 +3,7 @@ use nu_test_support::nu;
#[test] #[test]
fn par_each_does_not_flatten_nested_structures() { fn par_each_does_not_flatten_nested_structures() {
// This is a regression test for issue #8497 // This is a regression test for issue #8497
let actual = nu!(r#"[1 2 3] | par-each { |it| [$it, $it] } | sort | to json --raw"#); let actual = nu!("[1 2 3] | par-each { |it| [$it, $it] } | sort | to json --raw");
assert_eq!(actual.out, "[[1,1],[2,2],[3,3]]"); assert_eq!(actual.out, "[[1,1],[2,2],[3,3]]");
} }

View File

@ -9,12 +9,12 @@ fn selects_a_row() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| sort-by name | sort-by name
| range 0..0 | range 0..0
| get name.0 | get name.0
"# "
)); ));
assert_eq!(actual.out, "notes.txt"); assert_eq!(actual.out, "notes.txt");
@ -32,12 +32,12 @@ fn selects_some_rows() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| range 1..2 | range 1..2
| length | length
"# "
)); ));
assert_eq!(actual.out, "2"); assert_eq!(actual.out, "2");
@ -55,12 +55,12 @@ fn negative_indices() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| range (-1..) | range (-1..)
| length | length
"# "
)); ));
assert_eq!(actual.out, "1"); assert_eq!(actual.out, "1");

View File

@ -104,7 +104,7 @@ fn separate_redirection() {
sandbox.with_files(vec![FileWithContent("test.sh", script_body)]); sandbox.with_files(vec![FileWithContent("test.sh", script_body)]);
nu!( nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"bash test.sh out> out.txt err> err.txt"# "bash test.sh out> out.txt err> err.txt"
); );
} }
#[cfg(windows)] #[cfg(windows)]
@ -112,7 +112,7 @@ fn separate_redirection() {
sandbox.with_files(vec![FileWithContent("test.bat", script_body)]); sandbox.with_files(vec![FileWithContent("test.bat", script_body)]);
nu!( nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"cmd /D /c test.bat out> out.txt err> err.txt"# "cmd /D /c test.bat out> out.txt err> err.txt"
); );
} }
// check for stdout redirection file. // check for stdout redirection file.
@ -142,10 +142,10 @@ fn same_target_redirection_with_too_much_stderr_not_hang_nushell() {
nu!( nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
$env.LARGE = (open --raw a_large_file.txt); $env.LARGE = (open --raw a_large_file.txt);
nu --testbin echo_env_stderr LARGE out+err> another_large_file.txt nu --testbin echo_env_stderr LARGE out+err> another_large_file.txt
"# "
), ),
); );
@ -166,7 +166,7 @@ fn redirection_keep_exit_codes() {
sandbox.with_files(vec![FileWithContent("test.sh", script_body)]); sandbox.with_files(vec![FileWithContent("test.sh", script_body)]);
nu!( nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"bash test.sh out> out.txt err> err.txt; echo $env.LAST_EXIT_CODE"# "bash test.sh out> out.txt err> err.txt; echo $env.LAST_EXIT_CODE"
) )
}; };
#[cfg(windows)] #[cfg(windows)]
@ -174,7 +174,7 @@ fn redirection_keep_exit_codes() {
sandbox.with_files(vec![FileWithContent("test.bat", script_body)]); sandbox.with_files(vec![FileWithContent("test.bat", script_body)]);
nu!( nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"cmd /D /c test.bat out> out.txt err> err.txt; echo $env.LAST_EXIT_CODE"# "cmd /D /c test.bat out> out.txt err> err.txt; echo $env.LAST_EXIT_CODE"
) )
}; };
assert_eq!(output.out, "10") assert_eq!(output.out, "10")
@ -196,7 +196,7 @@ fn redirection_with_pipeline_works() {
nu!( nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"bash test.sh out> out.txt | describe"# "bash test.sh out> out.txt | describe"
); );
// check for stdout redirection file. // check for stdout redirection file.
let expected_out_file = dirs.test().join("out.txt"); let expected_out_file = dirs.test().join("out.txt");

View File

@ -18,11 +18,11 @@ fn reduce_table_column() {
#[test] #[test]
fn reduce_table_column_with_path() { fn reduce_table_column_with_path() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}] [{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]
| reduce -f 20 { |it, acc| $it.total + $acc ** 1.05} | reduce -f 20 { |it, acc| $it.total + $acc ** 1.05}
| into string -d 1 | into string -d 1
"# "
)); ));
assert_eq!(actual.out, "180.6"); assert_eq!(actual.out, "180.6");
@ -31,10 +31,10 @@ fn reduce_table_column_with_path() {
#[test] #[test]
fn reduce_rows_example() { fn reduce_rows_example() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[[a,b]; [1,2] [3,4]] [[a,b]; [1,2] [3,4]]
| reduce -f 1.6 { |it, acc| $acc * ($it.a | into int) + ($it.b | into int) } | reduce -f 1.6 { |it, acc| $acc * ($it.a | into int) + ($it.b | into int) }
"# "
)); ));
assert_eq!(actual.out, "14.8"); assert_eq!(actual.out, "14.8");
@ -43,14 +43,14 @@ fn reduce_rows_example() {
#[test] #[test]
fn reduce_with_return_in_closure() { fn reduce_with_return_in_closure() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[1, 2] | reduce --fold null { |it, state| [1, 2] | reduce --fold null { |it, state|
if $it == 1 { if $it == 1 {
return 10 return 10
}; };
return ($it * $state) return ($it * $state)
} }
"# "
)); ));
assert_eq!(actual.out, "20"); assert_eq!(actual.out, "20");
@ -60,11 +60,11 @@ fn reduce_with_return_in_closure() {
#[test] #[test]
fn reduce_enumerate_example() { fn reduce_enumerate_example() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
echo one longest three bar | enumerate echo one longest three bar | enumerate
| reduce { |it, acc| if ($it.item | str length) > ($acc.item | str length) {echo $it} else {echo $acc}} | reduce { |it, acc| if ($it.item | str length) > ($acc.item | str length) {echo $it} else {echo $acc}}
| get index | get index
"# "
)); ));
assert_eq!(actual.out, "1"); assert_eq!(actual.out, "1");
@ -73,12 +73,12 @@ fn reduce_enumerate_example() {
#[test] #[test]
fn reduce_enumerate_integer_addition_example() { fn reduce_enumerate_integer_addition_example() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
echo [1 2 3 4] echo [1 2 3 4]
| enumerate | enumerate
| reduce { |it, acc| { index: ($it.index) item: ($acc.item + $it.item)} } | reduce { |it, acc| { index: ($it.index) item: ($acc.item + $it.item)} }
| get item | get item
"# "
)); ));
assert_eq!(actual.out, "10"); assert_eq!(actual.out, "10");
@ -87,7 +87,7 @@ fn reduce_enumerate_integer_addition_example() {
#[test] #[test]
fn folding_with_tables() { fn folding_with_tables() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
echo [10 20 30 40] echo [10 20 30 40]
| reduce -f [] { |it, acc| | reduce -f [] { |it, acc|
with-env [value $it] { with-env [value $it] {
@ -95,7 +95,7 @@ fn folding_with_tables() {
} }
} }
| math sum | math sum
"# "
)); ));
assert_eq!(actual.out, "1000"); assert_eq!(actual.out, "1000");
@ -104,9 +104,7 @@ fn folding_with_tables() {
#[test] #[test]
fn error_reduce_fold_type_mismatch() { fn error_reduce_fold_type_mismatch() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "echo a b c | reduce -f 0 { |it, acc| $acc + $it }"
echo a b c | reduce -f 0 { |it, acc| $acc + $it }
"#
)); ));
assert!(actual.err.contains("mismatch")); assert!(actual.err.contains("mismatch"));
@ -114,11 +112,7 @@ fn error_reduce_fold_type_mismatch() {
#[test] #[test]
fn error_reduce_empty() { fn error_reduce_empty() {
let actual = nu!(pipeline( let actual = nu!(pipeline("reduce { |it, acc| $acc + $it }"));
r#"
reduce { |it, acc| $acc + $it }
"#
));
assert!(actual.err.contains("needs input")); assert!(actual.err.contains("needs input"));
} }
@ -126,9 +120,7 @@ fn error_reduce_empty() {
#[test] #[test]
fn enumerate_reduce_example() { fn enumerate_reduce_example() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "[one longest three bar] | enumerate | reduce {|it, acc| if ($it.item | str length) > ($acc.item | str length) { $it } else { $acc }} | get index"
[one longest three bar] | enumerate | reduce {|it, acc| if ($it.item | str length) > ($acc.item | str length) { $it } else { $acc }} | get index
"#
)); ));
assert_eq!(actual.out, "1"); assert_eq!(actual.out, "1");

View File

@ -17,14 +17,14 @@ fn changes_the_column_name() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open los_cuatro_mosqueteros.txt open los_cuatro_mosqueteros.txt
| lines | lines
| wrap name | wrap name
| rename mosqueteros | rename mosqueteros
| get mosqueteros | get mosqueteros
| length | length
"# "
)); ));
assert_eq!(actual.out, "4"); assert_eq!(actual.out, "4");
@ -76,11 +76,11 @@ fn errors_if_no_columns_present() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open los_cuatro_mosqueteros.txt open los_cuatro_mosqueteros.txt
| lines | lines
| rename mosqueteros | rename mosqueteros
"# "
)); ));
assert!(actual.err.contains("command doesn't support")); assert!(actual.err.contains("command doesn't support"));

View File

@ -2,18 +2,14 @@ use nu_test_support::{nu, pipeline};
#[test] #[test]
fn early_return_if_true() { fn early_return_if_true() {
let actual = nu!(r#" let actual = nu!("def foo [x] { if true { return 2 }; $x }; foo 100");
def foo [x] { if true { return 2 }; $x }; foo 100
"#);
assert_eq!(actual.out, r#"2"#); assert_eq!(actual.out, r#"2"#);
} }
#[test] #[test]
fn early_return_if_false() { fn early_return_if_false() {
let actual = nu!(r#" let actual = nu!("def foo [x] { if false { return 2 }; $x }; foo 100");
def foo [x] { if false { return 2 }; $x }; foo 100
"#);
assert_eq!(actual.out, r#"100"#); assert_eq!(actual.out, r#"100"#);
} }
@ -22,9 +18,7 @@ fn early_return_if_false() {
fn return_works_in_script_without_def_main() { fn return_works_in_script_without_def_main() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "nu early_return.nu"
nu early_return.nu
"#
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());

View File

@ -313,7 +313,7 @@ fn rm_wildcard_leading_dot_deletes_dotfiles() {
nu!( nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"rm .*"# "rm .*"
); );
assert!(files_exist_at(vec!["foo"], dirs.test())); assert!(files_exist_at(vec!["foo"], dirs.test()));

View File

@ -23,11 +23,11 @@ mod rows {
"{} | {}", "{} | {}",
table(), table(),
pipeline( pipeline(
r#" "
roll down roll down
| first | first
| get status | get status
"# "
) )
)); ));
@ -40,11 +40,11 @@ mod rows {
"{} | {}", "{} | {}",
table(), table(),
pipeline( pipeline(
r#" "
roll up --by 3 roll up --by 3
| first | first
| get status | get status
"# "
) )
)); ));

View File

@ -7,9 +7,9 @@ use nu_test_support::{nu, pipeline};
fn better_empty_redirection() { fn better_empty_redirection() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
ls | each { |it| nu --testbin cococo $it.name } | ignore ls | each { |it| nu --testbin cococo $it.name } | ignore
"# "
)); ));
eprintln!("out: {}", actual.out); eprintln!("out: {}", actual.out);
@ -50,9 +50,9 @@ fn bare_word_expand_path_glob() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
^ls *.txt ^ls *.txt
"# "
)); ));
assert!(actual.out.contains("D&D_volume_1.txt")); assert!(actual.out.contains("D&D_volume_1.txt"));
@ -130,9 +130,9 @@ fn failed_command_with_semicolon_will_not_execute_following_cmds() {
Playground::setup("external failed command with semicolon", |dirs, _| { Playground::setup("external failed command with semicolon", |dirs, _| {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
^ls *.abc; echo done ^ls *.abc; echo done
"# "
)); ));
assert!(!actual.out.contains("done")); assert!(!actual.out.contains("done"));
@ -228,7 +228,7 @@ fn external_command_expand_tilde_with_back_quotes() {
fn external_command_receives_raw_binary_data() { fn external_command_receives_raw_binary_data() {
Playground::setup("external command receives raw binary data", |dirs, _| { Playground::setup("external command receives raw binary data", |dirs, _| {
let actual = let actual =
nu!(cwd: dirs.test(), pipeline(r#"0x[deadbeef] | nu --testbin input_bytes_length"#)); nu!(cwd: dirs.test(), pipeline("0x[deadbeef] | nu --testbin input_bytes_length"));
assert_eq!(actual.out, r#"4"#); assert_eq!(actual.out, r#"4"#);
}) })
} }
@ -239,9 +239,9 @@ fn failed_command_with_semicolon_will_not_execute_following_cmds_windows() {
Playground::setup("external failed command with semicolon", |dirs, _| { Playground::setup("external failed command with semicolon", |dirs, _| {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
^cargo asdf; echo done ^cargo asdf; echo done
"# "
)); ));
assert!(!actual.out.contains("done")); assert!(!actual.out.contains("done"));

View File

@ -30,7 +30,7 @@ fn writes_out_list() {
nu!( nu!(
cwd: dirs.root(), cwd: dirs.root(),
r#"[a b c d] | save save_test_3/list_sample.txt"#, "[a b c d] | save save_test_3/list_sample.txt",
); );
let actual = file_contents(expected_file); let actual = file_contents(expected_file);
@ -185,7 +185,7 @@ fn save_failure_not_overrides() {
nu!( nu!(
cwd: dirs.root(), cwd: dirs.root(),
// Writing number to file as toml fails // Writing number to file as toml fails
r#"3 | save save_test_10/result.toml -f"# "3 | save save_test_10/result.toml -f"
); );
let actual = file_contents(expected_file); let actual = file_contents(expected_file);
assert_eq!(actual, "Old content"); assert_eq!(actual, "Old content");
@ -272,7 +272,7 @@ fn save_list_stream() {
nu!( nu!(
cwd: dirs.root(), cwd: dirs.root(),
r#"[a b c d] | each {|i| $i} | save -r save_test_13/list_sample.txt"#, "[a b c d] | each {|i| $i} | save -r save_test_13/list_sample.txt",
); );
let actual = file_contents(expected_file); let actual = file_contents(expected_file);
@ -289,7 +289,7 @@ fn writes_out_range() {
nu!( nu!(
cwd: dirs.root(), cwd: dirs.root(),
r#"1..3 | save save_test_14/list_sample.json"#, "1..3 | save save_test_14/list_sample.json",
); );
let actual = file_contents(expected_file); let actual = file_contents(expected_file);

View File

@ -129,12 +129,12 @@ fn selects_a_row() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| sort-by name | sort-by name
| select 0 | select 0
| get name.0 | get name.0
"# "
)); ));
assert_eq!(actual.out, "arepas.txt"); assert_eq!(actual.out, "arepas.txt");
@ -148,12 +148,12 @@ fn selects_many_rows() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| select 1 0 | select 1 0
| length | length
"# "
)); ));
assert_eq!(actual.out, "2"); assert_eq!(actual.out, "2");

View File

@ -20,14 +20,14 @@ fn by_invalid_types() {
fn sort_primitive_values() { fn sort_primitive_values() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open cargo_sample.toml --raw open cargo_sample.toml --raw
| lines | lines
| skip 1 | skip 1
| first 6 | first 6
| sort | sort
| first | first
"# "
)); ));
assert_eq!(actual.out, "authors = [\"The Nushell Project Developers\"]"); assert_eq!(actual.out, "authors = [\"The Nushell Project Developers\"]");

View File

@ -54,12 +54,12 @@ fn sort_by_empty() {
fn ls_sort_by_name_sensitive() { fn ls_sort_by_name_sensitive() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample-ls-output.json open sample-ls-output.json
| sort-by name | sort-by name
| select name | select name
| to json --raw | to json --raw
"# "
)); ));
let json_output = r#"[{"name": "B.txt"},{"name": "C"},{"name": "a.txt"}]"#; let json_output = r#"[{"name": "B.txt"},{"name": "C"},{"name": "a.txt"}]"#;
@ -71,12 +71,12 @@ fn ls_sort_by_name_sensitive() {
fn ls_sort_by_name_insensitive() { fn ls_sort_by_name_insensitive() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample-ls-output.json open sample-ls-output.json
| sort-by -i name | sort-by -i name
| select name | select name
| to json --raw | to json --raw
"# "
)); ));
let json_output = r#"[{"name": "a.txt"},{"name": "B.txt"},{"name": "C"}]"#; let json_output = r#"[{"name": "a.txt"},{"name": "B.txt"},{"name": "C"}]"#;
@ -87,12 +87,12 @@ fn ls_sort_by_name_insensitive() {
fn ls_sort_by_type_name_sensitive() { fn ls_sort_by_type_name_sensitive() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample-ls-output.json open sample-ls-output.json
| sort-by type name | sort-by type name
| select name type | select name type
| to json --raw | to json --raw
"# "
)); ));
let json_output = r#"[{"name": "C","type": "Dir"},{"name": "B.txt","type": "File"},{"name": "a.txt","type": "File"}]"#; let json_output = r#"[{"name": "C","type": "Dir"},{"name": "B.txt","type": "File"},{"name": "a.txt","type": "File"}]"#;
@ -103,12 +103,12 @@ fn ls_sort_by_type_name_sensitive() {
fn ls_sort_by_type_name_insensitive() { fn ls_sort_by_type_name_insensitive() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample-ls-output.json open sample-ls-output.json
| sort-by -i type name | sort-by -i type name
| select name type | select name type
| to json --raw | to json --raw
"# "
)); ));
let json_output = r#"[{"name": "C","type": "Dir"},{"name": "a.txt","type": "File"},{"name": "B.txt","type": "File"}]"#; let json_output = r#"[{"name": "C","type": "Dir"},{"name": "a.txt","type": "File"},{"name": "B.txt","type": "File"}]"#;

View File

@ -37,11 +37,11 @@ fn sources_also_files_under_custom_lib_dirs_path() {
let actual = nu!( let actual = nu!(
cwd: ".", pipeline( cwd: ".", pipeline(
r#" "
source-env my_library.nu ; source-env my_library.nu ;
hello hello
"# "
)); ));
assert_eq!(actual.out, "hello nu"); assert_eq!(actual.out, "hello nu");
@ -319,9 +319,9 @@ fn source_env_const_file() {
fn source_respects_early_return() { fn source_respects_early_return() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
source early_return.nu source early_return.nu
"# "
)); ));
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());

View File

@ -42,11 +42,11 @@ fn errors_if_no_table_given_as_input() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| split-by type | split-by type
"# "
)); ));
assert!(actual.err.contains("requires a table")); assert!(actual.err.contains("requires a table"));

File diff suppressed because one or more lines are too long

View File

@ -105,7 +105,7 @@ fn not_create_file_if_it_not_exists() {
Playground::setup("change_time_test_28", |dirs, _sandbox| { Playground::setup("change_time_test_28", |dirs, _sandbox| {
nu!( nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"touch -c file.txt"# "touch -c file.txt"
); );
let path = dirs.test().join("file.txt"); let path = dirs.test().join("file.txt");
@ -114,7 +114,7 @@ fn not_create_file_if_it_not_exists() {
nu!( nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#"touch -c file.txt"# "touch -c file.txt"
); );
let path = dirs.test().join("file.txt"); let path = dirs.test().join("file.txt");

View File

@ -19,11 +19,11 @@ fn removes_duplicate_rows() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open los_tres_caballeros.csv open los_tres_caballeros.csv
| uniq | uniq
| length | length
"# "
)); ));
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
@ -47,12 +47,12 @@ fn uniq_values() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open los_tres_caballeros.csv open los_tres_caballeros.csv
| select type | select type
| uniq | uniq
| length | length
"# "
)); ));
assert_eq!(actual.out, "2"); assert_eq!(actual.out, "2");
@ -119,11 +119,11 @@ fn nested_json_structures() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open nested_json_structures.json open nested_json_structures.json
| uniq | uniq
| length | length
"# "
)); ));
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
}) })
@ -195,10 +195,10 @@ fn uniq_simple_vals_strs() {
#[test] #[test]
fn table() { fn table() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[[fruit day]; [apple monday] [apple friday] [Apple friday] [apple monday] [pear monday] [orange tuesday]] [[fruit day]; [apple monday] [apple friday] [Apple friday] [apple monday] [pear monday] [orange tuesday]]
| uniq | uniq
"# "
)); ));
let expected = nu!("[[fruit day]; [apple monday] [apple friday] [Apple friday] [pear monday] [orange tuesday]]"); let expected = nu!("[[fruit day]; [apple monday] [apple friday] [Apple friday] [pear monday] [orange tuesday]]");

View File

@ -18,11 +18,11 @@ fn removes_duplicate_rows() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open los_tres_caballeros.csv open los_tres_caballeros.csv
| uniq-by last_name | uniq-by last_name
| length | length
"# "
)); ));
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
@ -69,12 +69,12 @@ fn uniq_counting() {
#[test] #[test]
fn uniq_unique() { fn uniq_unique() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
echo [1 2 3 4 1 5] echo [1 2 3 4 1 5]
| wrap item | wrap item
| uniq-by item --unique | uniq-by item --unique
| get item | get item
"# "
)); ));
let expected = nu!("[2 3 4 5]"); let expected = nu!("[2 3 4 5]");
assert_eq!(actual.out, expected.out); assert_eq!(actual.out, expected.out);
@ -83,16 +83,16 @@ fn uniq_unique() {
#[test] #[test]
fn table() { fn table() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[[fruit day]; [apple monday] [apple friday] [Apple friday] [apple monday] [pear monday] [orange tuesday]] [[fruit day]; [apple monday] [apple friday] [Apple friday] [apple monday] [pear monday] [orange tuesday]]
| uniq-by fruit | uniq-by fruit
"# "
)); ));
let expected = nu!(pipeline( let expected = nu!(pipeline(
r#" "
echo [[fruit day]; [apple monday] [Apple friday] [pear monday] [orange tuesday]] echo [[fruit day]; [apple monday] [Apple friday] [pear monday] [orange tuesday]]
"# "
)); ));
print!("{}", actual.out); print!("{}", actual.out);
print!("{}", expected.out); print!("{}", expected.out);
@ -109,16 +109,16 @@ fn uniq_by_empty() {
#[test] #[test]
fn uniq_by_multiple_columns() { fn uniq_by_multiple_columns() {
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" "
[[fruit day]; [apple monday] [apple friday] [Apple friday] [apple monday] [pear monday] [orange tuesday]] [[fruit day]; [apple monday] [apple friday] [Apple friday] [apple monday] [pear monday] [orange tuesday]]
| uniq-by fruit day | uniq-by fruit day
"# "
)); ));
let expected = nu!(pipeline( let expected = nu!(pipeline(
r#" "
echo [[fruit day]; [apple monday] [apple friday] [Apple friday] [pear monday] [orange tuesday]] echo [[fruit day]; [apple monday] [apple friday] [Apple friday] [pear monday] [orange tuesday]]
"# "
)); ));
assert_eq!(actual.out, expected.out); assert_eq!(actual.out, expected.out);
} }

View File

@ -26,11 +26,11 @@ fn doesnt_convert_record_to_table() {
fn sets_the_column_from_a_block_run_output() { fn sets_the_column_from_a_block_run_output() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open cargo_sample.toml open cargo_sample.toml
| update dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor } | update dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor }
| get dev-dependencies.pretty_assertions | get dev-dependencies.pretty_assertions
"# "
)); ));
assert_eq!(actual.out, "0.7.0"); assert_eq!(actual.out, "0.7.0");

View File

@ -25,11 +25,11 @@ fn doesnt_convert_record_to_table() {
fn sets_the_column_from_a_block_run_output() { fn sets_the_column_from_a_block_run_output() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open cargo_sample.toml open cargo_sample.toml
| upsert dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor } | upsert dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor }
| get dev-dependencies.pretty_assertions | get dev-dependencies.pretty_assertions
"# "
)); ));
assert_eq!(actual.out, "0.7.0"); assert_eq!(actual.out, "0.7.0");
@ -68,7 +68,7 @@ fn sets_the_column_from_a_subexpression() {
#[test] #[test]
fn upsert_uses_enumerate_index_inserting() { fn upsert_uses_enumerate_index_inserting() {
let actual = nu!( let actual = nu!(
r#"[[a]; [7] [6]] | enumerate | upsert b {|el| $el.index + 1 + $el.item.a } | flatten | to nuon"# "[[a]; [7] [6]] | enumerate | upsert b {|el| $el.index + 1 + $el.item.a } | flatten | to nuon"
); );
assert_eq!(actual.out, "[[index, a, b]; [0, 7, 8], [1, 6, 8]]"); assert_eq!(actual.out, "[[index, a, b]; [0, 7, 8], [1, 6, 8]]");

View File

@ -20,13 +20,13 @@ fn use_module_file_within_block() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
def bar [] { def bar [] {
use spam.nu foo; use spam.nu foo;
foo foo
}; };
bar bar
"# "
) )
); );
@ -53,10 +53,10 @@ fn use_keeps_doc_comments() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
use spam.nu foo; use spam.nu foo;
help foo help foo
"# "
) )
); );

View File

@ -81,65 +81,65 @@ fn where_uses_enumerate_index() {
fn binary_operator_comparisons() { fn binary_operator_comparisons() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample.db open sample.db
| get ints | get ints
| first 4 | first 4
| where z > 4200 | where z > 4200
| get z.0 | get z.0
"# "
)); ));
assert_eq!(actual.out, "4253"); assert_eq!(actual.out, "4253");
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample.db open sample.db
| get ints | get ints
| first 4 | first 4
| where z >= 4253 | where z >= 4253
| get z.0 | get z.0
"# "
)); ));
assert_eq!(actual.out, "4253"); assert_eq!(actual.out, "4253");
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample.db open sample.db
| get ints | get ints
| first 4 | first 4
| where z < 10 | where z < 10
| get z.0 | get z.0
"# "
)); ));
assert_eq!(actual.out, "1"); assert_eq!(actual.out, "1");
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample.db open sample.db
| get ints | get ints
| first 4 | first 4
| where z <= 1 | where z <= 1
| get z.0 | get z.0
"# "
)); ));
assert_eq!(actual.out, "1"); assert_eq!(actual.out, "1");
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample.db open sample.db
| get ints | get ints
| where z != 1 | where z != 1
| first | first
| get z | get z
"# "
)); ));
assert_eq!(actual.out, "42"); assert_eq!(actual.out, "42");
@ -150,24 +150,24 @@ fn binary_operator_comparisons() {
fn contains_operator() { fn contains_operator() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample.db open sample.db
| get strings | get strings
| where x =~ ell | where x =~ ell
| length | length
"# "
)); ));
assert_eq!(actual.out, "4"); assert_eq!(actual.out, "4");
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
r#" "
open sample.db open sample.db
| get strings | get strings
| where x !~ ell | where x !~ ell
| length | length
"# "
)); ));
assert_eq!(actual.out, "2"); assert_eq!(actual.out, "2");

View File

@ -17,14 +17,14 @@ fn wrap_rows_into_a_row() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open los_tres_caballeros.txt open los_tres_caballeros.txt
| from csv | from csv
| wrap caballeros | wrap caballeros
| get caballeros | get caballeros
| get 0 | get 0
| get last_name | get last_name
"# "
)); ));
assert_eq!(actual.out, "Robalino"); assert_eq!(actual.out, "Robalino");
@ -46,14 +46,14 @@ fn wrap_rows_into_a_table() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open los_tres_caballeros.txt open los_tres_caballeros.txt
| from csv | from csv
| get last_name | get last_name
| wrap caballero | wrap caballero
| get 2 | get 2
| get caballero | get caballero
"# "
)); ));
assert_eq!(actual.out, "Katz"); assert_eq!(actual.out, "Katz");

View File

@ -23,7 +23,7 @@ fn zips_two_tables() {
)]); )]);
let actual = nu!(pipeline(&format!( let actual = nu!(pipeline(&format!(
r#" "
use {} expect ; use {} expect ;
let contributors = ([ let contributors = ([
@ -35,7 +35,7 @@ fn zips_two_tables() {
let actual = ($contributors | upsert commits {{ |i| ($i.commits + 10) }}); let actual = ($contributors | upsert commits {{ |i| ($i.commits + 10) }});
expect $actual --to-eq [[name, commits]; [andres, 20] [jt, 30]] expect $actual --to-eq [[name, commits]; [andres, 20] [jt, 30]]
"#, ",
dirs.test().join("zip_test.nu").display() dirs.test().join("zip_test.nu").display()
))); )));