From acd7c98c39404c5a5b7a168455c2537c967b21f8 Mon Sep 17 00:00:00 2001 From: nicolb2305 Date: Thu, 18 May 2023 01:55:26 +0200 Subject: [PATCH] Removes unnecessary cwd and pipeline from various tests (#9202) # Description Cleans up various tests that unnecessarily use the `cwd` argument of `nu!`, and the `pipeline` function for single line commands. Also replaces some unnecessary raw strings with normal strings. Part of #8670. # User-Facing Changes None # Tests + Formatting All checks pass # After Submitting --- crates/nu-color-config/src/style_computer.rs | 2 +- crates/nu-command/src/strings/split/words.rs | 6 +-- crates/nu-command/tests/commands/alias.rs | 7 ++-- crates/nu-command/tests/commands/all.rs | 38 +++++++++---------- crates/nu-command/tests/commands/any.rs | 34 ++++++++--------- crates/nu-command/tests/commands/each.rs | 26 +++---------- .../nu-command/tests/commands/export_def.rs | 9 +---- crates/nu-command/tests/commands/fill.rs | 18 ++------- crates/nu-command/tests/commands/first.rs | 27 +++++-------- crates/nu-command/tests/commands/get.rs | 2 +- crates/nu-command/tests/commands/help.rs | 16 ++++---- crates/nu-command/tests/commands/join.rs | 14 +++---- crates/nu-command/tests/commands/last.rs | 13 +++---- 13 files changed, 86 insertions(+), 126 deletions(-) diff --git a/crates/nu-color-config/src/style_computer.rs b/crates/nu-color-config/src/style_computer.rs index 4c2b47de9f..a1767950e6 100644 --- a/crates/nu-color-config/src/style_computer.rs +++ b/crates/nu-color-config/src/style_computer.rs @@ -270,7 +270,7 @@ fn test_computable_style_closure_errors() { };"#, "[bell] | table", ]; - let actual_repl = nu!(cwd: ".", nu_repl_code(&inp)); + let actual_repl = nu!(nu_repl_code(&inp)); // Check that the error was printed assert!(actual_repl.err.contains("type mismatch for operator")); // Check that the value was printed diff --git a/crates/nu-command/src/strings/split/words.rs b/crates/nu-command/src/strings/split/words.rs index 9c7eeb4207..fe534f4e1d 100644 --- a/crates/nu-command/src/strings/split/words.rs +++ b/crates/nu-command/src/strings/split/words.rs @@ -363,17 +363,17 @@ fn split_words_helper( #[cfg(test)] mod test { use super::*; - use nu_test_support::{nu, pipeline}; + use nu_test_support::nu; #[test] fn test_incompat_flags() { - let out = nu!(cwd: ".", pipeline("'a' | split words -bg -l 2")); + let out = nu!("'a' | split words -bg -l 2"); assert!(out.err.contains("incompatible_parameters")); } #[test] fn test_incompat_flags_2() { - let out = nu!(cwd: ".", pipeline("'a' | split words -g")); + let out = nu!("'a' | split words -g"); assert!(out.err.contains("incompatible_parameters")); } diff --git a/crates/nu-command/tests/commands/alias.rs b/crates/nu-command/tests/commands/alias.rs index 5cd4fd9adc..8c1ad79488 100644 --- a/crates/nu-command/tests/commands/alias.rs +++ b/crates/nu-command/tests/commands/alias.rs @@ -71,9 +71,8 @@ fn cant_alias_keyword() { #[test] fn alias_wont_recurse() { - let actual = nu!( - cwd: ".", pipeline( - r#" + let actual = nu!(pipeline( + " module myspamsymbol { export def myfoosymbol [prefix: string, msg: string] { $prefix + $msg @@ -82,7 +81,7 @@ fn alias_wont_recurse() { use myspamsymbol myfoosymbol; alias myfoosymbol = myfoosymbol 'hello'; myfoosymbol ' world' - "# + " )); assert_eq!(actual.out, "hello world"); diff --git a/crates/nu-command/tests/commands/all.rs b/crates/nu-command/tests/commands/all.rs index acb5d8b1c4..bcf6f86a45 100644 --- a/crates/nu-command/tests/commands/all.rs +++ b/crates/nu-command/tests/commands/all.rs @@ -4,8 +4,8 @@ use nu_test_support::{nu, pipeline}; fn checks_all_rows_are_true() { let actual = nu!(pipeline( r#" - echo [ "Andrés", "Andrés", "Andrés" ] - | all {|it| $it == "Andrés" } + echo [ "Andrés", "Andrés", "Andrés" ] + | all {|it| $it == "Andrés" } "# )); @@ -14,14 +14,14 @@ fn checks_all_rows_are_true() { #[test] fn checks_all_rows_are_false_with_param() { - let actual = nu!(r#" [1, 2, 3, 4] | all { |a| $a >= 5 } "#); + let actual = nu!(" [1, 2, 3, 4] | all { |a| $a >= 5 } "); assert_eq!(actual.out, "false"); } #[test] fn checks_all_rows_are_true_with_param() { - let actual = nu!(r#" [1, 2, 3, 4] | all { |a| $a < 5 } "#); + let actual = nu!(" [1, 2, 3, 4] | all { |a| $a < 5 } "); assert_eq!(actual.out, "true"); } @@ -29,16 +29,16 @@ fn checks_all_rows_are_true_with_param() { #[test] fn checks_all_columns_of_a_table_is_true() { let actual = nu!(pipeline( - r#" - echo [ - [ first_name, last_name, rusty_at, likes ]; - [ Andrés, Robalino, '10/11/2013', 1 ] - [ JT, Turner, '10/12/2013', 1 ] - [ Darren, Schroeder, '10/11/2013', 1 ] - [ Yehuda, Katz, '10/11/2013', 1 ] - ] - | all {|x| $x.likes > 0 } - "# + " + echo [ + [ first_name, last_name, rusty_at, likes ]; + [ Andrés, Robalino, '10/11/2013', 1 ] + [ JT, Turner, '10/12/2013', 1 ] + [ Darren, Schroeder, '10/11/2013', 1 ] + [ Yehuda, Katz, '10/11/2013', 1 ] + ] + | all {|x| $x.likes > 0 } + " )); assert_eq!(actual.out, "true"); @@ -60,35 +60,35 @@ fn checks_if_all_returns_error_with_invalid_command() { #[test] fn works_with_1_param_blocks() { - let actual = nu!(r#"[1 2 3] | all {|e| print $e | true }"#); + let actual = nu!("[1 2 3] | all {|e| print $e | true }"); assert_eq!(actual.out, "123true"); } #[test] fn works_with_0_param_blocks() { - let actual = nu!(r#"[1 2 3] | all {|| print $in | true }"#); + let actual = nu!("[1 2 3] | all {|| print $in | true }"); assert_eq!(actual.out, "123true"); } #[test] fn early_exits_with_1_param_blocks() { - let actual = nu!(r#"[1 2 3] | all {|e| print $e | false }"#); + let actual = nu!("[1 2 3] | all {|e| print $e | false }"); assert_eq!(actual.out, "1false"); } #[test] fn early_exits_with_0_param_blocks() { - let actual = nu!(r#"[1 2 3] | all {|| print $in | false }"#); + let actual = nu!("[1 2 3] | all {|| print $in | false }"); assert_eq!(actual.out, "1false"); } #[test] fn all_uses_enumerate_index() { - let actual = nu!(r#"[7 8 9] | enumerate | all {|el| print $el.index | true }"#); + let actual = nu!("[7 8 9] | enumerate | all {|el| print $el.index | true }"); assert_eq!(actual.out, "012true"); } diff --git a/crates/nu-command/tests/commands/any.rs b/crates/nu-command/tests/commands/any.rs index b6d195d8c1..0e43f26cfd 100644 --- a/crates/nu-command/tests/commands/any.rs +++ b/crates/nu-command/tests/commands/any.rs @@ -4,8 +4,8 @@ use nu_test_support::{nu, pipeline}; fn checks_any_row_is_true() { let actual = nu!(pipeline( r#" - echo [ "Ecuador", "USA", "New Zealand" ] - | any {|it| $it == "New Zealand" } + echo [ "Ecuador", "USA", "New Zealand" ] + | any {|it| $it == "New Zealand" } "# )); @@ -15,16 +15,16 @@ fn checks_any_row_is_true() { #[test] fn checks_any_column_of_a_table_is_true() { let actual = nu!(pipeline( - r#" - echo [ - [ first_name, last_name, rusty_at, likes ]; - [ Andrés, Robalino, '10/11/2013', 1 ] - [ JT, Turner, '10/12/2013', 1 ] - [ Darren, Schroeder, '10/11/2013', 1 ] - [ Yehuda, Katz, '10/11/2013', 1 ] - ] - | any {|x| $x.rusty_at == '10/12/2013' } - "# + " + echo [ + [ first_name, last_name, rusty_at, likes ]; + [ Andrés, Robalino, '10/11/2013', 1 ] + [ JT, Turner, '10/12/2013', 1 ] + [ Darren, Schroeder, '10/11/2013', 1 ] + [ Yehuda, Katz, '10/11/2013', 1 ] + ] + | any {|x| $x.rusty_at == '10/12/2013' } + " )); assert_eq!(actual.out, "true"); @@ -46,35 +46,35 @@ fn checks_if_any_returns_error_with_invalid_command() { #[test] fn works_with_1_param_blocks() { - let actual = nu!(r#"[1 2 3] | any {|e| print $e | false }"#); + let actual = nu!("[1 2 3] | any {|e| print $e | false }"); assert_eq!(actual.out, "123false"); } #[test] fn works_with_0_param_blocks() { - let actual = nu!(r#"[1 2 3] | any {|| print $in | false }"#); + let actual = nu!("[1 2 3] | any {|| print $in | false }"); assert_eq!(actual.out, "123false"); } #[test] fn early_exits_with_1_param_blocks() { - let actual = nu!(r#"[1 2 3] | any {|e| print $e | true }"#); + let actual = nu!("[1 2 3] | any {|e| print $e | true }"); assert_eq!(actual.out, "1true"); } #[test] fn early_exits_with_0_param_blocks() { - let actual = nu!(r#"[1 2 3] | any {|| print $in | true }"#); + let actual = nu!("[1 2 3] | any {|| print $in | true }"); assert_eq!(actual.out, "1true"); } #[test] fn any_uses_enumerate_index() { - let actual = nu!(r#"[7 8 9] | enumerate | any {|el| print $el.index | false }"#); + let actual = nu!("[7 8 9] | enumerate | any {|el| print $el.index | false }"); assert_eq!(actual.out, "012false"); } diff --git a/crates/nu-command/tests/commands/each.rs b/crates/nu-command/tests/commands/each.rs index 750e108648..599597e66c 100644 --- a/crates/nu-command/tests/commands/each.rs +++ b/crates/nu-command/tests/commands/each.rs @@ -2,50 +2,35 @@ use nu_test_support::nu; #[test] fn each_works_separately() { - let actual = nu!( - cwd: "tests/fixtures/formats", - "echo [1 2 3] | each { |it| echo $it 10 | math sum } | to json -r" - ); + let actual = nu!("echo [1 2 3] | each { |it| echo $it 10 | math sum } | to json -r"); assert_eq!(actual.out, "[11,12,13]"); } #[test] fn each_group_works() { - let actual = nu!( - cwd: "tests/fixtures/formats", - "echo [1 2 3 4 5 6] | group 3 | to json --raw" - ); + let actual = nu!("echo [1 2 3 4 5 6] | group 3 | to json --raw"); assert_eq!(actual.out, "[[1,2,3],[4,5,6]]"); } #[test] fn each_window() { - let actual = nu!( - cwd: "tests/fixtures/formats", - "echo [1 2 3 4] | window 3 | to json --raw" - ); + let actual = nu!("echo [1 2 3 4] | window 3 | to json --raw"); assert_eq!(actual.out, "[[1,2,3],[2,3,4]]"); } #[test] fn each_window_stride() { - let actual = nu!( - cwd: "tests/fixtures/formats", - "echo [1 2 3 4 5 6] | window 3 -s 2 | to json --raw" - ); + let actual = nu!("echo [1 2 3 4 5 6] | window 3 -s 2 | to json --raw"); assert_eq!(actual.out, "[[1,2,3],[3,4,5]]"); } #[test] fn each_no_args_in_block() { - let actual = nu!( - cwd: "tests/fixtures/formats", - "echo [[foo bar]; [a b] [c d] [e f]] | each {|i| $i | to json -r } | get 1" - ); + let actual = nu!("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"}"#); } @@ -53,7 +38,6 @@ fn each_no_args_in_block() { #[test] fn each_implicit_it_in_block() { let actual = nu!( - cwd: "tests/fixtures/formats", "echo [[foo bar]; [a b] [c d] [e f]] | each { |it| nu --testbin cococo $it.foo } | str join" ); diff --git a/crates/nu-command/tests/commands/export_def.rs b/crates/nu-command/tests/commands/export_def.rs index e4cfca21ed..5b6edcc8a6 100644 --- a/crates/nu-command/tests/commands/export_def.rs +++ b/crates/nu-command/tests/commands/export_def.rs @@ -1,13 +1,8 @@ -use nu_test_support::{nu, pipeline}; +use nu_test_support::nu; #[test] fn export_subcommands_help() { - let actual = nu!( - cwd: ".", pipeline( - r#" - export def -h - "# - )); + let actual = nu!("export def -h"); assert!(actual .out diff --git a/crates/nu-command/tests/commands/fill.rs b/crates/nu-command/tests/commands/fill.rs index 972bb562cf..3fe02b92cf 100644 --- a/crates/nu-command/tests/commands/fill.rs +++ b/crates/nu-command/tests/commands/fill.rs @@ -2,29 +2,19 @@ use nu_test_support::{nu, pipeline}; #[test] fn string_fill_plain() { - let actual = nu!( - cwd: ".", - pipeline( - r#" - "abc" | fill --alignment center --character "+" --width 5 - "# - ) - ); + let actual = nu!(r#""abc" | fill --alignment center --character "+" --width 5"#); assert_eq!(actual.out, "+abc+"); } #[test] fn string_fill_fancy() { - let actual = nu!( - cwd: ".", - pipeline( - r#" + let actual = nu!(pipeline( + r#" $"(ansi red)a(ansi green)\u{65}\u{308}(ansi cyan)c(ansi reset)" | fill --alignment center --character "+" --width 5 "# - ) - ); + )); assert_eq!( actual.out, diff --git a/crates/nu-command/tests/commands/first.rs b/crates/nu-command/tests/commands/first.rs index fb53b6b023..1c3dc4ccd7 100644 --- a/crates/nu-command/tests/commands/first.rs +++ b/crates/nu-command/tests/commands/first.rs @@ -68,13 +68,12 @@ fn gets_first_row_when_no_amount_given() { #[test] fn gets_first_row_as_list_when_amount_given() { - let actual = nu!( - cwd: ".", pipeline( + let actual = nu!(pipeline( r#" - [1, 2, 3] - | first 1 - | describe - "# + [1, 2, 3] + | first 1 + | describe + "# )); assert_eq!(actual.out, "list (stream)"); @@ -83,24 +82,18 @@ fn gets_first_row_as_list_when_amount_given() { #[test] // covers a situation where `first` used to behave strangely on list input fn works_with_binary_list() { - let actual = nu!( - cwd: ".", pipeline( - r#" - ([0x[01 11]] | first) == 0x[01 11] - "# - )); + let actual = nu!("([0x[01 11]] | first) == 0x[01 11]"); assert_eq!(actual.out, "true"); } #[test] fn errors_on_negative_rows() { - let actual = nu!( - cwd: ".", pipeline( + let actual = nu!(pipeline( r#" - [1, 2, 3] - | first -10 - "# + [1, 2, 3] + | first -10 + "# )); assert!(actual.err.contains("use a positive value")); diff --git a/crates/nu-command/tests/commands/get.rs b/crates/nu-command/tests/commands/get.rs index b532bae690..e9b86089ac 100644 --- a/crates/nu-command/tests/commands/get.rs +++ b/crates/nu-command/tests/commands/get.rs @@ -176,7 +176,7 @@ fn errors_fetching_by_index_out_of_bounds() { #[test] fn errors_fetching_by_accessing_empty_list() { - let actual = nu!(cwd: ".", pipeline(r#"[] | get 3"#)); + let actual = nu!("[] | get 3"); assert!(actual.err.contains("Row number too large (empty content)"),); } diff --git a/crates/nu-command/tests/commands/help.rs b/crates/nu-command/tests/commands/help.rs index ec9df6577d..b0c61ce7af 100644 --- a/crates/nu-command/tests/commands/help.rs +++ b/crates/nu-command/tests/commands/help.rs @@ -19,13 +19,13 @@ fn help_commands_length() { #[test] fn help_shows_signature() { - let actual = nu!(cwd: ".", pipeline("help str distance")); + let actual = nu!("help str distance"); assert!(actual .out .contains(" | str distance -> ")); // don't show signature for parser keyword - let actual = nu!(cwd: ".", pipeline("help alias")); + let actual = nu!("help alias"); assert!(!actual.out.contains("Signatures")); } @@ -36,7 +36,7 @@ fn help_aliases() { "alias SPAM = print 'spam'", "help aliases | where name == SPAM | length", ]; - let actual = nu!(cwd: ".", nu_repl_code(code)); + let actual = nu!(nu_repl_code(code)); assert_eq!(actual.out, "1"); } @@ -289,21 +289,21 @@ fn help_usage_extra_usage_command() { "#, )]); - let actual = nu!(cwd: dirs.test(), pipeline("use spam.nu *; help modules spam")); + let actual = nu!(cwd: dirs.test(), "use spam.nu *; help modules spam"); assert!(actual.out.contains("module_line1")); assert!(actual.out.contains("module_line2")); let actual = nu!(cwd: dirs.test(), - pipeline("use spam.nu *; help modules | where name == spam | get 0.usage")); + "use spam.nu *; help modules | where name == spam | get 0.usage"); assert!(actual.out.contains("module_line1")); assert!(!actual.out.contains("module_line2")); - let actual = nu!(cwd: dirs.test(), pipeline("use spam.nu *; help commands foo")); + let actual = nu!(cwd: dirs.test(), "use spam.nu *; help commands foo"); assert!(actual.out.contains("def_line1")); assert!(actual.out.contains("def_line2")); let actual = nu!(cwd: dirs.test(), - pipeline("use spam.nu *; help commands | where name == foo | get 0.usage")); + "use spam.nu *; help commands | where name == foo | get 0.usage"); assert!(actual.out.contains("def_line1")); assert!(!actual.out.contains("def_line2")); }) @@ -356,7 +356,7 @@ fn help_modules_main_1() { "help spam", ]; - let actual = nu!(cwd: ".", pipeline(&inp.join("; "))); + let actual = nu!(&inp.join("; ")); assert!(actual.out.contains(" spam")); } diff --git a/crates/nu-command/tests/commands/join.rs b/crates/nu-command/tests/commands/join.rs index 4c66994e02..69aa39f59a 100644 --- a/crates/nu-command/tests/commands/join.rs +++ b/crates/nu-command/tests/commands/join.rs @@ -84,7 +84,7 @@ fn do_cases_where_result_is_same_between_join_types(join_type: &str) { (("[{a: 1}]", "[{a: 1 b: 1}]", "a"), "[[a, b]; [1, 1]]"), ] { let expr = format!("{} | join {} {} {} | to nuon", left, right, join_type, on); - let actual = nu!(cwd: ".", expr).out; + let actual = nu!(expr).out; assert_eq!(actual, expected); // Test again with streaming input (using `each` to convert the input into a ListStream) @@ -93,7 +93,7 @@ fn do_cases_where_result_is_same_between_join_types(join_type: &str) { "{} | {} join {} {} {} | to nuon", left, to_list_stream, right, join_type, on ); - let actual = nu!(cwd: ".", expr).out; + let actual = nu!(expr).out; assert_eq!(actual, expected); } } @@ -199,7 +199,7 @@ fn do_cases_where_result_differs_between_join_types(join_type: &str) { for (join_type_, expected) in join_types { if join_type_ == join_type { let expr = format!("{} | join {} {} {} | to nuon", left, right, join_type, on); - let actual = nu!(cwd: ".", expr).out; + let actual = nu!(expr).out; assert_eq!(actual, expected); // Test again with streaming input (using `each` to convert the input into a ListStream) @@ -208,7 +208,7 @@ fn do_cases_where_result_differs_between_join_types(join_type: &str) { "{} | {} join {} {} {} | to nuon", left, to_list_stream, right, join_type, on ); - let actual = nu!(cwd: ".", expr).out; + let actual = nu!(expr).out; assert_eq!(actual, expected); } } @@ -339,7 +339,7 @@ fn do_cases_where_result_differs_between_join_types_with_different_join_keys(joi for (join_type_, expected) in join_types { if join_type_ == join_type { let expr = format!("{} | join {} {} {} {} | to nuon", left, right, join_type, left_on, right_on); - let actual = nu!(cwd: ".", expr).out; + let actual = nu!(expr).out; assert_eq!(actual, expected); // Test again with streaming input (using `each` to convert the input into a ListStream) @@ -348,7 +348,7 @@ fn do_cases_where_result_differs_between_join_types_with_different_join_keys(joi "{} | {} join {} {} {} {} | to nuon", left, to_list_stream, right, join_type, left_on, right_on ); - let actual = nu!(cwd: ".", expr).out; + let actual = nu!(expr).out; assert_eq!(actual, expected); } } @@ -366,7 +366,7 @@ fn test_alternative_table_syntax() { (("[[a]; [1]]", "[[a]; [1]]", "a"), "[[a]; [1]]"), ] { let expr = format!("{} | join {} {} {} | to nuon", left, right, join_type, on); - let actual = nu!(cwd: ".", &expr).out; + let actual = nu!(&expr).out; assert_eq!(actual, expected, "Expression was {}", &expr); } } diff --git a/crates/nu-command/tests/commands/last.rs b/crates/nu-command/tests/commands/last.rs index cf7cc6048e..af0029dba5 100644 --- a/crates/nu-command/tests/commands/last.rs +++ b/crates/nu-command/tests/commands/last.rs @@ -81,12 +81,11 @@ fn gets_last_row_as_list_when_amount_given() { #[test] fn last_errors_on_negative_index() { - let actual = nu!( - cwd: ".", pipeline( - r#" - [1, 2, 3] - | last -2 - "# + let actual = nu!(pipeline( + " + [1, 2, 3] + | last -2 + " )); assert!(actual.err.contains("use a positive value")); @@ -94,7 +93,7 @@ fn last_errors_on_negative_index() { #[test] fn fail_on_non_iterator() { - let actual = nu!(cwd: ".", pipeline("1 | last")); + let actual = nu!("1 | last"); assert!(actual.err.contains("only_supports_this_input_type")); }