From 96e5fc05a37bbd632867219b18fb85ecbb37f683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Thu, 7 May 2020 06:03:43 -0500 Subject: [PATCH] Pick->Select rename. Integration tests changes. (#1725) Pick->Select rename. Integration tests changes. --- crates/nu-cli/src/cli.rs | 2 +- crates/nu-cli/src/commands.rs | 4 +- .../src/commands/{pick.rs => select.rs} | 20 ++-- crates/nu-cli/tests/commands/alias.rs | 2 +- crates/nu-cli/tests/commands/append.rs | 2 +- crates/nu-cli/tests/commands/calc.rs | 8 +- crates/nu-cli/tests/commands/cd.rs | 70 ++++++++------ crates/nu-cli/tests/commands/compact.rs | 4 +- crates/nu-cli/tests/commands/cp.rs | 8 +- crates/nu-cli/tests/commands/default.rs | 2 +- crates/nu-cli/tests/commands/drop.rs | 2 +- crates/nu-cli/tests/commands/each.rs | 2 +- crates/nu-cli/tests/commands/enter.rs | 8 +- crates/nu-cli/tests/commands/first.rs | 6 +- crates/nu-cli/tests/commands/format.rs | 4 +- crates/nu-cli/tests/commands/get.rs | 58 ++++++------ crates/nu-cli/tests/commands/group_by.rs | 8 +- crates/nu-cli/tests/commands/headers.rs | 4 +- crates/nu-cli/tests/commands/histogram.rs | 9 +- crates/nu-cli/tests/commands/insert.rs | 2 +- crates/nu-cli/tests/commands/is_empty.rs | 6 +- crates/nu-cli/tests/commands/keep.rs | 2 +- crates/nu-cli/tests/commands/keep_until.rs | 2 +- crates/nu-cli/tests/commands/keep_while.rs | 2 +- crates/nu-cli/tests/commands/last.rs | 6 +- crates/nu-cli/tests/commands/lines.rs | 2 +- crates/nu-cli/tests/commands/ls.rs | 18 ++-- crates/nu-cli/tests/commands/math.rs | 24 ++--- crates/nu-cli/tests/commands/merge.rs | 2 +- crates/nu-cli/tests/commands/mod.rs | 2 +- crates/nu-cli/tests/commands/mv.rs | 6 +- crates/nu-cli/tests/commands/nth.rs | 4 +- crates/nu-cli/tests/commands/open.rs | 28 +++--- crates/nu-cli/tests/commands/parse.rs | 2 +- crates/nu-cli/tests/commands/prepend.rs | 2 +- crates/nu-cli/tests/commands/range.rs | 4 +- crates/nu-cli/tests/commands/rename.rs | 16 ++-- crates/nu-cli/tests/commands/reverse.rs | 2 +- crates/nu-cli/tests/commands/rm.rs | 16 ++-- .../tests/commands/{pick.rs => select.rs} | 18 ++-- crates/nu-cli/tests/commands/semicolon.rs | 4 +- crates/nu-cli/tests/commands/skip_until.rs | 4 +- crates/nu-cli/tests/commands/sort_by.rs | 4 +- crates/nu-cli/tests/commands/split_by.rs | 8 +- crates/nu-cli/tests/commands/split_column.rs | 2 +- crates/nu-cli/tests/commands/sum.rs | 4 +- crates/nu-cli/tests/commands/trim.rs | 6 +- crates/nu-cli/tests/commands/uniq.rs | 10 +- crates/nu-cli/tests/commands/update.rs | 4 +- crates/nu-cli/tests/commands/where_.rs | 24 ++--- crates/nu-cli/tests/commands/with_env.rs | 4 +- crates/nu-cli/tests/commands/wrap.rs | 4 +- .../nu-cli/tests/format_conversions/bson.rs | 2 +- crates/nu-cli/tests/format_conversions/csv.rs | 20 ++-- crates/nu-cli/tests/format_conversions/eml.rs | 10 +- .../nu-cli/tests/format_conversions/html.rs | 4 +- crates/nu-cli/tests/format_conversions/ics.rs | 4 +- .../nu-cli/tests/format_conversions/json.rs | 10 +- .../tests/format_conversions/markdown.rs | 4 +- crates/nu-cli/tests/format_conversions/ods.rs | 2 +- .../nu-cli/tests/format_conversions/sqlite.rs | 2 +- crates/nu-cli/tests/format_conversions/ssv.rs | 8 +- .../nu-cli/tests/format_conversions/toml.rs | 2 +- crates/nu-cli/tests/format_conversions/tsv.rs | 12 +-- crates/nu-cli/tests/format_conversions/url.rs | 2 +- crates/nu-cli/tests/format_conversions/vcf.rs | 4 +- .../nu-cli/tests/format_conversions/xlsx.rs | 2 +- .../nu-cli/tests/format_conversions/yaml.rs | 2 +- crates/nu-test-support/src/macros.rs | 91 ++++--------------- docs/commands/from-vcf.md | 2 +- docs/commands/save.md | 4 +- docs/commands/{pick.md => select.md} | 8 +- docs/commands/wrap.md | 4 +- tests/plugins/core_inc.rs | 20 ++-- tests/plugins/core_str.rs | 24 ++--- tests/shell/pipeline/commands/external.rs | 41 +++++---- tests/shell/pipeline/commands/internal.rs | 38 ++++---- tests/shell/pipeline/mod.rs | 2 +- 78 files changed, 380 insertions(+), 411 deletions(-) rename crates/nu-cli/src/commands/{pick.rs => select.rs} (93%) rename crates/nu-cli/tests/commands/{pick.rs => select.rs} (84%) rename docs/commands/{pick.md => select.md} (97%) diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index 3455aa178d..30b5ee14bc 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -285,7 +285,7 @@ pub fn create_default_context( whole_stream_command(Parse), // Column manipulation whole_stream_command(Reject), - whole_stream_command(Pick), + whole_stream_command(Select), whole_stream_command(Get), whole_stream_command(Update), whole_stream_command(Insert), diff --git a/crates/nu-cli/src/commands.rs b/crates/nu-cli/src/commands.rs index 488c263d1c..6c583dfeee 100644 --- a/crates/nu-cli/src/commands.rs +++ b/crates/nu-cli/src/commands.rs @@ -70,7 +70,6 @@ pub(crate) mod next; pub(crate) mod nth; pub(crate) mod open; pub(crate) mod parse; -pub(crate) mod pick; pub(crate) mod pivot; pub(crate) mod plugin; pub(crate) mod prepend; @@ -86,6 +85,7 @@ pub(crate) mod rm; pub(crate) mod run_alias; pub(crate) mod run_external; pub(crate) mod save; +pub(crate) mod select; pub(crate) mod shells; pub(crate) mod shuffle; pub(crate) mod size; @@ -194,7 +194,6 @@ pub(crate) use next::Next; pub(crate) use nth::Nth; pub(crate) use open::Open; pub(crate) use parse::Parse; -pub(crate) use pick::Pick; pub(crate) use pivot::Pivot; pub(crate) use prepend::Prepend; pub(crate) use prev::Previous; @@ -208,6 +207,7 @@ pub(crate) use reverse::Reverse; pub(crate) use rm::Remove; pub(crate) use run_external::RunExternalCommand; pub(crate) use save::Save; +pub(crate) use select::Select; pub(crate) use shells::Shells; pub(crate) use shuffle::Shuffle; pub(crate) use size::Size; diff --git a/crates/nu-cli/src/commands/pick.rs b/crates/nu-cli/src/commands/select.rs similarity index 93% rename from crates/nu-cli/src/commands/pick.rs rename to crates/nu-cli/src/commands/select.rs index 3d2d9090fc..215ec977e5 100644 --- a/crates/nu-cli/src/commands/pick.rs +++ b/crates/nu-cli/src/commands/select.rs @@ -10,19 +10,19 @@ use nu_source::span_for_spanned_list; use nu_value_ext::{as_string, get_data_by_column_path}; #[derive(Deserialize)] -struct PickArgs { +struct SelectArgs { rest: Vec, } -pub struct Pick; +pub struct Select; -impl WholeStreamCommand for Pick { +impl WholeStreamCommand for Select { fn name(&self) -> &str { - "pick" + "select" } fn signature(&self) -> Signature { - Signature::build("pick").rest( + Signature::build("select").rest( SyntaxShape::ColumnPath, "the columns to select from the table", ) @@ -37,19 +37,19 @@ impl WholeStreamCommand for Pick { args: CommandArgs, registry: &CommandRegistry, ) -> Result { - args.process(registry, pick)?.run() + args.process(registry, select)?.run() } } -fn pick( - PickArgs { rest: mut fields }: PickArgs, +fn select( + SelectArgs { rest: mut fields }: SelectArgs, RunnableContext { mut input, name, .. }: RunnableContext, ) -> Result { if fields.is_empty() { return Err(ShellError::labeled_error( - "Pick requires columns to pick", + "Select requires columns to select", "needs parameter", name, )); @@ -76,7 +76,7 @@ fn pick( if let PathMember { unspanned: UnspannedPathMember::String(column), .. } = path_member_tried { return ShellError::labeled_error_with_secondary( "No data to fetch.", - format!("Couldn't pick column \"{}\"", column), + format!("Couldn't select column \"{}\"", column), path_member_tried.span, format!("How about exploring it with \"get\"? Check the input is appropriate originating from here"), obj_source.tag.span) diff --git a/crates/nu-cli/tests/commands/alias.rs b/crates/nu-cli/tests/commands/alias.rs index 64d56e9ed1..acda5b8f2c 100644 --- a/crates/nu-cli/tests/commands/alias.rs +++ b/crates/nu-cli/tests/commands/alias.rs @@ -12,6 +12,6 @@ fn alias_args_work() { "# ); - assert_eq!(actual, "[1,2]"); + assert_eq!(actual.out, "[1,2]"); }) } diff --git a/crates/nu-cli/tests/commands/append.rs b/crates/nu-cli/tests/commands/append.rs index cbb0994f39..5207ad975f 100644 --- a/crates/nu-cli/tests/commands/append.rs +++ b/crates/nu-cli/tests/commands/append.rs @@ -25,6 +25,6 @@ fn adds_a_row_to_the_end() { "# )); - assert_eq!(actual, "pollo loco"); + assert_eq!(actual.out, "pollo loco"); }) } diff --git a/crates/nu-cli/tests/commands/calc.rs b/crates/nu-cli/tests/commands/calc.rs index c4953ef8e9..874ce68f97 100644 --- a/crates/nu-cli/tests/commands/calc.rs +++ b/crates/nu-cli/tests/commands/calc.rs @@ -9,7 +9,7 @@ fn calculates_two_plus_two() { "# )); - assert!(actual.contains("4.0")); + assert!(actual.out.contains("4.0")); } #[test] @@ -21,7 +21,7 @@ fn calculates_two_to_the_power_six() { "# )); - assert!(actual.contains("64.0")); + assert!(actual.out.contains("64.0")); } #[test] @@ -33,7 +33,7 @@ fn calculates_three_multiplied_by_five() { "# )); - assert!(actual.contains("15.0")); + assert!(actual.out.contains("15.0")); } #[test] @@ -45,5 +45,5 @@ fn calculates_twenty_four_divided_by_two() { "# )); - assert!(actual.contains("12.0")); + assert!(actual.out.contains("12.0")); } diff --git a/crates/nu-cli/tests/commands/cd.rs b/crates/nu-cli/tests/commands/cd.rs index d149c9755e..8d7b15bfbe 100644 --- a/crates/nu-cli/tests/commands/cd.rs +++ b/crates/nu-cli/tests/commands/cd.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::{Stub::EmptyFile, Stub::FileWithContent}; +use nu_test_support::nu; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error}; use std::path::PathBuf; #[test] @@ -14,7 +14,7 @@ fn filesystem_change_from_current_directory_using_relative_path() { "# ); - assert_eq!(PathBuf::from(actual), *dirs.test()); + assert_eq!(PathBuf::from(actual.out), *dirs.test()); }) } @@ -30,7 +30,7 @@ fn filesystem_change_from_current_directory_using_absolute_path() { dirs.formats() ); - assert_eq!(PathBuf::from(actual), dirs.formats()); + assert_eq!(PathBuf::from(actual.out), dirs.formats()); }) } @@ -49,7 +49,7 @@ fn filesystem_switch_back_to_previous_working_directory() { dirs.test() ); - assert_eq!(PathBuf::from(actual), dirs.test().join("odin")); + assert_eq!(PathBuf::from(actual.out), dirs.test().join("odin")); }) } @@ -66,7 +66,10 @@ fn filesytem_change_from_current_directory_using_relative_path_and_dash() { "# ); - assert_eq!(PathBuf::from(actual), dirs.test().join("odin").join("-")); + assert_eq!( + PathBuf::from(actual.out), + dirs.test().join("odin").join("-") + ); }) } @@ -81,7 +84,7 @@ fn filesystem_change_current_directory_to_parent_directory() { "# ); - assert_eq!(PathBuf::from(actual), *dirs.root()); + assert_eq!(PathBuf::from(actual.out), *dirs.root()); }) } @@ -98,7 +101,7 @@ fn filesystem_change_current_directory_to_two_parents_up_using_multiple_dots() { "# ); - assert_eq!(PathBuf::from(actual), *dirs.test()); + assert_eq!(PathBuf::from(actual.out), *dirs.test()); }) } @@ -118,7 +121,7 @@ fn filesystem_change_current_directory_to_parent_directory_after_delete_cwd() { dirs.test() ); - let actual = actual.split(',').nth(1).unwrap(); + let actual = actual.out.split(',').nth(1).unwrap(); assert_eq!(PathBuf::from(actual), *dirs.test().join("foo")); }) @@ -135,7 +138,7 @@ fn filesystem_change_to_home_directory() { "# ); - assert_eq!(Some(PathBuf::from(actual)), dirs::home_dir()); + assert_eq!(Some(PathBuf::from(actual.out)), dirs::home_dir()); }) } @@ -153,7 +156,7 @@ fn filesystem_change_to_a_directory_containing_spaces() { ); assert_eq!( - PathBuf::from(actual), + PathBuf::from(actual.out), dirs.test().join("robalino turner katz") ); }) @@ -164,34 +167,42 @@ fn filesystem_not_a_directory() { Playground::setup("cd_test_10", |dirs, sandbox| { sandbox.with_files(vec![EmptyFile("ferris_did_it.txt")]); - let actual = nu_error!( + let actual = nu!( cwd: dirs.test(), "cd ferris_did_it.txt" ); - assert!(actual.contains("ferris_did_it.txt"), "actual={:?}", actual); - assert!(actual.contains("is not a directory"), "actual={:?}", actual); + assert!( + actual.err.contains("ferris_did_it.txt"), + "actual={:?}", + actual.err + ); + assert!( + actual.err.contains("is not a directory"), + "actual={:?}", + actual.err + ); }) } #[test] fn filesystem_directory_not_found() { Playground::setup("cd_test_11", |dirs, _| { - let actual = nu_error!( + let actual = nu!( cwd: dirs.test(), "cd dir_that_does_not_exist" ); assert!( - actual.contains("dir_that_does_not_exist"), + actual.err.contains("dir_that_does_not_exist"), "actual={:?}", - actual + actual.err ); assert!( - actual.contains("directory not found"), + actual.err.contains("directory not found"), "actual={:?}", - actual + actual.err ); }) } @@ -211,7 +222,7 @@ fn filesystem_change_directory_to_symlink_relative() { "# ); - assert_eq!(PathBuf::from(actual), dirs.test().join("foo")); + assert_eq!(PathBuf::from(actual.out), dirs.test().join("foo")); }) } @@ -242,7 +253,7 @@ fn valuesystem_change_from_current_path_using_relative_path() { "# ); - assert_eq!(PathBuf::from(actual), PathBuf::from("/bin")); + assert_eq!(PathBuf::from(actual.out), PathBuf::from("/bin")); }) } @@ -276,7 +287,7 @@ fn valuesystem_change_from_current_path_using_absolute_path() { "# ); - assert_eq!(PathBuf::from(actual), PathBuf::from("/dependencies")); + assert_eq!(PathBuf::from(actual.out), PathBuf::from("/dependencies")); }) } @@ -312,7 +323,7 @@ fn valuesystem_switch_back_to_previous_working_path() { "# ); - assert_eq!(PathBuf::from(actual), PathBuf::from("/dependencies")); + assert_eq!(PathBuf::from(actual.out), PathBuf::from("/dependencies")); }) } @@ -346,7 +357,7 @@ fn valuesystem_change_from_current_path_using_relative_path_and_dash() { "# ); - assert_eq!(PathBuf::from(actual), PathBuf::from("/package/-")); + assert_eq!(PathBuf::from(actual.out), PathBuf::from("/package/-")); }) } @@ -373,7 +384,7 @@ fn valuesystem_change_current_path_to_parent_path() { "# ); - assert_eq!(PathBuf::from(actual), PathBuf::from("/package")); + assert_eq!(PathBuf::from(actual.out), PathBuf::from("/package")); }) } @@ -398,14 +409,17 @@ fn valuesystem_change_to_a_path_containing_spaces() { "# ); - assert_eq!(PathBuf::from(actual), PathBuf::from("/").join("pa que te")); + assert_eq!( + PathBuf::from(actual.out), + PathBuf::from("/").join("pa que te") + ); }) } #[test] fn valuesystem_path_not_found() { Playground::setup("cd_test_19", |dirs, _| { - let actual = nu_error!( + let actual = nu!( cwd: dirs.formats(), r#" enter cargo_sample.toml @@ -414,7 +428,7 @@ fn valuesystem_path_not_found() { "# ); - assert!(actual.contains("Can not change to path inside")); - assert!(actual.contains("No such path exists")); + assert!(actual.err.contains("Can not change to path inside")); + assert!(actual.err.contains("No such path exists")); }) } diff --git a/crates/nu-cli/tests/commands/compact.rs b/crates/nu-cli/tests/commands/compact.rs index 373958565e..7e3aaa9111 100644 --- a/crates/nu-cli/tests/commands/compact.rs +++ b/crates/nu-cli/tests/commands/compact.rs @@ -30,7 +30,7 @@ fn discards_rows_where_given_column_is_empty() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }); } #[test] @@ -47,6 +47,6 @@ fn discards_empty_rows_by_default() { "# )); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); }); } diff --git a/crates/nu-cli/tests/commands/cp.rs b/crates/nu-cli/tests/commands/cp.rs index 67a2a2da54..0249d53ed5 100644 --- a/crates/nu-cli/tests/commands/cp.rs +++ b/crates/nu-cli/tests/commands/cp.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::{files_exist_at, AbsoluteFile, Stub::EmptyFile}; +use nu_test_support::nu; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error}; use std::path::Path; #[test] @@ -34,13 +34,13 @@ fn copies_the_file_inside_directory_if_path_to_copy_is_directory() { #[test] fn error_if_attempting_to_copy_a_directory_to_another_directory() { Playground::setup("cp_test_3", |dirs, _| { - let actual = nu_error!( + let actual = nu!( cwd: dirs.formats(), "cp ../formats {}", dirs.test() ); - assert!(actual.contains("../formats")); - assert!(actual.contains("resolves to a directory (not copied)")); + assert!(actual.err.contains("../formats")); + assert!(actual.err.contains("resolves to a directory (not copied)")); }); } diff --git a/crates/nu-cli/tests/commands/default.rs b/crates/nu-cli/tests/commands/default.rs index aa2c94ef31..e341b4538d 100644 --- a/crates/nu-cli/tests/commands/default.rs +++ b/crates/nu-cli/tests/commands/default.rs @@ -31,6 +31,6 @@ fn adds_row_data_if_column_missing() { "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); }); } diff --git a/crates/nu-cli/tests/commands/drop.rs b/crates/nu-cli/tests/commands/drop.rs index 625f08ca62..1bdb26aac5 100644 --- a/crates/nu-cli/tests/commands/drop.rs +++ b/crates/nu-cli/tests/commands/drop.rs @@ -7,5 +7,5 @@ fn drop_rows() { r#"echo '[{"foo": 3}, {"foo": 8}, {"foo": 4}]' | from json | drop 2 | get foo | sum | echo $it"# ); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); } diff --git a/crates/nu-cli/tests/commands/each.rs b/crates/nu-cli/tests/commands/each.rs index 3700ebff87..bfffe2bf26 100644 --- a/crates/nu-cli/tests/commands/each.rs +++ b/crates/nu-cli/tests/commands/each.rs @@ -9,5 +9,5 @@ fn each_works_separately() { "# )); - assert_eq!(actual, "[11,12,13]"); + assert_eq!(actual.out, "[11,12,13]"); } diff --git a/crates/nu-cli/tests/commands/enter.rs b/crates/nu-cli/tests/commands/enter.rs index 27444fba73..2bc87e74ff 100644 --- a/crates/nu-cli/tests/commands/enter.rs +++ b/crates/nu-cli/tests/commands/enter.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::{files_exist_at, Stub::EmptyFile}; +use nu_test_support::nu; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error}; use std::path::Path; #[test] @@ -75,12 +75,12 @@ fn knows_the_filesystems_entered() { #[test] fn errors_if_file_not_found() { Playground::setup("enter_test_2", |dirs, _| { - let actual = nu_error!( + let actual = nu!( cwd: dirs.test(), "enter i_dont_exist.csv" ); - assert!(actual.contains("File could not be opened")); - assert!(actual.contains("file not found")); + assert!(actual.err.contains("File could not be opened")); + assert!(actual.err.contains("file not found")); }) } diff --git a/crates/nu-cli/tests/commands/first.rs b/crates/nu-cli/tests/commands/first.rs index 00b6bbcf1a..dbcba2573c 100644 --- a/crates/nu-cli/tests/commands/first.rs +++ b/crates/nu-cli/tests/commands/first.rs @@ -22,7 +22,7 @@ fn gets_first_rows_by_amount() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -46,7 +46,7 @@ fn gets_all_rows_if_amount_higher_than_all_rows() { "# )); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); }) } @@ -65,6 +65,6 @@ fn gets_first_row_when_no_amount_given() { "# )); - assert_eq!(actual, "1"); + assert_eq!(actual.out, "1"); }) } diff --git a/crates/nu-cli/tests/commands/format.rs b/crates/nu-cli/tests/commands/format.rs index 8701fc2d4c..eb44805517 100644 --- a/crates/nu-cli/tests/commands/format.rs +++ b/crates/nu-cli/tests/commands/format.rs @@ -12,7 +12,7 @@ fn creates_the_resulting_string_from_the_given_fields() { "# )); - assert_eq!(actual, "nu has license ISC"); + assert_eq!(actual.out, "nu has license ISC"); } #[test] @@ -26,5 +26,5 @@ fn given_fields_can_be_column_paths() { "# )); - assert_eq!(actual, "nu is a new type of shell"); + assert_eq!(actual.out, "nu is a new type of shell"); } diff --git a/crates/nu-cli/tests/commands/get.rs b/crates/nu-cli/tests/commands/get.rs index c824c6e9a2..53e071890a 100644 --- a/crates/nu-cli/tests/commands/get.rs +++ b/crates/nu-cli/tests/commands/get.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::Stub::FileWithContent; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error, pipeline}; +use nu_test_support::{nu, pipeline}; #[test] fn fetches_a_row() { @@ -21,7 +21,7 @@ fn fetches_a_row() { "# )); - assert_eq!(actual, "zion"); + assert_eq!(actual.out, "zion"); }) } @@ -48,7 +48,7 @@ fn fetches_by_index() { "# )); - assert_eq!(actual, "Andrés N. Robalino "); + assert_eq!(actual.out, "Andrés N. Robalino "); }) } #[test] @@ -71,7 +71,7 @@ fn fetches_by_column_path() { "# )); - assert_eq!(actual, "nu"); + assert_eq!(actual.out, "nu"); }) } @@ -97,7 +97,7 @@ fn column_paths_are_either_double_quoted_or_regular_unquoted_words_separated_by_ "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -131,7 +131,7 @@ fn fetches_more_than_one_column_path() { "# )); - assert_eq!(actual, "Jonathan Turner"); + assert_eq!(actual.out, "Jonathan Turner"); }) } @@ -146,7 +146,7 @@ fn errors_fetching_by_column_not_present() { "#, )]); - let actual = nu_error!( + let actual = nu!( cwd: dirs.test(), pipeline( r#" open sample.toml @@ -155,16 +155,16 @@ fn errors_fetching_by_column_not_present() { )); assert!( - actual.contains("Unknown column"), - format!("actual: {:?}", actual) + actual.err.contains("Unknown column"), + format!("actual: {:?}", actual.err) ); assert!( - actual.contains("There isn't a column named 'taco'"), - format!("actual: {:?}", actual) + actual.err.contains("There isn't a column named 'taco'"), + format!("actual: {:?}", actual.err) ); assert!( - actual.contains("Perhaps you meant 'taconushell'?"), - format!("actual: {:?}", actual) + actual.err.contains("Perhaps you meant 'taconushell'?"), + format!("actual: {:?}", actual.err) ) }) } @@ -180,7 +180,7 @@ fn errors_fetching_by_column_using_a_number() { "#, )]); - let actual = nu_error!( + let actual = nu!( cwd: dirs.test(), pipeline( r#" open sample.toml @@ -189,16 +189,18 @@ fn errors_fetching_by_column_using_a_number() { )); assert!( - actual.contains("No rows available"), - format!("actual: {:?}", actual) + actual.err.contains("No rows available"), + format!("actual: {:?}", actual.err) ); assert!( - actual.contains("A row at '0' can't be indexed."), - format!("actual: {:?}", actual) + actual.err.contains("A row at '0' can't be indexed."), + format!("actual: {:?}", actual.err) ); assert!( - actual.contains("Appears to contain columns. Columns available: 0"), - format!("actual: {:?}", actual) + actual + .err + .contains("Appears to contain columns. Columns available: 0"), + format!("actual: {:?}", actual.err) ) }) } @@ -213,7 +215,7 @@ fn errors_fetching_by_index_out_of_bounds() { "#, )]); - let actual = nu_error!( + let actual = nu!( cwd: dirs.test(), pipeline( r#" open sample.toml @@ -222,16 +224,16 @@ fn errors_fetching_by_index_out_of_bounds() { )); assert!( - actual.contains("Row not found"), - format!("actual: {:?}", actual) + actual.err.contains("Row not found"), + format!("actual: {:?}", actual.err) ); assert!( - actual.contains("There isn't a row indexed at 3"), - format!("actual: {:?}", actual) + actual.err.contains("There isn't a row indexed at 3"), + format!("actual: {:?}", actual.err) ); assert!( - actual.contains("The table only has 3 rows (0 to 2)"), - format!("actual: {:?}", actual) + actual.err.contains("The table only has 3 rows (0 to 2)"), + format!("actual: {:?}", actual.err) ) }) } @@ -243,5 +245,5 @@ fn quoted_column_access() { r#"echo '[{"foo bar": {"baz": 4}}]' | from json | get "foo bar".baz | echo $it"# ); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); } diff --git a/crates/nu-cli/tests/commands/group_by.rs b/crates/nu-cli/tests/commands/group_by.rs index b4eb06354f..5f3661abb6 100644 --- a/crates/nu-cli/tests/commands/group_by.rs +++ b/crates/nu-cli/tests/commands/group_by.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error, pipeline}; +use nu_test_support::{nu, pipeline}; #[test] fn groups() { @@ -26,7 +26,7 @@ fn groups() { "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); }) } @@ -43,7 +43,7 @@ fn errors_if_given_unknown_column_name_is_missing() { "#, )]); - let actual = nu_error!( + let actual = nu!( cwd: dirs.test(), pipeline( r#" open los_tres_caballeros.csv @@ -51,6 +51,6 @@ fn errors_if_given_unknown_column_name_is_missing() { "# )); - assert!(actual.contains("Unknown column")); + assert!(actual.err.contains("Unknown column")); }) } diff --git a/crates/nu-cli/tests/commands/headers.rs b/crates/nu-cli/tests/commands/headers.rs index 607d19d408..1eadf754a0 100644 --- a/crates/nu-cli/tests/commands/headers.rs +++ b/crates/nu-cli/tests/commands/headers.rs @@ -12,7 +12,7 @@ fn headers_uses_first_row_as_header() { | from json"# )); - assert_eq!(actual, "r1c0r2c0") + assert_eq!(actual.out, "r1c0r2c0") } #[test] @@ -27,5 +27,5 @@ fn headers_adds_missing_column_name() { | from json"# )); - assert_eq!(actual, "r1c1r2c1") + assert_eq!(actual.out, "r1c1r2c1") } diff --git a/crates/nu-cli/tests/commands/histogram.rs b/crates/nu-cli/tests/commands/histogram.rs index 2080c367c6..abd3280d87 100644 --- a/crates/nu-cli/tests/commands/histogram.rs +++ b/crates/nu-cli/tests/commands/histogram.rs @@ -26,7 +26,10 @@ fn summarizes() { "# )); - assert_eq!(actual, "**************************************************"); + assert_eq!( + actual.out, + "**************************************************" + ); // 50% }) } @@ -55,7 +58,7 @@ fn help() { "# )); - assert_eq!(help_short, help_command); - assert_eq!(help_long, help_command); + assert_eq!(help_short.out, help_command.out); + assert_eq!(help_long.out, help_command.out); }) } diff --git a/crates/nu-cli/tests/commands/insert.rs b/crates/nu-cli/tests/commands/insert.rs index 89bb0b93fa..9323256cd8 100644 --- a/crates/nu-cli/tests/commands/insert.rs +++ b/crates/nu-cli/tests/commands/insert.rs @@ -12,5 +12,5 @@ fn insert_plugin() { "# )); - assert_eq!(actual, "1"); + assert_eq!(actual.out, "1"); } diff --git a/crates/nu-cli/tests/commands/is_empty.rs b/crates/nu-cli/tests/commands/is_empty.rs index 1d3181743c..c53192f245 100644 --- a/crates/nu-cli/tests/commands/is_empty.rs +++ b/crates/nu-cli/tests/commands/is_empty.rs @@ -27,7 +27,7 @@ fn adds_value_provided_if_column_is_empty() { "# )); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); }) } @@ -58,7 +58,7 @@ fn adds_value_provided_for_columns_that_are_empty() { "# )); - assert_eq!(actual, "8"); + assert_eq!(actual.out, "8"); }) } @@ -91,6 +91,6 @@ fn value_emptiness_check() { "# )); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); }) } diff --git a/crates/nu-cli/tests/commands/keep.rs b/crates/nu-cli/tests/commands/keep.rs index 17bcc46ecf..540566c8c2 100644 --- a/crates/nu-cli/tests/commands/keep.rs +++ b/crates/nu-cli/tests/commands/keep.rs @@ -27,6 +27,6 @@ fn rows() { "# )); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); }) } diff --git a/crates/nu-cli/tests/commands/keep_until.rs b/crates/nu-cli/tests/commands/keep_until.rs index 878d6df69a..47df093415 100644 --- a/crates/nu-cli/tests/commands/keep_until.rs +++ b/crates/nu-cli/tests/commands/keep_until.rs @@ -46,6 +46,6 @@ fn condition_is_met() { "# )); - assert_eq!(actual, "8"); + assert_eq!(actual.out, "8"); }) } diff --git a/crates/nu-cli/tests/commands/keep_while.rs b/crates/nu-cli/tests/commands/keep_while.rs index 89c12b8a38..e340cdd839 100644 --- a/crates/nu-cli/tests/commands/keep_while.rs +++ b/crates/nu-cli/tests/commands/keep_while.rs @@ -46,6 +46,6 @@ fn condition_is_met() { "# )); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); }) } diff --git a/crates/nu-cli/tests/commands/last.rs b/crates/nu-cli/tests/commands/last.rs index 652ccefb5c..f9fb0deb33 100644 --- a/crates/nu-cli/tests/commands/last.rs +++ b/crates/nu-cli/tests/commands/last.rs @@ -9,7 +9,7 @@ fn gets_the_last_row() { "ls | sort-by name | last 1 | get name | trim | echo $it" ); - assert_eq!(actual, "utf16.ini"); + assert_eq!(actual.out, "utf16.ini"); } #[test] @@ -32,7 +32,7 @@ fn gets_last_rows_by_amount() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -51,6 +51,6 @@ fn gets_last_row_when_no_amount_given() { "# )); - assert_eq!(actual, "1"); + assert_eq!(actual.out, "1"); }) } diff --git a/crates/nu-cli/tests/commands/lines.rs b/crates/nu-cli/tests/commands/lines.rs index 87e2f5c16a..4f68dbf79c 100644 --- a/crates/nu-cli/tests/commands/lines.rs +++ b/crates/nu-cli/tests/commands/lines.rs @@ -17,5 +17,5 @@ fn lines() { "# )); - assert_eq!(actual, "rustyline"); + assert_eq!(actual.out, "rustyline"); } diff --git a/crates/nu-cli/tests/commands/ls.rs b/crates/nu-cli/tests/commands/ls.rs index 70b853c3c9..0ce9136a72 100644 --- a/crates/nu-cli/tests/commands/ls.rs +++ b/crates/nu-cli/tests/commands/ls.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::Stub::EmptyFile; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error, pipeline}; +use nu_test_support::{nu, pipeline}; #[test] fn lists_regular_files() { @@ -20,7 +20,7 @@ fn lists_regular_files() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -43,7 +43,7 @@ fn lists_regular_files_using_asterisk_wildcard() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -66,7 +66,7 @@ fn lists_regular_files_using_question_mark_wildcard() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -96,7 +96,7 @@ fn lists_all_files_in_directories_from_stream() { "# )); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); }) } @@ -114,7 +114,7 @@ fn does_not_fail_if_glob_matches_empty_directory() { "# )); - assert_eq!(actual, "0"); + assert_eq!(actual.out, "0"); }) } @@ -123,12 +123,12 @@ fn fails_when_glob_doesnt_match() { Playground::setup("ls_test_5", |dirs, sandbox| { sandbox.with_files(vec![EmptyFile("root1.txt"), EmptyFile("root2.txt")]); - let actual = nu_error!( + let actual = nu!( cwd: dirs.test(), "ls root3*" ); - assert!(actual.contains("no matches found")); + assert!(actual.err.contains("no matches found")); }) } @@ -151,6 +151,6 @@ fn list_files_from_two_parents_up_using_multiple_dots() { "# ); - assert_eq!(actual, "5"); + assert_eq!(actual.out, "5"); }) } diff --git a/crates/nu-cli/tests/commands/math.rs b/crates/nu-cli/tests/commands/math.rs index 9080cb0a6a..23ed9b69d2 100644 --- a/crates/nu-cli/tests/commands/math.rs +++ b/crates/nu-cli/tests/commands/math.rs @@ -9,7 +9,7 @@ fn one_arg() { "# )); - assert_eq!(actual, "1"); + assert_eq!(actual.out, "1"); } #[test] @@ -21,7 +21,7 @@ fn add() { "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); } #[test] @@ -33,7 +33,7 @@ fn add_compount() { "# )); - assert_eq!(actual, "5"); + assert_eq!(actual.out, "5"); } #[test] @@ -45,7 +45,7 @@ fn precedence_of_operators() { "# )); - assert_eq!(actual, "5"); + assert_eq!(actual.out, "5"); } #[test] @@ -57,7 +57,7 @@ fn precedence_of_operators2() { "# )); - assert_eq!(actual, "6"); + assert_eq!(actual.out, "6"); } #[test] @@ -69,7 +69,7 @@ fn division_of_ints() { "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); } #[test] @@ -81,7 +81,7 @@ fn division_of_ints2() { "# )); - assert_eq!(actual, "0.25"); + assert_eq!(actual.out, "0.25"); } #[test] @@ -93,7 +93,7 @@ fn parens_precedence() { "# )); - assert_eq!(actual, "12"); + assert_eq!(actual.out, "12"); } #[test] @@ -105,7 +105,7 @@ fn compound_comparison() { "# )); - assert_eq!(actual, "true"); + assert_eq!(actual.out, "true"); } #[test] @@ -117,7 +117,7 @@ fn compound_comparison2() { "# )); - assert_eq!(actual, "true"); + assert_eq!(actual.out, "true"); } #[test] @@ -129,7 +129,7 @@ fn compound_where() { "# )); - assert_eq!(actual, r#"{"a":2,"b":1}"#); + assert_eq!(actual.out, r#"{"a":2,"b":1}"#); } #[test] @@ -141,5 +141,5 @@ fn compound_where_paren() { "# )); - assert_eq!(actual, r#"[{"a":2,"b":1},{"a":2,"b":2}]"#); + assert_eq!(actual.out, r#"[{"a":2,"b":1},{"a":2,"b":2}]"#); } diff --git a/crates/nu-cli/tests/commands/merge.rs b/crates/nu-cli/tests/commands/merge.rs index de2796adf4..dfda69ee59 100644 --- a/crates/nu-cli/tests/commands/merge.rs +++ b/crates/nu-cli/tests/commands/merge.rs @@ -38,6 +38,6 @@ fn row() { "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); }) } diff --git a/crates/nu-cli/tests/commands/mod.rs b/crates/nu-cli/tests/commands/mod.rs index 120dcf3f43..dc6d8db174 100644 --- a/crates/nu-cli/tests/commands/mod.rs +++ b/crates/nu-cli/tests/commands/mod.rs @@ -28,13 +28,13 @@ mod mkdir; mod mv; mod open; mod parse; -mod pick; mod prepend; mod range; mod rename; mod reverse; mod rm; mod save; +mod select; mod semicolon; mod skip_until; mod sort_by; diff --git a/crates/nu-cli/tests/commands/mv.rs b/crates/nu-cli/tests/commands/mv.rs index b1fd240936..268aac7d92 100644 --- a/crates/nu-cli/tests/commands/mv.rs +++ b/crates/nu-cli/tests/commands/mv.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::{files_exist_at, Stub::EmptyFile}; +use nu_test_support::nu; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error}; #[test] fn moves_a_file() { @@ -223,11 +223,11 @@ fn moves_a_directory_with_files() { fn errors_if_source_doesnt_exist() { Playground::setup("mv_test_10", |dirs, sandbox| { sandbox.mkdir("test_folder"); - let actual = nu_error!( + let actual = nu!( cwd: dirs.root(), "mv non-existing-file test_folder/" ); - assert!(actual.contains("Invalid file or pattern")); + assert!(actual.err.contains("Invalid file or pattern")); }) } diff --git a/crates/nu-cli/tests/commands/nth.rs b/crates/nu-cli/tests/commands/nth.rs index 6880c06488..ef6b825be4 100644 --- a/crates/nu-cli/tests/commands/nth.rs +++ b/crates/nu-cli/tests/commands/nth.rs @@ -14,7 +14,7 @@ fn selects_a_row() { "# )); - assert_eq!(actual, "arepas.txt"); + assert_eq!(actual.out, "arepas.txt"); }); } @@ -34,6 +34,6 @@ fn selects_many_rows() { "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); }); } \ No newline at end of file diff --git a/crates/nu-cli/tests/commands/open.rs b/crates/nu-cli/tests/commands/open.rs index 0fbceda6dd..b009f98213 100644 --- a/crates/nu-cli/tests/commands/open.rs +++ b/crates/nu-cli/tests/commands/open.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error, pipeline}; +use nu_test_support::{nu, pipeline}; #[test] fn parses_csv() { @@ -25,7 +25,7 @@ fn parses_csv() { "# )); - assert_eq!(actual, "Ecuador"); + assert_eq!(actual.out, "Ecuador"); }) } @@ -61,7 +61,7 @@ fn parses_bson() { "open sample.bson | get root | nth 0 | get b | echo $it" ); - assert_eq!(actual, "hello"); + assert_eq!(actual.out, "hello"); } #[test] @@ -78,7 +78,7 @@ fn parses_more_bson_complexity() { "# )); - assert_eq!(actual, "function"); + assert_eq!(actual.out, "function"); } // sample.db has the following format: @@ -143,7 +143,7 @@ fn parses_sqlite() { "# )); - assert_eq!(actual, "hello"); + assert_eq!(actual.out, "hello"); } #[test] @@ -153,7 +153,7 @@ fn parses_toml() { "open cargo_sample.toml | get package.edition | echo $it" ); - assert_eq!(actual, "2018"); + assert_eq!(actual.out, "2018"); } #[test] @@ -168,7 +168,7 @@ fn parses_tsv() { "# )); - assert_eq!(actual, "SPAIN") + assert_eq!(actual.out, "SPAIN") } #[test] @@ -182,7 +182,7 @@ fn parses_json() { "# )); - assert_eq!(actual, "markup") + assert_eq!(actual.out, "markup") } #[test] @@ -193,7 +193,7 @@ fn parses_xml() { ); assert_eq!( - actual, + actual.out, "http://www.jonathanturner.org/2015/10/off-to-new-adventures.html" ) } @@ -205,7 +205,7 @@ fn parses_ini() { "open sample.ini | get SectionOne.integer | echo $it" ); - assert_eq!(actual, "1234") + assert_eq!(actual.out, "1234") } #[test] @@ -215,16 +215,16 @@ fn parses_utf16_ini() { "open utf16.ini | get '.ShellClassInfo' | get IconIndex | echo $it" ); - assert_eq!(actual, "-236") + assert_eq!(actual.out, "-236") } #[test] fn errors_if_file_not_found() { - let actual = nu_error!( + let actual = nu!( cwd: "tests/fixtures/formats", "open i_dont_exist.txt" ); - assert!(actual.contains("File could not be opened")); - assert!(actual.contains("file not found")); + assert!(actual.err.contains("File could not be opened")); + assert!(actual.err.contains("file not found")); } diff --git a/crates/nu-cli/tests/commands/parse.rs b/crates/nu-cli/tests/commands/parse.rs index d78abc1da5..07d8949eff 100644 --- a/crates/nu-cli/tests/commands/parse.rs +++ b/crates/nu-cli/tests/commands/parse.rs @@ -25,6 +25,6 @@ fn extracts_fields_from_the_given_the_pattern() { "# )); - assert_eq!(actual, "JonathanParsed"); + assert_eq!(actual.out, "JonathanParsed"); }) } diff --git a/crates/nu-cli/tests/commands/prepend.rs b/crates/nu-cli/tests/commands/prepend.rs index 288fad5528..d4cfa55e13 100644 --- a/crates/nu-cli/tests/commands/prepend.rs +++ b/crates/nu-cli/tests/commands/prepend.rs @@ -25,6 +25,6 @@ fn adds_a_row_to_the_beginning() { "# )); - assert_eq!(actual, "pollo loco"); + assert_eq!(actual.out, "pollo loco"); }) } diff --git a/crates/nu-cli/tests/commands/range.rs b/crates/nu-cli/tests/commands/range.rs index 3594cdf879..eb112d0b8b 100644 --- a/crates/nu-cli/tests/commands/range.rs +++ b/crates/nu-cli/tests/commands/range.rs @@ -18,7 +18,7 @@ fn selects_a_row() { "# )); - assert_eq!(actual, "notes.txt"); + assert_eq!(actual.out, "notes.txt"); }); } @@ -42,6 +42,6 @@ fn selects_some_rows() { "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); }); } diff --git a/crates/nu-cli/tests/commands/rename.rs b/crates/nu-cli/tests/commands/rename.rs index 00cf714163..ef7cf36fc6 100644 --- a/crates/nu-cli/tests/commands/rename.rs +++ b/crates/nu-cli/tests/commands/rename.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error, pipeline}; +use nu_test_support::{nu, pipeline}; #[test] fn changes_the_column_name() { @@ -28,7 +28,7 @@ fn changes_the_column_name() { "# )); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); }) } @@ -59,7 +59,7 @@ fn keeps_remaining_original_names_given_less_new_names_than_total_original_names "# )); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); }) } @@ -76,7 +76,7 @@ fn errors_if_no_columns_present() { "#, )]); - let actual = nu_error!( + let actual = nu!( cwd: dirs.test(), pipeline( r#" open los_cuatro_mosqueteros.txt @@ -86,12 +86,12 @@ fn errors_if_no_columns_present() { )); assert!( - actual.contains("no column names available"), - format!("actual: {:?}", actual) + actual.err.contains("no column names available"), + format!("actual: {:?}", actual.err) ); assert!( - actual.contains("can't rename"), - format!("actual: {:?}", actual) + actual.err.contains("can't rename"), + format!("actual: {:?}", actual.err) ); }) } diff --git a/crates/nu-cli/tests/commands/reverse.rs b/crates/nu-cli/tests/commands/reverse.rs index 436eeed421..6e6a993ef8 100644 --- a/crates/nu-cli/tests/commands/reverse.rs +++ b/crates/nu-cli/tests/commands/reverse.rs @@ -7,5 +7,5 @@ fn can_get_reverse_first() { "ls | sort-by name | reverse | first 1 | get name | trim | echo $it" ); - assert_eq!(actual, "utf16.ini"); + assert_eq!(actual.out, "utf16.ini"); } diff --git a/crates/nu-cli/tests/commands/rm.rs b/crates/nu-cli/tests/commands/rm.rs index 13dd5003b5..3b89afa992 100644 --- a/crates/nu-cli/tests/commands/rm.rs +++ b/crates/nu-cli/tests/commands/rm.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::{files_exist_at, Stub::EmptyFile}; +use nu_test_support::nu; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error}; #[test] fn removes_a_file() { @@ -126,37 +126,37 @@ fn errors_if_attempting_to_delete_a_directory_with_content_without_recursive_fla Playground::setup("rm_test_6", |dirs, sandbox| { sandbox.with_files(vec![EmptyFile("some_empty_file.txt")]); - let actual = nu_error!( + let actual = nu!( cwd: dirs.root(), "rm rm_test_6" ); assert!(dirs.test().exists()); - assert!(actual.contains("cannot remove non-empty directory")); + assert!(actual.err.contains("cannot remove non-empty directory")); }) } #[test] fn errors_if_attempting_to_delete_single_dot_as_argument() { Playground::setup("rm_test_7", |dirs, _| { - let actual = nu_error!( + let actual = nu!( cwd: dirs.root(), "rm ." ); - assert!(actual.contains("cannot remove any parent directory")); + assert!(actual.err.contains("cannot remove any parent directory")); }) } #[test] fn errors_if_attempting_to_delete_two_dot_as_argument() { Playground::setup("rm_test_8", |dirs, _| { - let actual = nu_error!( + let actual = nu!( cwd: dirs.root(), "rm .." ); - assert!(actual.contains("cannot remove any parent directory")); + assert!(actual.err.contains("cannot remove any parent directory")); }) } @@ -239,7 +239,7 @@ fn allows_doubly_specified_file() { Playground::glob_vec(&format!("{}/*", dirs.test().display())), Vec::::new() ); - assert!(!actual.contains("error")) + assert!(!actual.out.contains("error")) }) } diff --git a/crates/nu-cli/tests/commands/pick.rs b/crates/nu-cli/tests/commands/select.rs similarity index 84% rename from crates/nu-cli/tests/commands/pick.rs rename to crates/nu-cli/tests/commands/select.rs index 3bd81ff06e..48ff2b7bcb 100644 --- a/crates/nu-cli/tests/commands/pick.rs +++ b/crates/nu-cli/tests/commands/select.rs @@ -4,7 +4,7 @@ use nu_test_support::{nu, pipeline}; #[test] fn regular_columns() { - Playground::setup("pick_test_1", |dirs, sandbox| { + Playground::setup("select_test_1", |dirs, sandbox| { sandbox.with_files(vec![FileWithContentToBeTrimmed( "los_tres_caballeros.csv", r#" @@ -19,20 +19,20 @@ fn regular_columns() { cwd: dirs.test(), pipeline( r#" open los_tres_caballeros.csv - | pick rusty_at last_name + | select rusty_at last_name | nth 0 | get last_name | echo $it "# )); - assert_eq!(actual, "Robalino"); + assert_eq!(actual.out, "Robalino"); }) } #[test] fn complex_nested_columns() { - Playground::setup("pick_test_2", |dirs, sandbox| { + Playground::setup("select_test_2", |dirs, sandbox| { sandbox.with_files(vec![FileWithContentToBeTrimmed( "los_tres_caballeros.json", r#" @@ -62,20 +62,20 @@ fn complex_nested_columns() { cwd: dirs.test(), pipeline( r#" open los_tres_caballeros.json - | pick nu."0xATYKARNU" nu.committers.name nu.releases.version + | select nu."0xATYKARNU" nu.committers.name nu.releases.version | where "nu.releases.version" > "0.8" | get "nu.releases.version" | echo $it "# )); - assert_eq!(actual, "0.9999999"); + assert_eq!(actual.out, "0.9999999"); }) } #[test] fn allows_if_given_unknown_column_name_is_missing() { - Playground::setup("pick_test_3", |dirs, sandbox| { + Playground::setup("select_test_3", |dirs, sandbox| { sandbox.with_files(vec![FileWithContentToBeTrimmed( "los_tres_caballeros.csv", r#" @@ -90,12 +90,12 @@ fn allows_if_given_unknown_column_name_is_missing() { cwd: dirs.test(), pipeline( r#" open los_tres_caballeros.csv - | pick rrusty_at first_name + | select rrusty_at first_name | count | echo $it "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } diff --git a/crates/nu-cli/tests/commands/semicolon.rs b/crates/nu-cli/tests/commands/semicolon.rs index de66ed5f1e..19e4a9cfe2 100644 --- a/crates/nu-cli/tests/commands/semicolon.rs +++ b/crates/nu-cli/tests/commands/semicolon.rs @@ -12,7 +12,7 @@ fn semicolon_allows_lhs_to_complete() { let path = dirs.test().join("i_will_be_created_semi.txt"); assert!(path.exists()); - assert_eq!(actual, "done"); + assert_eq!(actual.out, "done"); }) } @@ -25,5 +25,5 @@ fn semicolon_lhs_error_stops_processing() { "# )); - assert!(!actual.contains("done")); + assert!(!actual.out.contains("done")); } diff --git a/crates/nu-cli/tests/commands/skip_until.rs b/crates/nu-cli/tests/commands/skip_until.rs index 7c709f734b..0c77163689 100644 --- a/crates/nu-cli/tests/commands/skip_until.rs +++ b/crates/nu-cli/tests/commands/skip_until.rs @@ -37,7 +37,7 @@ fn condition_is_met() { | skip 2 | split-column ',' | headers - | skip-until "Chicken Collection" != "Red Chickens" + | skip-until "Chicken Collection" == "Red Chickens" | str "31/04/2020" --to-int | get "31/04/2020" | sum @@ -45,6 +45,6 @@ fn condition_is_met() { "# )); - assert_eq!(actual, "12"); + assert_eq!(actual.out, "12"); }) } diff --git a/crates/nu-cli/tests/commands/sort_by.rs b/crates/nu-cli/tests/commands/sort_by.rs index d4de43b236..6c0306068e 100644 --- a/crates/nu-cli/tests/commands/sort_by.rs +++ b/crates/nu-cli/tests/commands/sort_by.rs @@ -19,7 +19,7 @@ fn by_column() { "# )); - assert_eq!(actual, "description"); + assert_eq!(actual.out, "description"); } #[test] @@ -37,5 +37,5 @@ fn sort_primitive_values() { "# )); - assert_eq!(actual, "authors = [\"The Nu Project Contributors\"]"); + assert_eq!(actual.out, "authors = [\"The Nu Project Contributors\"]"); } diff --git a/crates/nu-cli/tests/commands/split_by.rs b/crates/nu-cli/tests/commands/split_by.rs index cf4a1b232f..77b8df74ae 100644 --- a/crates/nu-cli/tests/commands/split_by.rs +++ b/crates/nu-cli/tests/commands/split_by.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::Stub::{EmptyFile, FileWithContentToBeTrimmed}; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error, pipeline}; +use nu_test_support::{nu, pipeline}; #[test] fn splits() { @@ -27,7 +27,7 @@ fn splits() { "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); }) } @@ -41,7 +41,7 @@ fn errors_if_no_table_given_as_input() { EmptyFile("arepas.clu"), ]); - let actual = nu_error!( + let actual = nu!( cwd: dirs.test(), pipeline( r#" ls @@ -50,6 +50,6 @@ fn errors_if_no_table_given_as_input() { "# )); - assert!(actual.contains("Expected table from pipeline")); + assert!(actual.err.contains("Expected table from pipeline")); }) } diff --git a/crates/nu-cli/tests/commands/split_column.rs b/crates/nu-cli/tests/commands/split_column.rs index da613a3e2b..e6bf5ebd03 100644 --- a/crates/nu-cli/tests/commands/split_column.rs +++ b/crates/nu-cli/tests/commands/split_column.rs @@ -16,5 +16,5 @@ fn by_column() { "# )); - assert_eq!(actual, "name"); + assert_eq!(actual.out, "name"); } diff --git a/crates/nu-cli/tests/commands/sum.rs b/crates/nu-cli/tests/commands/sum.rs index 63963941e4..0513a57c51 100644 --- a/crates/nu-cli/tests/commands/sum.rs +++ b/crates/nu-cli/tests/commands/sum.rs @@ -29,7 +29,7 @@ fn all() { "# )); - assert_eq!(actual, "448"); + assert_eq!(actual.out, "448"); }) } @@ -57,6 +57,6 @@ fn outputs_zero_with_no_input() { "# )); - assert_eq!(actual, "0"); + assert_eq!(actual.out, "0"); }) } diff --git a/crates/nu-cli/tests/commands/trim.rs b/crates/nu-cli/tests/commands/trim.rs index 1c5bf0ae5a..dd1e1c8129 100644 --- a/crates/nu-cli/tests/commands/trim.rs +++ b/crates/nu-cli/tests/commands/trim.rs @@ -19,7 +19,7 @@ fn string() { let actual = nu!( cwd: dirs.test(), pipeline(&commandline )); - assert_eq!(actual, test_string.trim()) + assert_eq!(actual.out, test_string.trim()) } }) } @@ -47,7 +47,7 @@ fn row() { "# )); - assert_eq!(actual, expected) + assert_eq!(actual.out, expected.out) }) } @@ -80,6 +80,6 @@ fn nested() { "# )); - assert_eq!(actual, expected) + assert_eq!(actual.out, expected.out) }) } diff --git a/crates/nu-cli/tests/commands/uniq.rs b/crates/nu-cli/tests/commands/uniq.rs index 4271bc16d9..465741c292 100644 --- a/crates/nu-cli/tests/commands/uniq.rs +++ b/crates/nu-cli/tests/commands/uniq.rs @@ -27,7 +27,7 @@ fn removes_duplicate_rows() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -50,14 +50,14 @@ fn uniq_values() { cwd: dirs.test(), pipeline( r#" open los_tres_caballeros.csv - | pick type + | select type | uniq | count | echo $it "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); }) } @@ -121,7 +121,7 @@ fn nested_json_structures() { | echo $it "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -138,5 +138,5 @@ fn uniq_when_keys_out_of_order() { "# )); - assert_eq!(actual, "1"); + assert_eq!(actual.out, "1"); } diff --git a/crates/nu-cli/tests/commands/update.rs b/crates/nu-cli/tests/commands/update.rs index 1371eb130d..7e270e9494 100644 --- a/crates/nu-cli/tests/commands/update.rs +++ b/crates/nu-cli/tests/commands/update.rs @@ -12,7 +12,7 @@ fn sets_the_column() { "# )); - assert_eq!(actual, "0.7.0"); + assert_eq!(actual.out, "0.7.0"); } #[test] @@ -27,5 +27,5 @@ fn sets_the_column_from_a_block_run_output() { "# )); - assert_eq!(actual, "0.7.0"); + assert_eq!(actual.out, "0.7.0"); } diff --git a/crates/nu-cli/tests/commands/where_.rs b/crates/nu-cli/tests/commands/where_.rs index d45439d294..1e55645c1c 100644 --- a/crates/nu-cli/tests/commands/where_.rs +++ b/crates/nu-cli/tests/commands/where_.rs @@ -7,7 +7,7 @@ fn filters_by_unit_size_comparison() { "ls | where size > 1kb | sort-by size | get name | first 1 | trim | echo $it" ); - assert_eq!(actual, "cargo_sample.toml"); + assert_eq!(actual.out, "cargo_sample.toml"); } #[test] @@ -17,7 +17,7 @@ fn filters_with_nothing_comparison() { r#"echo '[{"foo": 3}, {"foo": null}, {"foo": 4}]' | from json | where foo > 1 | get foo | sum | echo $it"# ); - assert_eq!(actual, "7"); + assert_eq!(actual.out, "7"); } #[test] @@ -27,7 +27,7 @@ fn where_in_table() { r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from json | where name in: ["foo"] | get size | sum | echo $it"# ); - assert_eq!(actual, "5"); + assert_eq!(actual.out, "5"); } #[test] @@ -37,7 +37,7 @@ fn where_not_in_table() { r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from json | where name not-in: ["foo"] | get size | sum | echo $it"# ); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); } #[test] @@ -55,7 +55,7 @@ fn explicit_block_condition() { "# )); - assert_eq!(actual, "4253"); + assert_eq!(actual.out, "4253"); } #[test] @@ -73,7 +73,7 @@ fn binary_operator_comparisons() { "# )); - assert_eq!(actual, "4253"); + assert_eq!(actual.out, "4253"); let actual = nu!( cwd: "tests/fixtures/formats", pipeline( @@ -88,7 +88,7 @@ fn binary_operator_comparisons() { "# )); - assert_eq!(actual, "4253"); + assert_eq!(actual.out, "4253"); let actual = nu!( cwd: "tests/fixtures/formats", pipeline( @@ -103,7 +103,7 @@ fn binary_operator_comparisons() { "# )); - assert_eq!(actual, "1"); + assert_eq!(actual.out, "1"); let actual = nu!( cwd: "tests/fixtures/formats", pipeline( @@ -118,7 +118,7 @@ fn binary_operator_comparisons() { "# )); - assert_eq!(actual, "1"); + assert_eq!(actual.out, "1"); let actual = nu!( cwd: "tests/fixtures/formats", pipeline( @@ -133,7 +133,7 @@ fn binary_operator_comparisons() { "# )); - assert_eq!(actual, "42"); + assert_eq!(actual.out, "42"); } #[test] @@ -150,7 +150,7 @@ fn contains_operator() { "# )); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); let actual = nu!( cwd: "tests/fixtures/formats", pipeline( @@ -164,5 +164,5 @@ fn contains_operator() { "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); } diff --git a/crates/nu-cli/tests/commands/with_env.rs b/crates/nu-cli/tests/commands/with_env.rs index d6c9df5d95..640dd867f3 100644 --- a/crates/nu-cli/tests/commands/with_env.rs +++ b/crates/nu-cli/tests/commands/with_env.rs @@ -7,7 +7,7 @@ fn with_env_extends_environment() { "with-env [FOO BARRRR] {echo $nu.env} | get FOO" ); - assert_eq!(actual, "BARRRR"); + assert_eq!(actual.out, "BARRRR"); } #[test] @@ -17,5 +17,5 @@ fn with_env_shorthand() { "FOO=BARRRR echo $nu.env | get FOO" ); - assert_eq!(actual, "BARRRR"); + assert_eq!(actual.out, "BARRRR"); } diff --git a/crates/nu-cli/tests/commands/wrap.rs b/crates/nu-cli/tests/commands/wrap.rs index 02a0ebb669..295f7366f7 100644 --- a/crates/nu-cli/tests/commands/wrap.rs +++ b/crates/nu-cli/tests/commands/wrap.rs @@ -28,7 +28,7 @@ fn wrap_rows_into_a_row() { "# )); - assert_eq!(actual, "Robalino"); + assert_eq!(actual.out, "Robalino"); }) } @@ -58,6 +58,6 @@ fn wrap_rows_into_a_table() { "# )); - assert_eq!(actual, "Katz"); + assert_eq!(actual.out, "Katz"); }) } diff --git a/crates/nu-cli/tests/format_conversions/bson.rs b/crates/nu-cli/tests/format_conversions/bson.rs index 3fc39e821f..72133b0025 100644 --- a/crates/nu-cli/tests/format_conversions/bson.rs +++ b/crates/nu-cli/tests/format_conversions/bson.rs @@ -14,5 +14,5 @@ fn table_to_bson_and_back_into_table() { "# )); - assert_eq!(actual, "whel"); + assert_eq!(actual.out, "whel"); } diff --git a/crates/nu-cli/tests/format_conversions/csv.rs b/crates/nu-cli/tests/format_conversions/csv.rs index 17e2f14c0b..59f1d31441 100644 --- a/crates/nu-cli/tests/format_conversions/csv.rs +++ b/crates/nu-cli/tests/format_conversions/csv.rs @@ -9,7 +9,7 @@ fn table_to_csv_text_and_from_csv_text_back_into_table() { "open caco3_plastics.csv | to csv | from csv | first 1 | get origin | echo $it" ); - assert_eq!(actual, "SPAIN"); + assert_eq!(actual.out, "SPAIN"); } #[test] @@ -39,7 +39,9 @@ fn table_to_csv_text() { "# )); - assert!(actual.contains("Tigre Ecuador,OMYA Andina,3824909999,Calcium carbonate,Colombia")); + assert!(actual + .out + .contains("Tigre Ecuador,OMYA Andina,3824909999,Calcium carbonate,Colombia")); }) } @@ -68,7 +70,9 @@ fn table_to_csv_text_skipping_headers_after_conversion() { "# )); - assert!(actual.contains("Tigre Ecuador,OMYA Andina,3824909999,Calcium carbonate,Colombia")); + assert!(actual + .out + .contains("Tigre Ecuador,OMYA Andina,3824909999,Calcium carbonate,Colombia")); }) } @@ -96,7 +100,7 @@ fn infers_types() { "# )); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); }) } @@ -124,7 +128,7 @@ fn from_csv_text_to_table() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -152,7 +156,7 @@ fn from_csv_text_with_separator_to_table() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -180,7 +184,7 @@ fn from_csv_text_with_tab_separator_to_table() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -207,6 +211,6 @@ fn from_csv_text_skipping_headers_to_table() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } diff --git a/crates/nu-cli/tests/format_conversions/eml.rs b/crates/nu-cli/tests/format_conversions/eml.rs index a568ae5f1c..bb5111c5bc 100644 --- a/crates/nu-cli/tests/format_conversions/eml.rs +++ b/crates/nu-cli/tests/format_conversions/eml.rs @@ -17,7 +17,7 @@ fn from_eml_get_to_field() { ) ); - assert_eq!(actual, "username@domain.com"); + assert_eq!(actual.out, "username@domain.com"); let actual = nu!( cwd: TEST_CWD, @@ -31,7 +31,7 @@ fn from_eml_get_to_field() { ) ); - assert_eq!(actual, ""); + assert_eq!(actual.out, ""); } // The Reply-To field in this email is "aw-confirm@ebay.com" , meaning both the Name and Address values are identical. @@ -49,7 +49,7 @@ fn from_eml_get_replyto_field() { ) ); - assert_eq!(actual, "aw-confirm@ebay.com"); + assert_eq!(actual.out, "aw-confirm@ebay.com"); let actual = nu!( cwd: TEST_CWD, @@ -63,7 +63,7 @@ fn from_eml_get_replyto_field() { ) ); - assert_eq!(actual, "aw-confirm@ebay.com"); + assert_eq!(actual.out, "aw-confirm@ebay.com"); } // The Reply-To field in this email is "aw-confirm@ebay.com" , meaning both the Name and Address values are identical. @@ -80,5 +80,5 @@ fn from_eml_get_subject_field() { ) ); - assert_eq!(actual, "Billing Issues"); + assert_eq!(actual.out, "Billing Issues"); } diff --git a/crates/nu-cli/tests/format_conversions/html.rs b/crates/nu-cli/tests/format_conversions/html.rs index d12eec98d5..06b642c637 100644 --- a/crates/nu-cli/tests/format_conversions/html.rs +++ b/crates/nu-cli/tests/format_conversions/html.rs @@ -9,7 +9,7 @@ fn out_html_simple() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); } #[test] @@ -22,7 +22,7 @@ fn out_html_table() { )); assert_eq!( - actual, + actual.out, "
name
jason
" ); } diff --git a/crates/nu-cli/tests/format_conversions/ics.rs b/crates/nu-cli/tests/format_conversions/ics.rs index 9d2d0f7e14..9926b2c888 100644 --- a/crates/nu-cli/tests/format_conversions/ics.rs +++ b/crates/nu-cli/tests/format_conversions/ics.rs @@ -53,7 +53,7 @@ fn infers_types() { "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); }) } @@ -96,6 +96,6 @@ fn from_ics_text_to_table() { "# )); - assert_eq!(actual, "Maryland Game"); + assert_eq!(actual.out, "Maryland Game"); }) } diff --git a/crates/nu-cli/tests/format_conversions/json.rs b/crates/nu-cli/tests/format_conversions/json.rs index 3f056839f1..19204dbe19 100644 --- a/crates/nu-cli/tests/format_conversions/json.rs +++ b/crates/nu-cli/tests/format_conversions/json.rs @@ -15,7 +15,7 @@ fn table_to_json_text_and_from_json_text_back_into_table() { "# )); - assert_eq!(actual, "markup"); + assert_eq!(actual.out, "markup"); } #[test] @@ -40,7 +40,7 @@ fn from_json_text_to_table() { "open katz.txt | from json | get katz | get rusty_luck | count | echo $it" ); - assert_eq!(actual, "4"); + assert_eq!(actual.out, "4"); }) } @@ -68,7 +68,7 @@ fn from_json_text_recognizing_objects_independently_to_table() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -89,7 +89,7 @@ fn table_to_json_text() { open sample.txt | lines | split-column "," name luck - | pick name + | select name | to json | from json | nth 0 @@ -98,6 +98,6 @@ fn table_to_json_text() { "# )); - assert_eq!(actual, "JonAndrehudaTZ"); + assert_eq!(actual.out, "JonAndrehudaTZ"); }) } diff --git a/crates/nu-cli/tests/format_conversions/markdown.rs b/crates/nu-cli/tests/format_conversions/markdown.rs index 2e79c57fd1..cdcf4f4f49 100644 --- a/crates/nu-cli/tests/format_conversions/markdown.rs +++ b/crates/nu-cli/tests/format_conversions/markdown.rs @@ -9,7 +9,7 @@ fn out_md_simple() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); } #[test] @@ -21,5 +21,5 @@ fn out_md_table() { "# )); - assert_eq!(actual, "|name||-||jason|"); + assert_eq!(actual.out, "|name||-||jason|"); } diff --git a/crates/nu-cli/tests/format_conversions/ods.rs b/crates/nu-cli/tests/format_conversions/ods.rs index 1597f9b522..08d9514dd2 100644 --- a/crates/nu-cli/tests/format_conversions/ods.rs +++ b/crates/nu-cli/tests/format_conversions/ods.rs @@ -13,5 +13,5 @@ fn from_ods_file_to_table() { "# )); - assert_eq!(actual, "Gill"); + assert_eq!(actual.out, "Gill"); } diff --git a/crates/nu-cli/tests/format_conversions/sqlite.rs b/crates/nu-cli/tests/format_conversions/sqlite.rs index 15843707af..9f42ce1f21 100644 --- a/crates/nu-cli/tests/format_conversions/sqlite.rs +++ b/crates/nu-cli/tests/format_conversions/sqlite.rs @@ -15,5 +15,5 @@ fn table_to_sqlite_and_back_into_table() { "# )); - assert_eq!(actual, "hello"); + assert_eq!(actual.out, "hello"); } diff --git a/crates/nu-cli/tests/format_conversions/ssv.rs b/crates/nu-cli/tests/format_conversions/ssv.rs index 7287cc807b..731f339bbd 100644 --- a/crates/nu-cli/tests/format_conversions/ssv.rs +++ b/crates/nu-cli/tests/format_conversions/ssv.rs @@ -26,7 +26,7 @@ fn from_ssv_text_to_table() { "# )); - assert_eq!(actual, "172.30.78.158"); + assert_eq!(actual.out, "172.30.78.158"); }) } @@ -54,7 +54,7 @@ fn from_ssv_text_to_table_with_separator_specified() { "# )); - assert_eq!(actual, "172.30.78.158"); + assert_eq!(actual.out, "172.30.78.158"); }) } @@ -92,7 +92,7 @@ fn from_ssv_text_treating_first_line_as_data_with_flag() { "# )); - assert_eq!(aligned_columns, separator_based); - assert_eq!(separator_based, "docker-registry"); + assert_eq!(aligned_columns.out, separator_based.out); + assert_eq!(separator_based.out, "docker-registry"); }) } diff --git a/crates/nu-cli/tests/format_conversions/toml.rs b/crates/nu-cli/tests/format_conversions/toml.rs index e1eb64c881..95d59b87db 100644 --- a/crates/nu-cli/tests/format_conversions/toml.rs +++ b/crates/nu-cli/tests/format_conversions/toml.rs @@ -13,5 +13,5 @@ fn table_to_toml_text_and_from_toml_text_back_into_table() { "# )); - assert_eq!(actual, "nu"); + assert_eq!(actual.out, "nu"); } diff --git a/crates/nu-cli/tests/format_conversions/tsv.rs b/crates/nu-cli/tests/format_conversions/tsv.rs index 785be19925..5648b6b7e8 100644 --- a/crates/nu-cli/tests/format_conversions/tsv.rs +++ b/crates/nu-cli/tests/format_conversions/tsv.rs @@ -9,7 +9,7 @@ fn table_to_tsv_text_and_from_tsv_text_back_into_table() { "open caco3_plastics.tsv | to tsv | from tsv | first 1 | get origin | echo $it" ); - assert_eq!(actual, "SPAIN"); + assert_eq!(actual.out, "SPAIN"); } #[test] @@ -19,7 +19,7 @@ fn table_to_tsv_text_and_from_tsv_text_back_into_table_using_csv_separator() { r"open caco3_plastics.tsv | to tsv | from csv --separator '\t' | first 1 | get origin | echo $it" ); - assert_eq!(actual, "SPAIN"); + assert_eq!(actual.out, "SPAIN"); } #[test] @@ -48,7 +48,7 @@ fn table_to_tsv_text() { "# )); - assert!(actual.contains("Colombia")); + assert!(actual.out.contains("Colombia")); }) } @@ -76,7 +76,7 @@ fn table_to_tsv_text_skipping_headers_after_conversion() { "# )); - assert!(actual.contains("Colombia")); + assert!(actual.out.contains("Colombia")); }) } @@ -104,7 +104,7 @@ fn from_tsv_text_to_table() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -131,6 +131,6 @@ fn from_tsv_text_skipping_headers_to_table() { "# )); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } diff --git a/crates/nu-cli/tests/format_conversions/url.rs b/crates/nu-cli/tests/format_conversions/url.rs index 1312bda77d..effb5c837a 100644 --- a/crates/nu-cli/tests/format_conversions/url.rs +++ b/crates/nu-cli/tests/format_conversions/url.rs @@ -13,5 +13,5 @@ fn can_encode_and_decode_urlencoding() { "# )); - assert_eq!(actual, "comté"); + assert_eq!(actual.out, "comté"); } diff --git a/crates/nu-cli/tests/format_conversions/vcf.rs b/crates/nu-cli/tests/format_conversions/vcf.rs index be59cca74a..ddf44c94ff 100644 --- a/crates/nu-cli/tests/format_conversions/vcf.rs +++ b/crates/nu-cli/tests/format_conversions/vcf.rs @@ -40,7 +40,7 @@ fn infers_types() { "# )); - assert_eq!(actual, "2"); + assert_eq!(actual.out, "2"); }) } @@ -79,6 +79,6 @@ fn from_vcf_text_to_table() { "# )); - assert_eq!(actual, "john.doe99@gmail.com"); + assert_eq!(actual.out, "john.doe99@gmail.com"); }) } diff --git a/crates/nu-cli/tests/format_conversions/xlsx.rs b/crates/nu-cli/tests/format_conversions/xlsx.rs index ddc9454242..cbfe2fe879 100644 --- a/crates/nu-cli/tests/format_conversions/xlsx.rs +++ b/crates/nu-cli/tests/format_conversions/xlsx.rs @@ -13,5 +13,5 @@ fn from_excel_file_to_table() { "# )); - assert_eq!(actual, "Gill"); + assert_eq!(actual.out, "Gill"); } diff --git a/crates/nu-cli/tests/format_conversions/yaml.rs b/crates/nu-cli/tests/format_conversions/yaml.rs index fce047e3c0..a6ea7cea62 100644 --- a/crates/nu-cli/tests/format_conversions/yaml.rs +++ b/crates/nu-cli/tests/format_conversions/yaml.rs @@ -13,5 +13,5 @@ fn table_to_yaml_text_and_from_yaml_text_back_into_table() { "# )); - assert_eq!(actual, "nushell"); + assert_eq!(actual.out, "nushell"); } diff --git a/crates/nu-test-support/src/macros.rs b/crates/nu-test-support/src/macros.rs index f4f5f890be..0724b9586f 100644 --- a/crates/nu-test-support/src/macros.rs +++ b/crates/nu-test-support/src/macros.rs @@ -47,8 +47,9 @@ macro_rules! nu { let mut process = match Command::new($crate::fs::executable_path()) .env("PATH", paths_joined) - .stdin(Stdio::piped()) .stdout(Stdio::piped()) + .stdin(Stdio::piped()) + .stderr(Stdio::piped()) .spawn() { Ok(child) => child, @@ -62,89 +63,31 @@ macro_rules! nu { let output = process .wait_with_output() - .expect("couldn't read from stdout"); + .expect("couldn't read from stdout/stderr"); let out = $crate::macros::read_std(&output.stdout); - let err = $crate::macros::read_std(&output.stderr); + let err = String::from_utf8_lossy(&output.stderr); - println!("=== stderr\n{}", err); + println!("=== stderr\n{}", err); - out + $crate::macros::Outcome::new(out,err.into_owned()) }}; } +pub struct Outcome { + pub out: String, + pub err: String, +} + +impl Outcome { + pub fn new(out: String, err: String) -> Outcome { + Outcome { out, err } + } +} + pub fn read_std(std: &[u8]) -> String { let out = String::from_utf8_lossy(std); let out = out.lines().skip(1).collect::>().join("\n"); let out = out.replace("\r\n", ""); out.replace("\n", "") } - -#[macro_export] -macro_rules! nu_error { - (cwd: $cwd:expr, $path:expr, $($part:expr),*) => {{ - use $crate::fs::DisplayPath; - - let path = format!($path, $( - $part.display_path() - ),*); - - nu_error!($cwd, &path) - }}; - - (cwd: $cwd:expr, $path:expr) => {{ - nu_error!($cwd, $path) - }}; - - ($cwd:expr, $path:expr) => {{ - pub use std::error::Error; - pub use std::io::prelude::*; - pub use std::process::{Command, Stdio}; - - let commands = &*format!( - " - cd \"{}\" - {} - exit", - $crate::fs::in_directory($cwd), - $crate::fs::DisplayPath::display_path(&$path) - ); - - let test_bins = $crate::fs::binaries(); - let test_bins = dunce::canonicalize(&test_bins).unwrap_or_else(|e| { - panic!( - "Couldn't canonicalize dummy binaries path {}: {:?}", - test_bins.display(), - e - ) - }); - - let mut paths = $crate::shell_os_paths(); - paths.push(test_bins); - - let paths_joined = match std::env::join_paths(paths.iter()) { - Ok(all) => all, - Err(_) => panic!("Couldn't join paths for PATH var."), - }; - - let mut process = Command::new($crate::fs::executable_path()) - .env("PATH", paths_joined) - .stdout(Stdio::piped()) - .stdin(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("couldn't run test"); - - let stdin = process.stdin.as_mut().expect("couldn't open stdin"); - stdin - .write_all(commands.as_bytes()) - .expect("couldn't write to stdin"); - - let output = process - .wait_with_output() - .expect("couldn't read from stdout/stderr"); - - let out = String::from_utf8_lossy(&output.stderr); - out.into_owned() - }}; -} diff --git a/docs/commands/from-vcf.md b/docs/commands/from-vcf.md index a471d1a2f4..8f16d31167 100644 --- a/docs/commands/from-vcf.md +++ b/docs/commands/from-vcf.md @@ -29,7 +29,7 @@ Pass the output of the `open` command to `from vcf` to get a correctly formatted ``` ```shell -> open contacts.txt | from vcf | get properties | where $it.name == "FN" | pick value +> open contacts.txt | from vcf | get properties | where $it.name == "FN" | select value ─────┬────────────────────── # │ value ─────┼────────────────────── diff --git a/docs/commands/save.md b/docs/commands/save.md index 461fb87726..76a0273b18 100644 --- a/docs/commands/save.md +++ b/docs/commands/save.md @@ -18,13 +18,13 @@ Syntax: `save (path) {flags}` You can save the name of files in a directory like this: ```shell -> ls | where type == File | pick name | save filenames.csv +> ls | where type == File | select name | save filenames.csv ``` Or you can format it in supported formats using one of the `to` commands: ```shell -> ls | where type == File | pick name | to csv | save filenames +> ls | where type == File | select name | to csv | save filenames ``` `filename.csv` and `filenames` are both `csv` formatted files. Nu auto-converts the format if a supported file extension is given. \ No newline at end of file diff --git a/docs/commands/pick.md b/docs/commands/select.md similarity index 97% rename from docs/commands/pick.md rename to docs/commands/select.md index 424460776f..e565671372 100644 --- a/docs/commands/pick.md +++ b/docs/commands/select.md @@ -1,4 +1,4 @@ -# pick +# select This command displays only the column names passed on to it. @@ -15,7 +15,7 @@ This command displays only the column names passed on to it. 3 │ abaracadabra.txt │ File │ │ 401 B │ a month ago │ a month ago │ a month ago 4 │ youshouldeatmorecereal.txt │ File │ │ 768 B │ a month ago │ a month ago │ a month ago ━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━┷━━━━━━━━━━┷━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━ -> ls | pick name +> ls | select name ━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # │ name ───┼──────────────────────────── @@ -30,7 +30,7 @@ This command displays only the column names passed on to it. The order in which you put the column names matters: ```shell -> ls | pick type name size +> ls | select type name size ━━━┯━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━ # │ type │ name │ size ───┼──────┼────────────────────────────┼──────── @@ -40,7 +40,7 @@ The order in which you put the column names matters: 3 │ File │ abaracadabra.txt │ 401 B 4 │ File │ youshouldeatmorecereal.txt │ 768 B ━━━┷━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━ -> ls | pick size type name +> ls | select size type name ━━━┯━━━━━━━━┯━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # │ size │ type │ name ───┼────────┼──────┼──────────────────────────── diff --git a/docs/commands/wrap.md b/docs/commands/wrap.md index f6d907a2c0..bd2ebe88f2 100644 --- a/docs/commands/wrap.md +++ b/docs/commands/wrap.md @@ -33,7 +33,7 @@ Syntax: `wrap ` `wrap` will encapsulate rows as embedded tables : ```shell -/home/chris> ls | pick name type size +/home/chris> ls | select name type size ───┬──────────────┬──────┬───────── # │ name │ type │ size ───┼──────────────┼──────┼───────── @@ -41,7 +41,7 @@ Syntax: `wrap ` 1 │ iso.csv │ File │ 20.8 KB ───┴──────────────┴──────┴───────── -/home/chris> ls | pick name type size | each {wrap details} +/home/chris> ls | select name type size | each {wrap details} ───┬──────────────── # │ details ───┼──────────────── diff --git a/tests/plugins/core_inc.rs b/tests/plugins/core_inc.rs index d90a7b4f4f..c92cd60c47 100644 --- a/tests/plugins/core_inc.rs +++ b/tests/plugins/core_inc.rs @@ -1,15 +1,17 @@ use nu_test_support::fs::Stub::FileWithContent; +use nu_test_support::nu; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error}; #[test] fn can_only_apply_one() { - let actual = nu_error!( + let actual = nu!( cwd: "tests/fixtures/formats", "open cargo_sample.toml | first 1 | inc package.version --major --minor" ); - assert!(actual.contains("Usage: inc field [--major|--minor|--patch]")); + assert!(actual + .err + .contains("Usage: inc field [--major|--minor|--patch]")); } #[test] @@ -28,7 +30,7 @@ fn by_one_with_field_passed() { "open sample.toml | inc package.edition | get package.edition | echo $it" ); - assert_eq!(actual, "2019"); + assert_eq!(actual.out, "2019"); }) } @@ -48,7 +50,7 @@ fn by_one_with_no_field_passed() { "open sample.toml | get package.contributors | inc | echo $it" ); - assert_eq!(actual, "3"); + assert_eq!(actual.out, "3"); }) } @@ -68,7 +70,7 @@ fn semversion_major_inc() { "open sample.toml | inc package.version -M | get package.version | echo $it" ); - assert_eq!(actual, "1.0.0"); + assert_eq!(actual.out, "1.0.0"); }) } @@ -88,7 +90,7 @@ fn semversion_minor_inc() { "open sample.toml | inc package.version --minor | get package.version | echo $it" ); - assert_eq!(actual, "0.2.0"); + assert_eq!(actual.out, "0.2.0"); }) } @@ -108,7 +110,7 @@ fn semversion_patch_inc() { "open sample.toml | inc package.version --patch | get package.version | echo $it" ); - assert_eq!(actual, "0.1.4"); + assert_eq!(actual.out, "0.1.4"); }) } @@ -128,6 +130,6 @@ fn semversion_without_passing_field() { "open sample.toml | get package.version | inc --patch | echo $it" ); - assert_eq!(actual, "0.1.4"); + assert_eq!(actual.out, "0.1.4"); }) } diff --git a/tests/plugins/core_str.rs b/tests/plugins/core_str.rs index bcafb30bec..07b50c4dd1 100644 --- a/tests/plugins/core_str.rs +++ b/tests/plugins/core_str.rs @@ -1,15 +1,15 @@ use nu_test_support::fs::Stub::FileWithContent; use nu_test_support::playground::Playground; -use nu_test_support::{nu, nu_error, pipeline}; +use nu_test_support::{nu, pipeline}; #[test] fn can_only_apply_one() { - let actual = nu_error!( + let actual = nu!( cwd: "tests/fixtures/formats", "open caco3_plastics.csv | first 1 | str origin --downcase --upcase" ); - assert!(actual.contains(r#"--capitalize|--downcase|--upcase|--to-int|--substring "start,end"|--replace|--find-replace [pattern replacement]|to-date-time|--trim]"#)); + assert!(actual.err.contains(r#"--capitalize|--downcase|--upcase|--to-int|--substring "start,end"|--replace|--find-replace [pattern replacement]|to-date-time|--trim]"#)); } #[test] @@ -29,7 +29,7 @@ fn acts_without_passing_field() { "open sample.yml | get environment.global.PROJECT_NAME | str --upcase | echo $it" ); - assert_eq!(actual, "NUSHELL"); + assert_eq!(actual.out, "NUSHELL"); }) } @@ -49,7 +49,7 @@ fn trims() { "open sample.toml | str dependency.name --trim | get dependency.name | echo $it" ); - assert_eq!(actual, "nu"); + assert_eq!(actual.out, "nu"); }) } @@ -69,7 +69,7 @@ fn capitalizes() { "open sample.toml | str dependency.name --capitalize | get dependency.name | echo $it" ); - assert_eq!(actual, "Nu"); + assert_eq!(actual.out, "Nu"); }) } @@ -89,7 +89,7 @@ fn downcases() { "open sample.toml | str dependency.name -d | get dependency.name | echo $it" ); - assert_eq!(actual, "light"); + assert_eq!(actual.out, "light"); }) } @@ -109,7 +109,7 @@ fn upcases() { "open sample.toml | str package.name --upcase | get package.name | echo $it" ); - assert_eq!(actual, "NUSHELL"); + assert_eq!(actual.out, "NUSHELL"); }) } @@ -128,7 +128,7 @@ fn converts_to_int() { "# )); - assert_eq!(actual, "1"); + assert_eq!(actual.out, "1"); } #[test] @@ -152,7 +152,7 @@ fn replaces() { "# )); - assert_eq!(actual, "wykittenshell"); + assert_eq!(actual.out, "wykittenshell"); }) } @@ -177,7 +177,7 @@ fn find_and_replaces() { "# )); - assert_eq!(actual, "1-800-5289"); + assert_eq!(actual.out, "1-800-5289"); }) } @@ -202,6 +202,6 @@ fn find_and_replaces_without_passing_field() { "# )); - assert_eq!(actual, "1-800-5289"); + assert_eq!(actual.out, "1-800-5289"); }) } diff --git a/tests/shell/pipeline/commands/external.rs b/tests/shell/pipeline/commands/external.rs index 1a15e8cda4..c197d8ee59 100644 --- a/tests/shell/pipeline/commands/external.rs +++ b/tests/shell/pipeline/commands/external.rs @@ -1,13 +1,13 @@ -use nu_test_support::{nu, nu_error}; +use nu_test_support::nu; #[test] fn shows_error_for_command_not_found() { - let actual = nu_error!( + let actual = nu!( cwd: ".", "ferris_is_not_here.exe" ); - assert!(actual.contains("Command not found")); + assert!(actual.err.contains("Command not found")); } #[test] @@ -25,7 +25,7 @@ fn automatically_change_directory() { "# ); - assert!(actual.ends_with("autodir")); + assert!(actual.out.ends_with("autodir")); }) } @@ -44,7 +44,7 @@ fn automatically_change_directory_with_trailing_slash_and_same_name_as_command() "# ); - assert!(actual.ends_with("cd")); + assert!(actual.out.ends_with("cd")); }) } @@ -52,7 +52,7 @@ fn automatically_change_directory_with_trailing_slash_and_same_name_as_command() fn correctly_escape_external_arguments() { let actual = nu!(cwd: ".", r#"^echo '$0'"#); - assert_eq!(actual, "$0"); + assert_eq!(actual.out, "$0"); } mod it_evaluation { @@ -81,7 +81,7 @@ mod it_evaluation { "# )); - assert_eq!(actual, "jonathan_likes_cake.txt"); + assert_eq!(actual.out, "jonathan_likes_cake.txt"); }) } @@ -108,7 +108,7 @@ mod it_evaluation { "# )); - assert_eq!(actual, "AndrásWithKitKat"); + assert_eq!(actual.out, "AndrásWithKitKat"); }) } @@ -131,18 +131,18 @@ mod it_evaluation { "# )); - assert_eq!(actual, "zion"); + assert_eq!(actual.out, "zion"); }) } } mod stdin_evaluation { - use super::{nu, nu_error}; + use super::nu; use nu_test_support::pipeline; #[test] fn does_not_panic_with_no_newline_in_stream() { - let stderr = nu_error!( + let actual = nu!( cwd: ".", pipeline(r#" nonu "where's the nuline?" @@ -150,7 +150,7 @@ mod stdin_evaluation { "# )); - assert_eq!(stderr, ""); + assert_eq!(actual.err, ""); } #[test] @@ -164,7 +164,8 @@ mod stdin_evaluation { | lines | first 1 "# - )); + )) + .out; assert_eq!(stdout, "y"); } @@ -179,7 +180,7 @@ mod external_words { cococo joturner@foo.bar.baz "#); - assert_eq!(actual, "joturner@foo.bar.baz"); + assert_eq!(actual.out, "joturner@foo.bar.baz"); } } @@ -192,7 +193,7 @@ mod nu_commands { nu -c "echo 'foo'" "#); - assert_eq!(actual, "foo"); + assert_eq!(actual.out, "foo"); } } @@ -205,7 +206,7 @@ mod nu_script { nu script.nu "#); - assert_eq!(actual, "done"); + assert_eq!(actual.out, "done"); } #[test] @@ -214,7 +215,7 @@ mod nu_script { nu script_multiline.nu "#); - assert_eq!(actual, "23"); + assert_eq!(actual.out, "23"); } } @@ -231,8 +232,8 @@ mod tilde_expansion { ); assert!( - !actual.contains('~'), - format!("'{}' should not contain ~", actual) + !actual.out.contains('~'), + format!("'{}' should not contain ~", actual.out) ); } @@ -245,6 +246,6 @@ mod tilde_expansion { "# ); - assert_eq!(actual, "1~1"); + assert_eq!(actual.out, "1~1"); } } diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 04027aabd6..144bdab039 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -28,7 +28,7 @@ fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() { "# )); - assert_eq!(actual, "AndKitKat"); + assert_eq!(actual.out, "AndKitKat"); }) } @@ -39,11 +39,11 @@ fn can_process_one_row_from_internal_and_pipes_it_to_stdin_of_external() { r#"echo "nushelll" | chop"# ); - assert_eq!(actual, "nushell"); + assert_eq!(actual.out, "nushell"); } mod parse { - use nu_test_support::nu_error; + use nu_test_support::nu; /* The debug command's signature is: @@ -58,49 +58,49 @@ mod parse { #[test] fn errors_if_flag_passed_is_not_exact() { - let actual = nu_error!(cwd: ".", "debug -ra"); + let actual = nu!(cwd: ".", "debug -ra"); assert!( - actual.contains("unexpected flag"), + actual.err.contains("unexpected flag"), format!( "error message '{}' should contain 'unexpected flag'", - actual + actual.err ) ); - let actual = nu_error!(cwd: ".", "debug --rawx"); + let actual = nu!(cwd: ".", "debug --rawx"); assert!( - actual.contains("unexpected flag"), + actual.err.contains("unexpected flag"), format!( "error message '{}' should contain 'unexpected flag'", - actual + actual.err ) ); } #[test] fn errors_if_flag_is_not_supported() { - let actual = nu_error!(cwd: ".", "debug --ferris"); + let actual = nu!(cwd: ".", "debug --ferris"); assert!( - actual.contains("unexpected flag"), + actual.err.contains("unexpected flag"), format!( "error message '{}' should contain 'unexpected flag'", - actual + actual.err ) ); } #[test] fn errors_if_passed_an_unexpected_argument() { - let actual = nu_error!(cwd: ".", "debug ferris"); + let actual = nu!(cwd: ".", "debug ferris"); assert!( - actual.contains("unexpected argument"), + actual.err.contains("unexpected argument"), format!( "error message '{}' should contain 'unexpected argument'", - actual + actual.err ) ); } @@ -122,8 +122,8 @@ mod tilde_expansion { ); assert!( - !actual.contains('~'), - format!("'{}' should not contain ~", actual) + !actual.out.contains('~'), + format!("'{}' should not contain ~", actual.out) ); } @@ -136,7 +136,7 @@ mod tilde_expansion { "# ); - assert_eq!(actual, "1~1"); + assert_eq!(actual.out, "1~1"); } #[test] @@ -157,7 +157,7 @@ mod tilde_expansion { )); assert_eq!( - actual, + actual.out, r#"["andres.txt","gedge.txt","jonathan.txt","yehuda.txt"]"# ); }) diff --git a/tests/shell/pipeline/mod.rs b/tests/shell/pipeline/mod.rs index 6fc8a40177..e8fb3af058 100644 --- a/tests/shell/pipeline/mod.rs +++ b/tests/shell/pipeline/mod.rs @@ -6,5 +6,5 @@ use nu_test_support::nu; fn doesnt_break_on_utf8() { let actual = nu!(cwd: ".", "echo ö"); - assert_eq!(actual, "ö", "'{}' should contain ö", actual); + assert_eq!(actual.out, "ö", "'{}' should contain ö", actual.out); }