fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793)

# Description

This PR further fixes tests as part of #8670 

# User-Facing Changes

None

# Tests + Formatting

None

# After Submitting

None

---------

Signed-off-by: Harshal Chaudhari <harshal.chaudhary@gmail.com>
Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
This commit is contained in:
Harshal Chaudhari 2023-04-07 22:09:55 +01:00 committed by GitHub
parent 1c5846e1fb
commit 35e8420780
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 140 additions and 335 deletions

View file

@ -2,8 +2,7 @@ use nu_test_support::{nu, pipeline};
#[test] #[test]
fn adds_a_row_to_the_end() { fn adds_a_row_to_the_end() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline(
r#" r#"
echo [ "Andrés N. Robalino", "JT Turner", "Yehuda Katz" ] echo [ "Andrés N. Robalino", "JT Turner", "Yehuda Katz" ]
| append "pollo loco" | append "pollo loco"

View file

@ -1,37 +1,26 @@
use nu_test_support::{nu, pipeline}; use nu_test_support::nu;
#[test] #[test]
fn break_for_loop() { fn break_for_loop() {
let actual = nu!( let actual = nu!("
cwd: ".", pipeline(
r#"
for i in 1..10 { if $i == 2 { break }; print $i } for i in 1..10 { if $i == 2 { break }; print $i }
"# ");
));
assert_eq!(actual.out, r#"1"#); assert_eq!(actual.out, "1");
} }
#[test] #[test]
fn break_while_loop() { fn break_while_loop() {
let actual = nu!( let actual = nu!(r#" while true { break }; print "hello" "#);
cwd: ".", pipeline(
r#"
while true { break }; print "hello"
"#
));
assert_eq!(actual.out, r#"hello"#); assert_eq!(actual.out, "hello");
} }
#[test] #[test]
fn break_each() { fn break_each() {
let actual = nu!( let actual = nu!("
cwd: ".", pipeline(
r#"
[1, 2, 3, 4, 5] | each {|x| if $x > 3 { break }; $x} | math sum [1, 2, 3, 4, 5] | each {|x| if $x > 3 { break }; $x} | math sum
"# ");
));
assert_eq!(actual.out, r#"6"#); assert_eq!(actual.out, "6");
} }

View file

@ -2,12 +2,7 @@ use nu_test_support::{nu, pipeline};
#[test] #[test]
fn cal_full_year() { fn cal_full_year() {
let actual = nu!( let actual = nu!("cal -y --full-year 2010 | first | to json -r");
cwd: ".", pipeline(
r#"
cal -y --full-year 2010 | first | to json -r
"#
));
let first_week_2010_json = r#"{"year": 2010,"sunday": null,"monday": null,"tuesday": null,"wednesday": null,"thursday": null,"friday": 1,"saturday": 2}"#; let first_week_2010_json = r#"{"year": 2010,"sunday": null,"monday": null,"tuesday": null,"wednesday": null,"thursday": null,"friday": 1,"saturday": 2}"#;
@ -16,8 +11,7 @@ fn cal_full_year() {
#[test] #[test]
fn cal_february_2020_leap_year() { fn cal_february_2020_leap_year() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline(
r#" r#"
cal -ym --full-year 2020 --month-names | where month == "february" | to json -r cal -ym --full-year 2020 --month-names | where month == "february" | to json -r
"# "#
@ -30,8 +24,7 @@ fn cal_february_2020_leap_year() {
#[test] #[test]
fn cal_friday_the_thirteenths_in_2015() { fn cal_friday_the_thirteenths_in_2015() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline(
r#" r#"
cal --full-year 2015 | default 0 friday | where friday == 13 | length cal --full-year 2015 | default 0 friday | where friday == 13 | length
"# "#
@ -42,8 +35,7 @@ fn cal_friday_the_thirteenths_in_2015() {
#[test] #[test]
fn cal_rows_in_2020() { fn cal_rows_in_2020() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline(
r#" r#"
cal --full-year 2020 | length cal --full-year 2020 | length
"# "#
@ -54,8 +46,7 @@ fn cal_rows_in_2020() {
#[test] #[test]
fn cal_week_day_start_monday() { fn cal_week_day_start_monday() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline(
r#" r#"
cal --full-year 2020 -m --month-names --week-start monday | where month == january | to json -r cal --full-year 2020 -m --month-names --week-start monday | where month == january | to json -r
"# "#
@ -68,8 +59,7 @@ fn cal_week_day_start_monday() {
#[test] #[test]
fn cal_sees_pipeline_year() { fn cal_sees_pipeline_year() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline(
r#" r#"
cal --full-year 1020 | get monday | first 4 | to json -r cal --full-year 1020 | get monday | first 4 | to json -r
"# "#

View file

@ -20,13 +20,7 @@ fn cd_works_with_in_var() {
#[test] #[test]
fn filesystem_change_from_current_directory_using_relative_path() { fn filesystem_change_from_current_directory_using_relative_path() {
Playground::setup("cd_test_1", |dirs, _| { Playground::setup("cd_test_1", |dirs, _| {
let actual = nu!( let actual = nu!( cwd: dirs.root(), "cd cd_test_1; $env.PWD");
cwd: dirs.root(),
r#"
cd cd_test_1
$env.PWD
"#
);
assert_eq!(PathBuf::from(actual.out), *dirs.test()); assert_eq!(PathBuf::from(actual.out), *dirs.test());
}) })
@ -55,11 +49,11 @@ fn filesystem_switch_back_to_previous_working_directory() {
let actual = nu!( let actual = nu!(
cwd: dirs.test().join("odin"), cwd: dirs.test().join("odin"),
r#" "
cd {} cd {}
cd - cd -
$env.PWD $env.PWD
"#, ",
dirs.test().display() dirs.test().display()
); );
@ -74,10 +68,10 @@ fn filesystem_change_from_current_directory_using_relative_path_and_dash() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#" "
cd odin/- cd odin/-
$env.PWD $env.PWD
"# "
); );
assert_eq!( assert_eq!(
@ -92,10 +86,10 @@ fn filesystem_change_current_directory_to_parent_directory() {
Playground::setup("cd_test_5", |dirs, _| { Playground::setup("cd_test_5", |dirs, _| {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#" "
cd .. cd ..
$env.PWD $env.PWD
"# "
); );
assert_eq!(PathBuf::from(actual.out), *dirs.root()); assert_eq!(PathBuf::from(actual.out), *dirs.root());
@ -109,10 +103,10 @@ fn filesystem_change_current_directory_to_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#" "
cd ... cd ...
$env.PWD $env.PWD
"# "
); );
assert_eq!(PathBuf::from(actual.out), *dirs.test()); assert_eq!(PathBuf::from(actual.out), *dirs.test());
@ -124,10 +118,10 @@ fn filesystem_change_to_home_directory() {
Playground::setup("cd_test_8", |dirs, _| { Playground::setup("cd_test_8", |dirs, _| {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#" "
cd ~ cd ~
$env.PWD $env.PWD
"# "
); );
assert_eq!(Some(PathBuf::from(actual.out)), dirs_next::home_dir()); assert_eq!(Some(PathBuf::from(actual.out)), dirs_next::home_dir());
@ -208,10 +202,10 @@ fn filesystem_change_directory_to_symlink_relative() {
let actual = nu!( let actual = nu!(
cwd: dirs.test().join("boo"), cwd: dirs.test().join("boo"),
r#" "
cd ../foo_link cd ../foo_link
$env.PWD $env.PWD
"# "
); );
assert_eq!(PathBuf::from(actual.out), dirs.test().join("foo")); assert_eq!(PathBuf::from(actual.out), dirs.test().join("foo"));
@ -251,18 +245,18 @@ fn cd_permission_denied_folder() {
sandbox.mkdir("banned"); sandbox.mkdir("banned");
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#" "
chmod -x banned chmod -x banned
cd banned cd banned
"# "
); );
assert!(actual.err.contains("Cannot change directory to")); assert!(actual.err.contains("Cannot change directory to"));
nu!( nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#" "
chmod +x banned chmod +x banned
rm banned rm banned
"# "
); );
}); });
} }

View file

@ -21,12 +21,12 @@ fn discards_rows_where_given_column_is_empty() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open los_tres_amigos.json open los_tres_amigos.json
| get amigos | get amigos
| compact rusty_luck | compact rusty_luck
| length | length
"# "
)); ));
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");

View file

@ -1,13 +1,8 @@
use nu_test_support::{nu, pipeline}; use nu_test_support::nu;
#[test] #[test]
fn continue_for_loop() { fn continue_for_loop() {
let actual = nu!( let actual = nu!("for i in 1..10 { if $i == 2 { continue }; print $i }");
cwd: ".", pipeline(
r#"
for i in 1..10 { if $i == 2 { continue }; print $i }
"#
));
assert_eq!(actual.out, r#"1345678910"#); assert_eq!(actual.out, "1345678910");
} }

View file

@ -1,5 +1,5 @@
use nu_test_support::nu;
use nu_test_support::playground::Playground; use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
use std::fs; use std::fs;
#[test] #[test]
@ -39,85 +39,49 @@ param:string #My cool attractive param
#[test] #[test]
fn def_errors_with_multiple_short_flags() { fn def_errors_with_multiple_short_flags() {
let actual = nu!( let actual = nu!("def test-command [ --long(-l)(-o) ] {}");
cwd: ".", pipeline(
r#"
def test-command [ --long(-l)(-o) ] {}
"#
));
assert!(actual.err.contains("expected only one short flag")); assert!(actual.err.contains("expected only one short flag"));
} }
#[test] #[test]
fn def_errors_with_comma_before_alternative_short_flag() { fn def_errors_with_comma_before_alternative_short_flag() {
let actual = nu!( let actual = nu!("def test-command [ --long, (-l) ] {}");
cwd: ".", pipeline(
r#"
def test-command [ --long, (-l) ] {}
"#
));
assert!(actual.err.contains("expected parameter")); assert!(actual.err.contains("expected parameter"));
} }
#[test] #[test]
fn def_errors_with_comma_before_equals() { fn def_errors_with_comma_before_equals() {
let actual = nu!( let actual = nu!("def test-command [ foo, = 1 ] {}");
cwd: ".", pipeline(
r#"
def test-command [ foo, = 1 ] {}
"#
));
assert!(actual.err.contains("expected parameter")); assert!(actual.err.contains("expected parameter"));
} }
#[test] #[test]
fn def_errors_with_comma_before_colon() { fn def_errors_with_comma_before_colon() {
let actual = nu!( let actual = nu!("def test-command [ foo, : int ] {}");
cwd: ".", pipeline(
r#"
def test-command [ foo, : int ] {}
"#
));
assert!(actual.err.contains("expected parameter")); assert!(actual.err.contains("expected parameter"));
} }
#[test] #[test]
fn def_errors_with_multiple_colons() { fn def_errors_with_multiple_colons() {
let actual = nu!( let actual = nu!("def test-command [ foo::int ] {}");
cwd: ".", pipeline(
r#"
def test-command [ foo::int ] {}
"#
));
assert!(actual.err.contains("expected type")); assert!(actual.err.contains("expected type"));
} }
#[ignore = "This error condition is not implemented yet"] #[ignore = "This error condition is not implemented yet"]
#[test] #[test]
fn def_errors_with_multiple_types() { fn def_errors_with_multiple_types() {
let actual = nu!( let actual = nu!("def test-command [ foo:int:string ] {}");
cwd: ".", pipeline(
r#"
def test-command [ foo:int:string ] {}
"#
));
assert!(actual.err.contains("expected parameter")); assert!(actual.err.contains("expected parameter"));
} }
#[test] #[test]
fn def_errors_with_multiple_commas() { fn def_errors_with_multiple_commas() {
let actual = nu!( let actual = nu!("def test-command [ foo,,bar ] {}");
cwd: ".", pipeline(
r#"
def test-command [ foo,,bar ] {}
"#
));
assert!(actual.err.contains("expected parameter")); assert!(actual.err.contains("expected parameter"));
} }
@ -125,28 +89,13 @@ fn def_errors_with_multiple_commas() {
#[test] #[test]
fn def_fails_with_invalid_name() { fn def_fails_with_invalid_name() {
let err_msg = "command name can't be a number, a filesize, or contain a hash # or caret ^"; let err_msg = "command name can't be a number, a filesize, or contain a hash # or caret ^";
let actual = nu!( let actual = nu!(r#"def 1234 = echo "test""#);
cwd: ".", pipeline(
r#"
def 1234 = echo "test"
"#
));
assert!(actual.err.contains(err_msg)); assert!(actual.err.contains(err_msg));
let actual = nu!( let actual = nu!(r#"def 5gib = echo "test""#);
cwd: ".", pipeline(
r#"
def 5gib = echo "test"
"#
));
assert!(actual.err.contains(err_msg)); assert!(actual.err.contains(err_msg));
let actual = nu!( let actual = nu!(r#"def ^foo [] {}"#);
cwd: ".", pipeline(
r#"
def ^foo [] {}
"#
));
assert!(actual.err.contains(err_msg)); assert!(actual.err.contains(err_msg));
} }
@ -188,12 +137,7 @@ param: list = [one]
#[test] #[test]
fn def_with_paren_params() { fn def_with_paren_params() {
let actual = nu!( let actual = nu!("def foo (x: int, y: int) { $x + $y }; foo 1 2");
cwd: ".", pipeline(
r#"
def foo (x: int, y: int) { $x + $y }; foo 1 2
"#
));
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
} }

View file

@ -21,13 +21,13 @@ fn adds_row_data_if_column_missing() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
open los_tres_amigos.json open los_tres_amigos.json
| get amigos | get amigos
| default 1 rusty_luck | default 1 rusty_luck
| where rusty_luck == 1 | where rusty_luck == 1
| length | length
"# "
)); ));
assert_eq!(actual.out, "2"); assert_eq!(actual.out, "2");

View file

@ -1,13 +1,10 @@
use nu_test_support::{nu, pipeline}; use nu_test_support::nu;
#[cfg(not(windows))]
use nu_test_support::pipeline;
#[test] #[test]
fn capture_errors_works() { fn capture_errors_works() {
let actual = nu!( let actual = nu!("do -c {$env.use}");
cwd: ".", pipeline(
r#"
do -c {$env.use}
"#
));
eprintln!("actual.err: {:?}", actual.err); eprintln!("actual.err: {:?}", actual.err);
@ -16,60 +13,35 @@ fn capture_errors_works() {
#[test] #[test]
fn capture_errors_works_for_external() { fn capture_errors_works_for_external() {
let actual = nu!( let actual = nu!("do -c {nu --testbin fail}");
cwd: ".", pipeline(
r#"
do -c {nu --testbin fail}
"#
));
assert!(actual.err.contains("External command failed")); assert!(actual.err.contains("External command failed"));
assert_eq!(actual.out, ""); assert_eq!(actual.out, "");
} }
#[test] #[test]
fn capture_errors_works_for_external_with_pipeline() { fn capture_errors_works_for_external_with_pipeline() {
let actual = nu!( let actual = nu!("do -c {nu --testbin fail} | echo `text`");
cwd: ".", pipeline(
r#"
do -c {nu --testbin fail} | echo `text`
"#
));
assert!(actual.err.contains("External command failed")); assert!(actual.err.contains("External command failed"));
assert_eq!(actual.out, ""); assert_eq!(actual.out, "");
} }
#[test] #[test]
fn capture_errors_works_for_external_with_semicolon() { fn capture_errors_works_for_external_with_semicolon() {
let actual = nu!( let actual = nu!(r#"do -c {nu --testbin fail}; echo `text`"#);
cwd: ".", pipeline(
r#"
do -c {nu --testbin fail}; echo `text`
"#
));
assert!(actual.err.contains("External command failed")); assert!(actual.err.contains("External command failed"));
assert_eq!(actual.out, ""); assert_eq!(actual.out, "");
} }
#[test] #[test]
fn do_with_semicolon_break_on_failed_external() { fn do_with_semicolon_break_on_failed_external() {
let actual = nu!( let actual = nu!(r#"do { nu --not_exist_flag }; `text`"#);
cwd: ".", pipeline(
r#"
do { nu --not_exist_flag }; `text`
"#
));
assert_eq!(actual.out, ""); assert_eq!(actual.out, "");
} }
#[test] #[test]
fn ignore_shell_errors_works_for_external_with_semicolon() { fn ignore_shell_errors_works_for_external_with_semicolon() {
let actual = nu!( let actual = nu!(r#"do -s { open asdfasdf.txt }; "text""#);
cwd: ".", pipeline(
r#"
do -s { open asdfasdf.txt }; "text"
"#
));
assert_eq!(actual.err, ""); assert_eq!(actual.err, "");
assert_eq!(actual.out, "text"); assert_eq!(actual.out, "text");
@ -77,12 +49,7 @@ fn ignore_shell_errors_works_for_external_with_semicolon() {
#[test] #[test]
fn ignore_program_errors_works_for_external_with_semicolon() { fn ignore_program_errors_works_for_external_with_semicolon() {
let actual = nu!( let actual = nu!(r#"do -p { nu -c 'exit 1' }; "text""#);
cwd: ".", pipeline(
r#"
do -p { nu -c 'exit 1' }; "text"
"#
));
assert_eq!(actual.err, ""); assert_eq!(actual.err, "");
assert_eq!(actual.out, "text"); assert_eq!(actual.out, "text");
@ -90,9 +57,7 @@ fn ignore_program_errors_works_for_external_with_semicolon() {
#[test] #[test]
fn ignore_error_should_work_for_external_command() { fn ignore_error_should_work_for_external_command() {
let actual = nu!(cwd: ".", pipeline( let actual = nu!(r#"do -i { nu --testbin fail asdf }; echo post"#);
r#"do -i { nu --testbin fail asdf }; echo post"#
));
assert_eq!(actual.err, ""); assert_eq!(actual.err, "");
assert_eq!(actual.out, "post"); assert_eq!(actual.out, "post");
@ -190,6 +155,6 @@ fn capture_error_with_both_stdout_stderr_messages_not_hang_nushell() {
#[test] #[test]
fn ignore_error_works_with_list_stream() { fn ignore_error_works_with_list_stream() {
let actual = nu!(cwd: ".", pipeline(r#"do -i { ["a", $nothing, "b"] | ansi strip }"#)); let actual = nu!(r#"do -i { ["a", $nothing, "b"] | ansi strip }"#);
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
} }

View file

@ -2,51 +2,47 @@ use nu_test_support::{nu, pipeline};
#[test] #[test]
fn columns() { fn columns() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline(r#" "
echo [ echo [
[arepas, color]; [arepas, color];
[3, white] [3, white]
[8, yellow] [8, yellow]
[4, white] [4, white]
] | drop column | columns | length ] | drop column | columns | length
"#) "
); ));
assert_eq!(actual.out, "1"); assert_eq!(actual.out, "1");
} }
#[test] #[test]
fn drop_columns_positive_value() { fn drop_columns_positive_value() {
let actual = nu!( let actual = nu!("echo [[a, b];[1,2]] | drop column -1");
cwd: ".", pipeline(r#"
echo [[a, b];[1,2]] | drop column -1
"#)
);
assert!(actual.err.contains("use a positive value")); assert!(actual.err.contains("use a positive value"));
} }
#[test] #[test]
fn more_columns_than_table_has() { fn more_columns_than_table_has() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline(r#" "
echo [ echo [
[arepas, color]; [arepas, color];
[3, white] [3, white]
[8, yellow] [8, yellow]
[4, white] [4, white]
] | drop column 3 | columns | is-empty ] | drop column 3 | columns | is-empty
"#) "
); ));
assert_eq!(actual.out, "true"); assert_eq!(actual.out, "true");
} }
#[test] #[test]
fn rows() { fn rows() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline(r#" "
echo [ echo [
[arepas]; [arepas];
@ -57,43 +53,43 @@ fn rows() {
| drop 2 | drop 2
| get arepas | get arepas
| math sum | math sum
"#) "
); ));
assert_eq!(actual.out, "3"); assert_eq!(actual.out, "3");
} }
#[test] #[test]
fn more_rows_than_table_has() { fn more_rows_than_table_has() {
let actual = nu!(cwd: ".", "[date] | drop 50 | length"); let actual = nu!("[date] | drop 50 | length");
assert_eq!(actual.out, "0"); assert_eq!(actual.out, "0");
} }
#[test] #[test]
fn nth_range_inclusive() { fn nth_range_inclusive() {
let actual = nu!(cwd: ".", "echo 10..15 | drop nth (2..3) | to json --raw"); let actual = nu!("echo 10..15 | drop nth (2..3) | to json --raw");
assert_eq!(actual.out, "[10,11,14,15]"); assert_eq!(actual.out, "[10,11,14,15]");
} }
#[test] #[test]
fn nth_range_exclusive() { fn nth_range_exclusive() {
let actual = nu!(cwd: ".", "echo 10..15 | drop nth (1..<3) | to json --raw"); let actual = nu!("echo 10..15 | drop nth (1..<3) | to json --raw");
assert_eq!(actual.out, "[10,13,14,15]"); assert_eq!(actual.out, "[10,13,14,15]");
} }
#[test] #[test]
fn nth_missing_first_argument() { fn nth_missing_first_argument() {
let actual = nu!(cwd: ".", "echo 10..15 | drop nth \"\""); let actual = nu!("echo 10..15 | drop nth \"\"");
assert!(actual.err.contains("int or range")); assert!(actual.err.contains("int or range"));
} }
#[test] #[test]
fn fail_on_non_iterator() { fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | drop 50")); let actual = nu!("1 | drop 50");
assert!(actual.err.contains("only_supports_this_input_type")); assert!(actual.err.contains("only_supports_this_input_type"));
} }

View file

@ -1,13 +1,11 @@
use nu_test_support::{nu, pipeline}; use nu_test_support::nu;
#[test] #[test]
fn each_works_separately() { fn each_works_separately() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats",
r#" "echo [1 2 3] | each { |it| echo $it 10 | math sum } | to json -r"
echo [1 2 3] | each { |it| echo $it 10 | math sum } | to json -r );
"#
));
assert_eq!(actual.out, "[11,12,13]"); assert_eq!(actual.out, "[11,12,13]");
} }
@ -15,11 +13,9 @@ fn each_works_separately() {
#[test] #[test]
fn each_group_works() { fn each_group_works() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats",
r#" "echo [1 2 3 4 5 6] | group 3 | to json --raw"
echo [1 2 3 4 5 6] | group 3 | to json --raw );
"#
));
assert_eq!(actual.out, "[[1,2,3],[4,5,6]]"); assert_eq!(actual.out, "[[1,2,3],[4,5,6]]");
} }
@ -27,11 +23,9 @@ fn each_group_works() {
#[test] #[test]
fn each_window() { fn each_window() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats",
r#" "echo [1 2 3 4] | window 3 | to json --raw"
echo [1 2 3 4] | window 3 | to json --raw );
"#
));
assert_eq!(actual.out, "[[1,2,3],[2,3,4]]"); assert_eq!(actual.out, "[[1,2,3],[2,3,4]]");
} }
@ -39,11 +33,9 @@ fn each_window() {
#[test] #[test]
fn each_window_stride() { fn each_window_stride() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats",
r#" "echo [1 2 3 4 5 6] | window 3 -s 2 | to json --raw"
echo [1 2 3 4 5 6] | window 3 -s 2 | to json --raw );
"#
));
assert_eq!(actual.out, "[[1,2,3],[3,4,5]]"); assert_eq!(actual.out, "[[1,2,3],[3,4,5]]");
} }
@ -51,11 +43,9 @@ fn each_window_stride() {
#[test] #[test]
fn each_no_args_in_block() { fn each_no_args_in_block() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats",
r#" "echo [[foo bar]; [a b] [c d] [e f]] | each {|i| $i | to json -r } | get 1"
echo [[foo bar]; [a b] [c d] [e f]] | each {|i| $i | to json -r } | get 1 );
"#
));
assert_eq!(actual.out, r#"{"foo": "c","bar": "d"}"#); assert_eq!(actual.out, r#"{"foo": "c","bar": "d"}"#);
} }
@ -63,31 +53,23 @@ fn each_no_args_in_block() {
#[test] #[test]
fn each_implicit_it_in_block() { fn each_implicit_it_in_block() {
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats",
r#" "echo [[foo bar]; [a b] [c d] [e f]] | each { |it| nu --testbin cococo $it.foo } | str join"
echo [[foo bar]; [a b] [c d] [e f]] | each { |it| nu --testbin cococo $it.foo } | str join );
"#
));
assert_eq!(actual.out, "ace"); assert_eq!(actual.out, "ace");
} }
#[test] #[test]
fn each_uses_enumerate_index() { fn each_uses_enumerate_index() {
let actual = nu!( let actual = nu!("[7 8 9 10] | enumerate | each {|el| $el.index } | to nuon");
cwd: ".", pipeline(
r#"[7 8 9 10] | enumerate | each {|el| $el.index } | to nuon"#
));
assert_eq!(actual.out, "[0, 1, 2, 3]"); assert_eq!(actual.out, "[0, 1, 2, 3]");
} }
#[test] #[test]
fn each_while_uses_enumerate_index() { fn each_while_uses_enumerate_index() {
let actual = nu!( let actual = nu!("[7 8 9 10] | enumerate | each while {|el| $el.index } | to nuon");
cwd: ".", pipeline(
r#"[7 8 9 10] | enumerate | each while {|el| $el.index } | to nuon"#
));
assert_eq!(actual.out, "[0, 1, 2, 3]"); assert_eq!(actual.out, "[0, 1, 2, 3]");
} }

View file

@ -1,61 +1,36 @@
use nu_test_support::{nu, pipeline}; use nu_test_support::nu;
#[test] #[test]
fn echo_range_is_lazy() { fn echo_range_is_lazy() {
let actual = nu!( let actual = nu!("echo 1..10000000000 | first 3 | to json --raw");
cwd: "tests/fixtures/formats", pipeline(
r#"
echo 1..10000000000 | first 3 | to json --raw
"#
));
assert_eq!(actual.out, "[1,2,3]"); assert_eq!(actual.out, "[1,2,3]");
} }
#[test] #[test]
fn echo_range_handles_inclusive() { fn echo_range_handles_inclusive() {
let actual = nu!( let actual = nu!("echo 1..3 | each { |x| $x } | to json --raw");
cwd: "tests/fixtures/formats", pipeline(
r#"
echo 1..3 | each { |x| $x } | to json --raw
"#
));
assert_eq!(actual.out, "[1,2,3]"); assert_eq!(actual.out, "[1,2,3]");
} }
#[test] #[test]
fn echo_range_handles_exclusive() { fn echo_range_handles_exclusive() {
let actual = nu!( let actual = nu!("echo 1..<3 | each { |x| $x } | to json --raw");
cwd: "tests/fixtures/formats", pipeline(
r#"
echo 1..<3 | each { |x| $x } | to json --raw
"#
));
assert_eq!(actual.out, "[1,2]"); assert_eq!(actual.out, "[1,2]");
} }
#[test] #[test]
fn echo_range_handles_inclusive_down() { fn echo_range_handles_inclusive_down() {
let actual = nu!( let actual = nu!("echo 3..1 | each { |it| $it } | to json --raw");
cwd: "tests/fixtures/formats", pipeline(
r#"
echo 3..1 | each { |it| $it } | to json --raw
"#
));
assert_eq!(actual.out, "[3,2,1]"); assert_eq!(actual.out, "[3,2,1]");
} }
#[test] #[test]
fn echo_range_handles_exclusive_down() { fn echo_range_handles_exclusive_down() {
let actual = nu!( let actual = nu!("echo 3..<1 | each { |it| $it } | to json --raw");
cwd: "tests/fixtures/formats", pipeline(
r#"
echo 3..<1 | each { |it| $it } | to json --raw
"#
));
assert_eq!(actual.out, "[3,2]"); assert_eq!(actual.out, "[3,2]");
} }

View file

@ -2,8 +2,7 @@ use nu_test_support::{nu, pipeline};
#[test] #[test]
fn reports_emptiness() { fn reports_emptiness() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline(
r#" r#"
[[] '' {} null] [[] '' {} null]
| all {|| | all {||
@ -17,8 +16,7 @@ fn reports_emptiness() {
#[test] #[test]
fn reports_nonemptiness() { fn reports_nonemptiness() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline(
r#" r#"
[[1] ' ' {a:1} 0] [[1] ' ' {a:1} 0]
| any {|| | any {||
@ -32,14 +30,13 @@ fn reports_nonemptiness() {
#[test] #[test]
fn reports_emptiness_by_columns() { fn reports_emptiness_by_columns() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline( "
r#"
[{a:1 b:null c:null} {a:2 b:null c:null}] [{a:1 b:null c:null} {a:2 b:null c:null}]
| any {|| | any {||
is-empty b c is-empty b c
} }
"# "
)); ));
assert_eq!(actual.out, "true"); assert_eq!(actual.out, "true");
@ -47,14 +44,13 @@ fn reports_emptiness_by_columns() {
#[test] #[test]
fn reports_nonemptiness_by_columns() { fn reports_nonemptiness_by_columns() {
let actual = nu!( let actual = nu!(pipeline(
cwd: ".", pipeline( "
r#"
[{a:1 b:null c:3} {a:null b:5 c:2}] [{a:1 b:null c:3} {a:null b:5 c:2}]
| any {|| | any {||
is-empty a b is-empty a b
} }
"# "
)); ));
assert_eq!(actual.out, "false"); assert_eq!(actual.out, "false");

View file

@ -28,7 +28,7 @@ fn knows_the_filesystems_entered() {
nu!( nu!(
cwd: dirs.test(), cwd: dirs.test(),
r#" "
enter expected enter expected
mkdir recycled mkdir recycled
enter ../red_pill enter ../red_pill
@ -47,7 +47,7 @@ fn knows_the_filesystems_entered() {
n n
rm blue_pill --recursive rm blue_pill --recursive
exit exit
"# "
); );
assert!(!red_pill_dir.exists()); assert!(!red_pill_dir.exists());

View file

@ -1,13 +1,8 @@
use nu_test_support::{nu, pipeline}; use nu_test_support::nu;
#[test] #[test]
fn error_label_works() { fn error_label_works() {
let actual = nu!( let actual = nu!("error make {msg:foo label:{text:unseen}}");
cwd: ".", pipeline(
r#"
error make {msg:foo label:{text:unseen}}
"#
));
assert!(actual.err.contains("unseen")); assert!(actual.err.contains("unseen"));
assert!(actual.err.contains("╰──")); assert!(actual.err.contains("╰──"));
@ -15,24 +10,14 @@ fn error_label_works() {
#[test] #[test]
fn no_span_if_unspanned() { fn no_span_if_unspanned() {
let actual = nu!( let actual = nu!("error make -u {msg:foo label:{text:unseen}}");
cwd: ".", pipeline(
r#"
error make -u {msg:foo label:{text:unseen}}
"#
));
assert!(!actual.err.contains("unseen")); assert!(!actual.err.contains("unseen"));
} }
#[test] #[test]
fn error_start_bigger_than_end_should_fail() { fn error_start_bigger_than_end_should_fail() {
let actual = nu!( let actual = nu!("error make {msg: foo label: {text: bar start 456 end 123}}");
cwd: ".", pipeline(
r#"
error make {msg: foo label: {text: bar start 456 end 123}}
"#
));
assert!(!actual.err.contains("invalid error format")); assert!(!actual.err.contains("invalid error format"));
assert!(!actual assert!(!actual

View file

@ -14,12 +14,12 @@ fn gets_all_rows_by_every_zero() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| every 0 | every 0
| to json --raw | to json --raw
"# "
)); ));
assert_eq!( assert_eq!(
@ -41,12 +41,12 @@ fn gets_no_rows_by_every_skip_zero() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| every 0 --skip | every 0 --skip
| to json --raw | to json --raw
"# "
)); ));
assert_eq!(actual.out, "[]"); assert_eq!(actual.out, "[]");
@ -65,12 +65,12 @@ fn gets_all_rows_by_every_one() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| every 1 | every 1
| to json --raw | to json --raw
"# "
)); ));
assert_eq!( assert_eq!(
@ -92,12 +92,12 @@ fn gets_no_rows_by_every_skip_one() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| every 1 --skip | every 1 --skip
| to json --raw | to json --raw
"# "
)); ));
assert_eq!(actual.out, "[]"); assert_eq!(actual.out, "[]");
@ -116,19 +116,14 @@ fn gets_first_row_by_every_too_much() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| every 999 | every 999
"# "
)); ));
let expected = nu!( let expected = nu!( cwd: dirs.test(), "echo [ amigos.txt ]");
cwd: dirs.test(), pipeline(
r#"
echo [ amigos.txt ]
"#
));
assert_eq!(actual.out, expected.out); assert_eq!(actual.out, expected.out);
}) })
@ -146,12 +141,12 @@ fn gets_all_rows_except_first_by_every_skip_too_much() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| every 999 --skip | every 999 --skip
| to json --raw | to json --raw
"# "
)); ));
assert_eq!(actual.out, r#"["arepas.clu","los.txt","tres.txt"]"#); assert_eq!(actual.out, r#"["arepas.clu","los.txt","tres.txt"]"#);
@ -171,12 +166,12 @@ fn gets_every_third_row() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| every 3 | every 3
| to json --raw | to json --raw
"# "
)); ));
assert_eq!(actual.out, r#"["amigos.txt","quatro.txt"]"#); assert_eq!(actual.out, r#"["amigos.txt","quatro.txt"]"#);
@ -196,12 +191,12 @@ fn skips_every_third_row() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" "
ls ls
| get name | get name
| every 3 --skip | every 3 --skip
| to json --raw | to json --raw
"# "
)); ));
assert_eq!(actual.out, r#"["arepas.clu","los.txt","tres.txt"]"#); assert_eq!(actual.out, r#"["arepas.clu","los.txt","tres.txt"]"#);