Pick->Select rename. Integration tests changes. (#1725)

Pick->Select rename. Integration tests changes.
This commit is contained in:
Andrés N. Robalino 2020-05-07 06:03:43 -05:00 committed by GitHub
parent c3efdf2689
commit 96e5fc05a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
78 changed files with 380 additions and 411 deletions

View File

@ -285,7 +285,7 @@ pub fn create_default_context(
whole_stream_command(Parse), whole_stream_command(Parse),
// Column manipulation // Column manipulation
whole_stream_command(Reject), whole_stream_command(Reject),
whole_stream_command(Pick), whole_stream_command(Select),
whole_stream_command(Get), whole_stream_command(Get),
whole_stream_command(Update), whole_stream_command(Update),
whole_stream_command(Insert), whole_stream_command(Insert),

View File

@ -70,7 +70,6 @@ pub(crate) mod next;
pub(crate) mod nth; pub(crate) mod nth;
pub(crate) mod open; pub(crate) mod open;
pub(crate) mod parse; pub(crate) mod parse;
pub(crate) mod pick;
pub(crate) mod pivot; pub(crate) mod pivot;
pub(crate) mod plugin; pub(crate) mod plugin;
pub(crate) mod prepend; pub(crate) mod prepend;
@ -86,6 +85,7 @@ pub(crate) mod rm;
pub(crate) mod run_alias; pub(crate) mod run_alias;
pub(crate) mod run_external; pub(crate) mod run_external;
pub(crate) mod save; pub(crate) mod save;
pub(crate) mod select;
pub(crate) mod shells; pub(crate) mod shells;
pub(crate) mod shuffle; pub(crate) mod shuffle;
pub(crate) mod size; pub(crate) mod size;
@ -194,7 +194,6 @@ pub(crate) use next::Next;
pub(crate) use nth::Nth; pub(crate) use nth::Nth;
pub(crate) use open::Open; pub(crate) use open::Open;
pub(crate) use parse::Parse; pub(crate) use parse::Parse;
pub(crate) use pick::Pick;
pub(crate) use pivot::Pivot; pub(crate) use pivot::Pivot;
pub(crate) use prepend::Prepend; pub(crate) use prepend::Prepend;
pub(crate) use prev::Previous; pub(crate) use prev::Previous;
@ -208,6 +207,7 @@ pub(crate) use reverse::Reverse;
pub(crate) use rm::Remove; pub(crate) use rm::Remove;
pub(crate) use run_external::RunExternalCommand; pub(crate) use run_external::RunExternalCommand;
pub(crate) use save::Save; pub(crate) use save::Save;
pub(crate) use select::Select;
pub(crate) use shells::Shells; pub(crate) use shells::Shells;
pub(crate) use shuffle::Shuffle; pub(crate) use shuffle::Shuffle;
pub(crate) use size::Size; pub(crate) use size::Size;

View File

@ -10,19 +10,19 @@ use nu_source::span_for_spanned_list;
use nu_value_ext::{as_string, get_data_by_column_path}; use nu_value_ext::{as_string, get_data_by_column_path};
#[derive(Deserialize)] #[derive(Deserialize)]
struct PickArgs { struct SelectArgs {
rest: Vec<ColumnPath>, rest: Vec<ColumnPath>,
} }
pub struct Pick; pub struct Select;
impl WholeStreamCommand for Pick { impl WholeStreamCommand for Select {
fn name(&self) -> &str { fn name(&self) -> &str {
"pick" "select"
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("pick").rest( Signature::build("select").rest(
SyntaxShape::ColumnPath, SyntaxShape::ColumnPath,
"the columns to select from the table", "the columns to select from the table",
) )
@ -37,19 +37,19 @@ impl WholeStreamCommand for Pick {
args: CommandArgs, args: CommandArgs,
registry: &CommandRegistry, registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> { ) -> Result<OutputStream, ShellError> {
args.process(registry, pick)?.run() args.process(registry, select)?.run()
} }
} }
fn pick( fn select(
PickArgs { rest: mut fields }: PickArgs, SelectArgs { rest: mut fields }: SelectArgs,
RunnableContext { RunnableContext {
mut input, name, .. mut input, name, ..
}: RunnableContext, }: RunnableContext,
) -> Result<OutputStream, ShellError> { ) -> Result<OutputStream, ShellError> {
if fields.is_empty() { if fields.is_empty() {
return Err(ShellError::labeled_error( return Err(ShellError::labeled_error(
"Pick requires columns to pick", "Select requires columns to select",
"needs parameter", "needs parameter",
name, name,
)); ));
@ -76,7 +76,7 @@ fn pick(
if let PathMember { unspanned: UnspannedPathMember::String(column), .. } = path_member_tried { if let PathMember { unspanned: UnspannedPathMember::String(column), .. } = path_member_tried {
return ShellError::labeled_error_with_secondary( return ShellError::labeled_error_with_secondary(
"No data to fetch.", "No data to fetch.",
format!("Couldn't pick column \"{}\"", column), format!("Couldn't select column \"{}\"", column),
path_member_tried.span, path_member_tried.span,
format!("How about exploring it with \"get\"? Check the input is appropriate originating from here"), format!("How about exploring it with \"get\"? Check the input is appropriate originating from here"),
obj_source.tag.span) obj_source.tag.span)

View File

@ -12,6 +12,6 @@ fn alias_args_work() {
"# "#
); );
assert_eq!(actual, "[1,2]"); assert_eq!(actual.out, "[1,2]");
}) })
} }

View File

@ -25,6 +25,6 @@ fn adds_a_row_to_the_end() {
"# "#
)); ));
assert_eq!(actual, "pollo loco"); assert_eq!(actual.out, "pollo loco");
}) })
} }

View File

@ -9,7 +9,7 @@ fn calculates_two_plus_two() {
"# "#
)); ));
assert!(actual.contains("4.0")); assert!(actual.out.contains("4.0"));
} }
#[test] #[test]
@ -21,7 +21,7 @@ fn calculates_two_to_the_power_six() {
"# "#
)); ));
assert!(actual.contains("64.0")); assert!(actual.out.contains("64.0"));
} }
#[test] #[test]
@ -33,7 +33,7 @@ fn calculates_three_multiplied_by_five() {
"# "#
)); ));
assert!(actual.contains("15.0")); assert!(actual.out.contains("15.0"));
} }
#[test] #[test]
@ -45,5 +45,5 @@ fn calculates_twenty_four_divided_by_two() {
"# "#
)); ));
assert!(actual.contains("12.0")); assert!(actual.out.contains("12.0"));
} }

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::{Stub::EmptyFile, Stub::FileWithContent}; use nu_test_support::fs::{Stub::EmptyFile, Stub::FileWithContent};
use nu_test_support::nu;
use nu_test_support::playground::Playground; use nu_test_support::playground::Playground;
use nu_test_support::{nu, nu_error};
use std::path::PathBuf; use std::path::PathBuf;
#[test] #[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() 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() 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() 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")); 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!( assert_eq!(
PathBuf::from(actual), PathBuf::from(actual.out),
dirs.test().join("robalino turner katz") dirs.test().join("robalino turner katz")
); );
}) })
@ -164,34 +167,42 @@ fn filesystem_not_a_directory() {
Playground::setup("cd_test_10", |dirs, sandbox| { Playground::setup("cd_test_10", |dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("ferris_did_it.txt")]); sandbox.with_files(vec![EmptyFile("ferris_did_it.txt")]);
let actual = nu_error!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
"cd ferris_did_it.txt" "cd ferris_did_it.txt"
); );
assert!(actual.contains("ferris_did_it.txt"), "actual={:?}", actual); assert!(
assert!(actual.contains("is not a directory"), "actual={:?}", actual); actual.err.contains("ferris_did_it.txt"),
"actual={:?}",
actual.err
);
assert!(
actual.err.contains("is not a directory"),
"actual={:?}",
actual.err
);
}) })
} }
#[test] #[test]
fn filesystem_directory_not_found() { fn filesystem_directory_not_found() {
Playground::setup("cd_test_11", |dirs, _| { Playground::setup("cd_test_11", |dirs, _| {
let actual = nu_error!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
"cd dir_that_does_not_exist" "cd dir_that_does_not_exist"
); );
assert!( assert!(
actual.contains("dir_that_does_not_exist"), actual.err.contains("dir_that_does_not_exist"),
"actual={:?}", "actual={:?}",
actual actual.err
); );
assert!( assert!(
actual.contains("directory not found"), actual.err.contains("directory not found"),
"actual={:?}", "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] #[test]
fn valuesystem_path_not_found() { fn valuesystem_path_not_found() {
Playground::setup("cd_test_19", |dirs, _| { Playground::setup("cd_test_19", |dirs, _| {
let actual = nu_error!( let actual = nu!(
cwd: dirs.formats(), cwd: dirs.formats(),
r#" r#"
enter cargo_sample.toml enter cargo_sample.toml
@ -414,7 +428,7 @@ fn valuesystem_path_not_found() {
"# "#
); );
assert!(actual.contains("Can not change to path inside")); assert!(actual.err.contains("Can not change to path inside"));
assert!(actual.contains("No such path exists")); assert!(actual.err.contains("No such path exists"));
}) })
} }

View File

@ -30,7 +30,7 @@ fn discards_rows_where_given_column_is_empty() {
"# "#
)); ));
assert_eq!(actual, "3"); assert_eq!(actual.out, "3");
}); });
} }
#[test] #[test]
@ -47,6 +47,6 @@ fn discards_empty_rows_by_default() {
"# "#
)); ));
assert_eq!(actual, "4"); assert_eq!(actual.out, "4");
}); });
} }

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::{files_exist_at, AbsoluteFile, Stub::EmptyFile}; 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::playground::Playground;
use nu_test_support::{nu, nu_error};
use std::path::Path; use std::path::Path;
#[test] #[test]
@ -34,13 +34,13 @@ fn copies_the_file_inside_directory_if_path_to_copy_is_directory() {
#[test] #[test]
fn error_if_attempting_to_copy_a_directory_to_another_directory() { fn error_if_attempting_to_copy_a_directory_to_another_directory() {
Playground::setup("cp_test_3", |dirs, _| { Playground::setup("cp_test_3", |dirs, _| {
let actual = nu_error!( let actual = nu!(
cwd: dirs.formats(), cwd: dirs.formats(),
"cp ../formats {}", dirs.test() "cp ../formats {}", dirs.test()
); );
assert!(actual.contains("../formats")); assert!(actual.err.contains("../formats"));
assert!(actual.contains("resolves to a directory (not copied)")); assert!(actual.err.contains("resolves to a directory (not copied)"));
}); });
} }

View File

@ -31,6 +31,6 @@ fn adds_row_data_if_column_missing() {
"# "#
)); ));
assert_eq!(actual, "2"); assert_eq!(actual.out, "2");
}); });
} }

View File

@ -7,5 +7,5 @@ fn drop_rows() {
r#"echo '[{"foo": 3}, {"foo": 8}, {"foo": 4}]' | from json | drop 2 | get foo | sum | echo $it"# 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");
} }

View File

@ -9,5 +9,5 @@ fn each_works_separately() {
"# "#
)); ));
assert_eq!(actual, "[11,12,13]"); assert_eq!(actual.out, "[11,12,13]");
} }

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::{files_exist_at, Stub::EmptyFile}; 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::playground::Playground;
use nu_test_support::{nu, nu_error};
use std::path::Path; use std::path::Path;
#[test] #[test]
@ -75,12 +75,12 @@ fn knows_the_filesystems_entered() {
#[test] #[test]
fn errors_if_file_not_found() { fn errors_if_file_not_found() {
Playground::setup("enter_test_2", |dirs, _| { Playground::setup("enter_test_2", |dirs, _| {
let actual = nu_error!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
"enter i_dont_exist.csv" "enter i_dont_exist.csv"
); );
assert!(actual.contains("File could not be opened")); assert!(actual.err.contains("File could not be opened"));
assert!(actual.contains("file not found")); assert!(actual.err.contains("file not found"));
}) })
} }

View File

@ -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");
}) })
} }

View File

@ -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] #[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");
} }

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::Stub::FileWithContent; use nu_test_support::fs::Stub::FileWithContent;
use nu_test_support::playground::Playground; use nu_test_support::playground::Playground;
use nu_test_support::{nu, nu_error, pipeline}; use nu_test_support::{nu, pipeline};
#[test] #[test]
fn fetches_a_row() { 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 <andres@androbtech.com>"); assert_eq!(actual.out, "Andrés N. Robalino <andres@androbtech.com>");
}) })
} }
#[test] #[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( cwd: dirs.test(), pipeline(
r#" r#"
open sample.toml open sample.toml
@ -155,16 +155,16 @@ fn errors_fetching_by_column_not_present() {
)); ));
assert!( assert!(
actual.contains("Unknown column"), actual.err.contains("Unknown column"),
format!("actual: {:?}", actual) format!("actual: {:?}", actual.err)
); );
assert!( assert!(
actual.contains("There isn't a column named 'taco'"), actual.err.contains("There isn't a column named 'taco'"),
format!("actual: {:?}", actual) format!("actual: {:?}", actual.err)
); );
assert!( assert!(
actual.contains("Perhaps you meant 'taconushell'?"), actual.err.contains("Perhaps you meant 'taconushell'?"),
format!("actual: {:?}", actual) 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( cwd: dirs.test(), pipeline(
r#" r#"
open sample.toml open sample.toml
@ -189,16 +189,18 @@ fn errors_fetching_by_column_using_a_number() {
)); ));
assert!( assert!(
actual.contains("No rows available"), actual.err.contains("No rows available"),
format!("actual: {:?}", actual) format!("actual: {:?}", actual.err)
); );
assert!( assert!(
actual.contains("A row at '0' can't be indexed."), actual.err.contains("A row at '0' can't be indexed."),
format!("actual: {:?}", actual) format!("actual: {:?}", actual.err)
); );
assert!( assert!(
actual.contains("Appears to contain columns. Columns available: 0"), actual
format!("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( cwd: dirs.test(), pipeline(
r#" r#"
open sample.toml open sample.toml
@ -222,16 +224,16 @@ fn errors_fetching_by_index_out_of_bounds() {
)); ));
assert!( assert!(
actual.contains("Row not found"), actual.err.contains("Row not found"),
format!("actual: {:?}", actual) format!("actual: {:?}", actual.err)
); );
assert!( assert!(
actual.contains("There isn't a row indexed at 3"), actual.err.contains("There isn't a row indexed at 3"),
format!("actual: {:?}", actual) format!("actual: {:?}", actual.err)
); );
assert!( assert!(
actual.contains("The table only has 3 rows (0 to 2)"), actual.err.contains("The table only has 3 rows (0 to 2)"),
format!("actual: {:?}", actual) 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"# r#"echo '[{"foo bar": {"baz": 4}}]' | from json | get "foo bar".baz | echo $it"#
); );
assert_eq!(actual, "4"); assert_eq!(actual.out, "4");
} }

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground; use nu_test_support::playground::Playground;
use nu_test_support::{nu, nu_error, pipeline}; use nu_test_support::{nu, pipeline};
#[test] #[test]
fn groups() { 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( cwd: dirs.test(), pipeline(
r#" r#"
open los_tres_caballeros.csv 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"));
}) })
} }

View File

@ -12,7 +12,7 @@ fn headers_uses_first_row_as_header() {
| from json"# | from json"#
)); ));
assert_eq!(actual, "r1c0r2c0") assert_eq!(actual.out, "r1c0r2c0")
} }
#[test] #[test]
@ -27,5 +27,5 @@ fn headers_adds_missing_column_name() {
| from json"# | from json"#
)); ));
assert_eq!(actual, "r1c1r2c1") assert_eq!(actual.out, "r1c1r2c1")
} }

View File

@ -26,7 +26,10 @@ fn summarizes() {
"# "#
)); ));
assert_eq!(actual, "**************************************************"); assert_eq!(
actual.out,
"**************************************************"
);
// 50% // 50%
}) })
} }
@ -55,7 +58,7 @@ fn help() {
"# "#
)); ));
assert_eq!(help_short, help_command); assert_eq!(help_short.out, help_command.out);
assert_eq!(help_long, help_command); assert_eq!(help_long.out, help_command.out);
}) })
} }

View File

@ -12,5 +12,5 @@ fn insert_plugin() {
"# "#
)); ));
assert_eq!(actual, "1"); assert_eq!(actual.out, "1");
} }

View File

@ -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");
}) })
} }

View File

@ -27,6 +27,6 @@ fn rows() {
"# "#
)); ));
assert_eq!(actual, "4"); assert_eq!(actual.out, "4");
}) })
} }

View File

@ -46,6 +46,6 @@ fn condition_is_met() {
"# "#
)); ));
assert_eq!(actual, "8"); assert_eq!(actual.out, "8");
}) })
} }

View File

@ -46,6 +46,6 @@ fn condition_is_met() {
"# "#
)); ));
assert_eq!(actual, "4"); assert_eq!(actual.out, "4");
}) })
} }

View File

@ -9,7 +9,7 @@ fn gets_the_last_row() {
"ls | sort-by name | last 1 | get name | trim | echo $it" "ls | sort-by name | last 1 | get name | trim | echo $it"
); );
assert_eq!(actual, "utf16.ini"); assert_eq!(actual.out, "utf16.ini");
} }
#[test] #[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");
}) })
} }

View File

@ -17,5 +17,5 @@ fn lines() {
"# "#
)); ));
assert_eq!(actual, "rustyline"); assert_eq!(actual.out, "rustyline");
} }

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::Stub::EmptyFile; use nu_test_support::fs::Stub::EmptyFile;
use nu_test_support::playground::Playground; use nu_test_support::playground::Playground;
use nu_test_support::{nu, nu_error, pipeline}; use nu_test_support::{nu, pipeline};
#[test] #[test]
fn lists_regular_files() { 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| { Playground::setup("ls_test_5", |dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("root1.txt"), EmptyFile("root2.txt")]); sandbox.with_files(vec![EmptyFile("root1.txt"), EmptyFile("root2.txt")]);
let actual = nu_error!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
"ls root3*" "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");
}) })
} }

View File

@ -9,7 +9,7 @@ fn one_arg() {
"# "#
)); ));
assert_eq!(actual, "1"); assert_eq!(actual.out, "1");
} }
#[test] #[test]
@ -21,7 +21,7 @@ fn add() {
"# "#
)); ));
assert_eq!(actual, "2"); assert_eq!(actual.out, "2");
} }
#[test] #[test]
@ -33,7 +33,7 @@ fn add_compount() {
"# "#
)); ));
assert_eq!(actual, "5"); assert_eq!(actual.out, "5");
} }
#[test] #[test]
@ -45,7 +45,7 @@ fn precedence_of_operators() {
"# "#
)); ));
assert_eq!(actual, "5"); assert_eq!(actual.out, "5");
} }
#[test] #[test]
@ -57,7 +57,7 @@ fn precedence_of_operators2() {
"# "#
)); ));
assert_eq!(actual, "6"); assert_eq!(actual.out, "6");
} }
#[test] #[test]
@ -69,7 +69,7 @@ fn division_of_ints() {
"# "#
)); ));
assert_eq!(actual, "2"); assert_eq!(actual.out, "2");
} }
#[test] #[test]
@ -81,7 +81,7 @@ fn division_of_ints2() {
"# "#
)); ));
assert_eq!(actual, "0.25"); assert_eq!(actual.out, "0.25");
} }
#[test] #[test]
@ -93,7 +93,7 @@ fn parens_precedence() {
"# "#
)); ));
assert_eq!(actual, "12"); assert_eq!(actual.out, "12");
} }
#[test] #[test]
@ -105,7 +105,7 @@ fn compound_comparison() {
"# "#
)); ));
assert_eq!(actual, "true"); assert_eq!(actual.out, "true");
} }
#[test] #[test]
@ -117,7 +117,7 @@ fn compound_comparison2() {
"# "#
)); ));
assert_eq!(actual, "true"); assert_eq!(actual.out, "true");
} }
#[test] #[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] #[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}]"#);
} }

View File

@ -38,6 +38,6 @@ fn row() {
"# "#
)); ));
assert_eq!(actual, "2"); assert_eq!(actual.out, "2");
}) })
} }

View File

@ -28,13 +28,13 @@ mod mkdir;
mod mv; mod mv;
mod open; mod open;
mod parse; mod parse;
mod pick;
mod prepend; mod prepend;
mod range; mod range;
mod rename; mod rename;
mod reverse; mod reverse;
mod rm; mod rm;
mod save; mod save;
mod select;
mod semicolon; mod semicolon;
mod skip_until; mod skip_until;
mod sort_by; mod sort_by;

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::{files_exist_at, Stub::EmptyFile}; 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::playground::Playground;
use nu_test_support::{nu, nu_error};
#[test] #[test]
fn moves_a_file() { fn moves_a_file() {
@ -223,11 +223,11 @@ fn moves_a_directory_with_files() {
fn errors_if_source_doesnt_exist() { fn errors_if_source_doesnt_exist() {
Playground::setup("mv_test_10", |dirs, sandbox| { Playground::setup("mv_test_10", |dirs, sandbox| {
sandbox.mkdir("test_folder"); sandbox.mkdir("test_folder");
let actual = nu_error!( let actual = nu!(
cwd: dirs.root(), cwd: dirs.root(),
"mv non-existing-file test_folder/" "mv non-existing-file test_folder/"
); );
assert!(actual.contains("Invalid file or pattern")); assert!(actual.err.contains("Invalid file or pattern"));
}) })
} }

View File

@ -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");
}); });
} }

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground; use nu_test_support::playground::Playground;
use nu_test_support::{nu, nu_error, pipeline}; use nu_test_support::{nu, pipeline};
#[test] #[test]
fn parses_csv() { 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" "open sample.bson | get root | nth 0 | get b | echo $it"
); );
assert_eq!(actual, "hello"); assert_eq!(actual.out, "hello");
} }
#[test] #[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: // sample.db has the following format:
@ -143,7 +143,7 @@ fn parses_sqlite() {
"# "#
)); ));
assert_eq!(actual, "hello"); assert_eq!(actual.out, "hello");
} }
#[test] #[test]
@ -153,7 +153,7 @@ fn parses_toml() {
"open cargo_sample.toml | get package.edition | echo $it" "open cargo_sample.toml | get package.edition | echo $it"
); );
assert_eq!(actual, "2018"); assert_eq!(actual.out, "2018");
} }
#[test] #[test]
@ -168,7 +168,7 @@ fn parses_tsv() {
"# "#
)); ));
assert_eq!(actual, "SPAIN") assert_eq!(actual.out, "SPAIN")
} }
#[test] #[test]
@ -182,7 +182,7 @@ fn parses_json() {
"# "#
)); ));
assert_eq!(actual, "markup") assert_eq!(actual.out, "markup")
} }
#[test] #[test]
@ -193,7 +193,7 @@ fn parses_xml() {
); );
assert_eq!( assert_eq!(
actual, actual.out,
"http://www.jonathanturner.org/2015/10/off-to-new-adventures.html" "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" "open sample.ini | get SectionOne.integer | echo $it"
); );
assert_eq!(actual, "1234") assert_eq!(actual.out, "1234")
} }
#[test] #[test]
@ -215,16 +215,16 @@ fn parses_utf16_ini() {
"open utf16.ini | get '.ShellClassInfo' | get IconIndex | echo $it" "open utf16.ini | get '.ShellClassInfo' | get IconIndex | echo $it"
); );
assert_eq!(actual, "-236") assert_eq!(actual.out, "-236")
} }
#[test] #[test]
fn errors_if_file_not_found() { fn errors_if_file_not_found() {
let actual = nu_error!( let actual = nu!(
cwd: "tests/fixtures/formats", cwd: "tests/fixtures/formats",
"open i_dont_exist.txt" "open i_dont_exist.txt"
); );
assert!(actual.contains("File could not be opened")); assert!(actual.err.contains("File could not be opened"));
assert!(actual.contains("file not found")); assert!(actual.err.contains("file not found"));
} }

View File

@ -25,6 +25,6 @@ fn extracts_fields_from_the_given_the_pattern() {
"# "#
)); ));
assert_eq!(actual, "JonathanParsed"); assert_eq!(actual.out, "JonathanParsed");
}) })
} }

View File

@ -25,6 +25,6 @@ fn adds_a_row_to_the_beginning() {
"# "#
)); ));
assert_eq!(actual, "pollo loco"); assert_eq!(actual.out, "pollo loco");
}) })
} }

View File

@ -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");
}); });
} }

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground; use nu_test_support::playground::Playground;
use nu_test_support::{nu, nu_error, pipeline}; use nu_test_support::{nu, pipeline};
#[test] #[test]
fn changes_the_column_name() { 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( cwd: dirs.test(), pipeline(
r#" r#"
open los_cuatro_mosqueteros.txt open los_cuatro_mosqueteros.txt
@ -86,12 +86,12 @@ fn errors_if_no_columns_present() {
)); ));
assert!( assert!(
actual.contains("no column names available"), actual.err.contains("no column names available"),
format!("actual: {:?}", actual) format!("actual: {:?}", actual.err)
); );
assert!( assert!(
actual.contains("can't rename"), actual.err.contains("can't rename"),
format!("actual: {:?}", actual) format!("actual: {:?}", actual.err)
); );
}) })
} }

View File

@ -7,5 +7,5 @@ fn can_get_reverse_first() {
"ls | sort-by name | reverse | first 1 | get name | trim | echo $it" "ls | sort-by name | reverse | first 1 | get name | trim | echo $it"
); );
assert_eq!(actual, "utf16.ini"); assert_eq!(actual.out, "utf16.ini");
} }

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::{files_exist_at, Stub::EmptyFile}; 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::playground::Playground;
use nu_test_support::{nu, nu_error};
#[test] #[test]
fn removes_a_file() { 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| { Playground::setup("rm_test_6", |dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("some_empty_file.txt")]); sandbox.with_files(vec![EmptyFile("some_empty_file.txt")]);
let actual = nu_error!( let actual = nu!(
cwd: dirs.root(), cwd: dirs.root(),
"rm rm_test_6" "rm rm_test_6"
); );
assert!(dirs.test().exists()); assert!(dirs.test().exists());
assert!(actual.contains("cannot remove non-empty directory")); assert!(actual.err.contains("cannot remove non-empty directory"));
}) })
} }
#[test] #[test]
fn errors_if_attempting_to_delete_single_dot_as_argument() { fn errors_if_attempting_to_delete_single_dot_as_argument() {
Playground::setup("rm_test_7", |dirs, _| { Playground::setup("rm_test_7", |dirs, _| {
let actual = nu_error!( let actual = nu!(
cwd: dirs.root(), cwd: dirs.root(),
"rm ." "rm ."
); );
assert!(actual.contains("cannot remove any parent directory")); assert!(actual.err.contains("cannot remove any parent directory"));
}) })
} }
#[test] #[test]
fn errors_if_attempting_to_delete_two_dot_as_argument() { fn errors_if_attempting_to_delete_two_dot_as_argument() {
Playground::setup("rm_test_8", |dirs, _| { Playground::setup("rm_test_8", |dirs, _| {
let actual = nu_error!( let actual = nu!(
cwd: dirs.root(), cwd: dirs.root(),
"rm .." "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())), Playground::glob_vec(&format!("{}/*", dirs.test().display())),
Vec::<std::path::PathBuf>::new() Vec::<std::path::PathBuf>::new()
); );
assert!(!actual.contains("error")) assert!(!actual.out.contains("error"))
}) })
} }

View File

@ -4,7 +4,7 @@ use nu_test_support::{nu, pipeline};
#[test] #[test]
fn regular_columns() { fn regular_columns() {
Playground::setup("pick_test_1", |dirs, sandbox| { Playground::setup("select_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed( sandbox.with_files(vec![FileWithContentToBeTrimmed(
"los_tres_caballeros.csv", "los_tres_caballeros.csv",
r#" r#"
@ -19,20 +19,20 @@ fn regular_columns() {
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" r#"
open los_tres_caballeros.csv open los_tres_caballeros.csv
| pick rusty_at last_name | select rusty_at last_name
| nth 0 | nth 0
| get last_name | get last_name
| echo $it | echo $it
"# "#
)); ));
assert_eq!(actual, "Robalino"); assert_eq!(actual.out, "Robalino");
}) })
} }
#[test] #[test]
fn complex_nested_columns() { fn complex_nested_columns() {
Playground::setup("pick_test_2", |dirs, sandbox| { Playground::setup("select_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed( sandbox.with_files(vec![FileWithContentToBeTrimmed(
"los_tres_caballeros.json", "los_tres_caballeros.json",
r#" r#"
@ -62,20 +62,20 @@ fn complex_nested_columns() {
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" r#"
open los_tres_caballeros.json 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" | where "nu.releases.version" > "0.8"
| get "nu.releases.version" | get "nu.releases.version"
| echo $it | echo $it
"# "#
)); ));
assert_eq!(actual, "0.9999999"); assert_eq!(actual.out, "0.9999999");
}) })
} }
#[test] #[test]
fn allows_if_given_unknown_column_name_is_missing() { 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( sandbox.with_files(vec![FileWithContentToBeTrimmed(
"los_tres_caballeros.csv", "los_tres_caballeros.csv",
r#" r#"
@ -90,12 +90,12 @@ fn allows_if_given_unknown_column_name_is_missing() {
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" r#"
open los_tres_caballeros.csv open los_tres_caballeros.csv
| pick rrusty_at first_name | select rrusty_at first_name
| count | count
| echo $it | echo $it
"# "#
)); ));
assert_eq!(actual, "3"); assert_eq!(actual.out, "3");
}) })
} }

View File

@ -12,7 +12,7 @@ fn semicolon_allows_lhs_to_complete() {
let path = dirs.test().join("i_will_be_created_semi.txt"); let path = dirs.test().join("i_will_be_created_semi.txt");
assert!(path.exists()); 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"));
} }

View File

@ -37,7 +37,7 @@ fn condition_is_met() {
| skip 2 | skip 2
| split-column ',' | split-column ','
| headers | headers
| skip-until "Chicken Collection" != "Red Chickens" | skip-until "Chicken Collection" == "Red Chickens"
| str "31/04/2020" --to-int | str "31/04/2020" --to-int
| get "31/04/2020" | get "31/04/2020"
| sum | sum
@ -45,6 +45,6 @@ fn condition_is_met() {
"# "#
)); ));
assert_eq!(actual, "12"); assert_eq!(actual.out, "12");
}) })
} }

View File

@ -19,7 +19,7 @@ fn by_column() {
"# "#
)); ));
assert_eq!(actual, "description"); assert_eq!(actual.out, "description");
} }
#[test] #[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\"]");
} }

View File

@ -1,6 +1,6 @@
use nu_test_support::fs::Stub::{EmptyFile, FileWithContentToBeTrimmed}; use nu_test_support::fs::Stub::{EmptyFile, FileWithContentToBeTrimmed};
use nu_test_support::playground::Playground; use nu_test_support::playground::Playground;
use nu_test_support::{nu, nu_error, pipeline}; use nu_test_support::{nu, pipeline};
#[test] #[test]
fn splits() { 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"), EmptyFile("arepas.clu"),
]); ]);
let actual = nu_error!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" r#"
ls 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"));
}) })
} }

View File

@ -16,5 +16,5 @@ fn by_column() {
"# "#
)); ));
assert_eq!(actual, "name"); assert_eq!(actual.out, "name");
} }

View File

@ -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");
}) })
} }

View File

@ -19,7 +19,7 @@ fn string() {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline(&commandline 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)
}) })
} }

View File

@ -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( cwd: dirs.test(), pipeline(
r#" r#"
open los_tres_caballeros.csv open los_tres_caballeros.csv
| pick type | select type
| uniq | uniq
| count | count
| echo $it | echo $it
"# "#
)); ));
assert_eq!(actual, "2"); assert_eq!(actual.out, "2");
}) })
} }
@ -121,7 +121,7 @@ fn nested_json_structures() {
| echo $it | 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");
} }

View File

@ -12,7 +12,7 @@ fn sets_the_column() {
"# "#
)); ));
assert_eq!(actual, "0.7.0"); assert_eq!(actual.out, "0.7.0");
} }
#[test] #[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");
} }

View File

@ -7,7 +7,7 @@ fn filters_by_unit_size_comparison() {
"ls | where size > 1kb | sort-by size | get name | first 1 | trim | echo $it" "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] #[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"# 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] #[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"# 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] #[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"# 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] #[test]
@ -55,7 +55,7 @@ fn explicit_block_condition() {
"# "#
)); ));
assert_eq!(actual, "4253"); assert_eq!(actual.out, "4253");
} }
#[test] #[test]
@ -73,7 +73,7 @@ fn binary_operator_comparisons() {
"# "#
)); ));
assert_eq!(actual, "4253"); assert_eq!(actual.out, "4253");
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( 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!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( 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!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( 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!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
@ -133,7 +133,7 @@ fn binary_operator_comparisons() {
"# "#
)); ));
assert_eq!(actual, "42"); assert_eq!(actual.out, "42");
} }
#[test] #[test]
@ -150,7 +150,7 @@ fn contains_operator() {
"# "#
)); ));
assert_eq!(actual, "4"); assert_eq!(actual.out, "4");
let actual = nu!( let actual = nu!(
cwd: "tests/fixtures/formats", pipeline( cwd: "tests/fixtures/formats", pipeline(
@ -164,5 +164,5 @@ fn contains_operator() {
"# "#
)); ));
assert_eq!(actual, "2"); assert_eq!(actual.out, "2");
} }

View File

@ -7,7 +7,7 @@ fn with_env_extends_environment() {
"with-env [FOO BARRRR] {echo $nu.env} | get FOO" "with-env [FOO BARRRR] {echo $nu.env} | get FOO"
); );
assert_eq!(actual, "BARRRR"); assert_eq!(actual.out, "BARRRR");
} }
#[test] #[test]
@ -17,5 +17,5 @@ fn with_env_shorthand() {
"FOO=BARRRR echo $nu.env | get FOO" "FOO=BARRRR echo $nu.env | get FOO"
); );
assert_eq!(actual, "BARRRR"); assert_eq!(actual.out, "BARRRR");
} }

View File

@ -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");
}) })
} }

View File

@ -14,5 +14,5 @@ fn table_to_bson_and_back_into_table() {
"# "#
)); ));
assert_eq!(actual, "whel"); assert_eq!(actual.out, "whel");
} }

View File

@ -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" "open caco3_plastics.csv | to csv | from csv | first 1 | get origin | echo $it"
); );
assert_eq!(actual, "SPAIN"); assert_eq!(actual.out, "SPAIN");
} }
#[test] #[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");
}) })
} }

View File

@ -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!( let actual = nu!(
cwd: TEST_CWD, 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" <aw-confirm@ebay.com>, meaning both the Name and Address values are identical. // The Reply-To field in this email is "aw-confirm@ebay.com" <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!( let actual = nu!(
cwd: TEST_CWD, 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" <aw-confirm@ebay.com>, meaning both the Name and Address values are identical. // The Reply-To field in this email is "aw-confirm@ebay.com" <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");
} }

View File

@ -9,7 +9,7 @@ fn out_html_simple() {
"# "#
)); ));
assert_eq!(actual, "<html><body>3</body></html>"); assert_eq!(actual.out, "<html><body>3</body></html>");
} }
#[test] #[test]
@ -22,7 +22,7 @@ fn out_html_table() {
)); ));
assert_eq!( assert_eq!(
actual, actual.out,
"<html><body><table><tr><th>name</th></tr><tr><td>jason</td></tr></table></body></html>" "<html><body><table><tr><th>name</th></tr><tr><td>jason</td></tr></table></body></html>"
); );
} }

View File

@ -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");
}) })
} }

View File

@ -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] #[test]
@ -40,7 +40,7 @@ fn from_json_text_to_table() {
"open katz.txt | from json | get katz | get rusty_luck | count | echo $it" "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 open sample.txt
| lines | lines
| split-column "," name luck | split-column "," name luck
| pick name | select name
| to json | to json
| from json | from json
| nth 0 | nth 0
@ -98,6 +98,6 @@ fn table_to_json_text() {
"# "#
)); ));
assert_eq!(actual, "JonAndrehudaTZ"); assert_eq!(actual.out, "JonAndrehudaTZ");
}) })
} }

View File

@ -9,7 +9,7 @@ fn out_md_simple() {
"# "#
)); ));
assert_eq!(actual, "3"); assert_eq!(actual.out, "3");
} }
#[test] #[test]
@ -21,5 +21,5 @@ fn out_md_table() {
"# "#
)); ));
assert_eq!(actual, "|name||-||jason|"); assert_eq!(actual.out, "|name||-||jason|");
} }

View File

@ -13,5 +13,5 @@ fn from_ods_file_to_table() {
"# "#
)); ));
assert_eq!(actual, "Gill"); assert_eq!(actual.out, "Gill");
} }

View File

@ -15,5 +15,5 @@ fn table_to_sqlite_and_back_into_table() {
"# "#
)); ));
assert_eq!(actual, "hello"); assert_eq!(actual.out, "hello");
} }

View File

@ -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!(aligned_columns.out, separator_based.out);
assert_eq!(separator_based, "docker-registry"); assert_eq!(separator_based.out, "docker-registry");
}) })
} }

View File

@ -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");
} }

View File

@ -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" "open caco3_plastics.tsv | to tsv | from tsv | first 1 | get origin | echo $it"
); );
assert_eq!(actual, "SPAIN"); assert_eq!(actual.out, "SPAIN");
} }
#[test] #[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" 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] #[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");
}) })
} }

View File

@ -13,5 +13,5 @@ fn can_encode_and_decode_urlencoding() {
"# "#
)); ));
assert_eq!(actual, "comté"); assert_eq!(actual.out, "comté");
} }

View File

@ -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");
}) })
} }

View File

@ -13,5 +13,5 @@ fn from_excel_file_to_table() {
"# "#
)); ));
assert_eq!(actual, "Gill"); assert_eq!(actual.out, "Gill");
} }

View File

@ -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");
} }

View File

@ -47,8 +47,9 @@ macro_rules! nu {
let mut process = match Command::new($crate::fs::executable_path()) let mut process = match Command::new($crate::fs::executable_path())
.env("PATH", paths_joined) .env("PATH", paths_joined)
.stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stdin(Stdio::piped())
.stderr(Stdio::piped())
.spawn() .spawn()
{ {
Ok(child) => child, Ok(child) => child,
@ -62,89 +63,31 @@ macro_rules! nu {
let output = process let output = process
.wait_with_output() .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 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 { pub fn read_std(std: &[u8]) -> String {
let out = String::from_utf8_lossy(std); let out = String::from_utf8_lossy(std);
let out = out.lines().skip(1).collect::<Vec<_>>().join("\n"); let out = out.lines().skip(1).collect::<Vec<_>>().join("\n");
let out = out.replace("\r\n", ""); let out = out.replace("\r\n", "");
out.replace("\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()
}};
}

View File

@ -29,7 +29,7 @@ Pass the output of the `open` command to `from vcf` to get a correctly formatted
``` ```
```shell ```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 # │ value
─────┼────────────────────── ─────┼──────────────────────

View File

@ -18,13 +18,13 @@ Syntax: `save (path) {flags}`
You can save the name of files in a directory like this: You can save the name of files in a directory like this:
```shell ```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: Or you can format it in supported formats using one of the `to` commands:
```shell ```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. `filename.csv` and `filenames` are both `csv` formatted files. Nu auto-converts the format if a supported file extension is given.

View File

@ -1,4 +1,4 @@
# pick # select
This command displays only the column names passed on to it. 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 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 4 │ youshouldeatmorecereal.txt │ File │ │ 768 B │ a month ago │ a month ago │ a month ago
━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━┷━━━━━━━━━━┷━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━ ━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━┷━━━━━━━━━━┷━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━
> ls | pick name > ls | select name
━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ 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: The order in which you put the column names matters:
```shell ```shell
> ls | pick type name size > ls | select type name size
━━━┯━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━ ━━━┯━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━
# │ 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 3 │ File │ abaracadabra.txt │ 401 B
4 │ File │ youshouldeatmorecereal.txt │ 768 B 4 │ File │ youshouldeatmorecereal.txt │ 768 B
━━━┷━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━ ━━━┷━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━
> ls | pick size type name > ls | select size type name
━━━┯━━━━━━━━┯━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━┯━━━━━━━━┯━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ size │ type │ name # │ size │ type │ name
───┼────────┼──────┼──────────────────────────── ───┼────────┼──────┼────────────────────────────

View File

@ -33,7 +33,7 @@ Syntax: `wrap <column>`
`wrap` will encapsulate rows as embedded tables : `wrap` will encapsulate rows as embedded tables :
```shell ```shell
/home/chris> ls | pick name type size /home/chris> ls | select name type size
───┬──────────────┬──────┬───────── ───┬──────────────┬──────┬─────────
# │ name │ type │ size # │ name │ type │ size
───┼──────────────┼──────┼───────── ───┼──────────────┼──────┼─────────
@ -41,7 +41,7 @@ Syntax: `wrap <column>`
1 │ iso.csv │ File │ 20.8 KB 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 # │ details
───┼──────────────── ───┼────────────────

View File

@ -1,15 +1,17 @@
use nu_test_support::fs::Stub::FileWithContent; use nu_test_support::fs::Stub::FileWithContent;
use nu_test_support::nu;
use nu_test_support::playground::Playground; use nu_test_support::playground::Playground;
use nu_test_support::{nu, nu_error};
#[test] #[test]
fn can_only_apply_one() { fn can_only_apply_one() {
let actual = nu_error!( let actual = nu!(
cwd: "tests/fixtures/formats", cwd: "tests/fixtures/formats",
"open cargo_sample.toml | first 1 | inc package.version --major --minor" "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] #[test]
@ -28,7 +30,7 @@ fn by_one_with_field_passed() {
"open sample.toml | inc package.edition | get package.edition | echo $it" "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" "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" "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" "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" "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" "open sample.toml | get package.version | inc --patch | echo $it"
); );
assert_eq!(actual, "0.1.4"); assert_eq!(actual.out, "0.1.4");
}) })
} }

View File

@ -1,15 +1,15 @@
use nu_test_support::fs::Stub::FileWithContent; use nu_test_support::fs::Stub::FileWithContent;
use nu_test_support::playground::Playground; use nu_test_support::playground::Playground;
use nu_test_support::{nu, nu_error, pipeline}; use nu_test_support::{nu, pipeline};
#[test] #[test]
fn can_only_apply_one() { fn can_only_apply_one() {
let actual = nu_error!( let actual = nu!(
cwd: "tests/fixtures/formats", cwd: "tests/fixtures/formats",
"open caco3_plastics.csv | first 1 | str origin --downcase --upcase" "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] #[test]
@ -29,7 +29,7 @@ fn acts_without_passing_field() {
"open sample.yml | get environment.global.PROJECT_NAME | str --upcase | echo $it" "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" "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" "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" "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" "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] #[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");
}) })
} }

View File

@ -1,13 +1,13 @@
use nu_test_support::{nu, nu_error}; use nu_test_support::nu;
#[test] #[test]
fn shows_error_for_command_not_found() { fn shows_error_for_command_not_found() {
let actual = nu_error!( let actual = nu!(
cwd: ".", cwd: ".",
"ferris_is_not_here.exe" "ferris_is_not_here.exe"
); );
assert!(actual.contains("Command not found")); assert!(actual.err.contains("Command not found"));
} }
#[test] #[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() { fn correctly_escape_external_arguments() {
let actual = nu!(cwd: ".", r#"^echo '$0'"#); let actual = nu!(cwd: ".", r#"^echo '$0'"#);
assert_eq!(actual, "$0"); assert_eq!(actual.out, "$0");
} }
mod it_evaluation { 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 { mod stdin_evaluation {
use super::{nu, nu_error}; use super::nu;
use nu_test_support::pipeline; use nu_test_support::pipeline;
#[test] #[test]
fn does_not_panic_with_no_newline_in_stream() { fn does_not_panic_with_no_newline_in_stream() {
let stderr = nu_error!( let actual = nu!(
cwd: ".", cwd: ".",
pipeline(r#" pipeline(r#"
nonu "where's the nuline?" nonu "where's the nuline?"
@ -150,7 +150,7 @@ mod stdin_evaluation {
"# "#
)); ));
assert_eq!(stderr, ""); assert_eq!(actual.err, "");
} }
#[test] #[test]
@ -164,7 +164,8 @@ mod stdin_evaluation {
| lines | lines
| first 1 | first 1
"# "#
)); ))
.out;
assert_eq!(stdout, "y"); assert_eq!(stdout, "y");
} }
@ -179,7 +180,7 @@ mod external_words {
cococo joturner@foo.bar.baz 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'" nu -c "echo 'foo'"
"#); "#);
assert_eq!(actual, "foo"); assert_eq!(actual.out, "foo");
} }
} }
@ -205,7 +206,7 @@ mod nu_script {
nu script.nu nu script.nu
"#); "#);
assert_eq!(actual, "done"); assert_eq!(actual.out, "done");
} }
#[test] #[test]
@ -214,7 +215,7 @@ mod nu_script {
nu script_multiline.nu nu script_multiline.nu
"#); "#);
assert_eq!(actual, "23"); assert_eq!(actual.out, "23");
} }
} }
@ -231,8 +232,8 @@ mod tilde_expansion {
); );
assert!( assert!(
!actual.contains('~'), !actual.out.contains('~'),
format!("'{}' should not contain ~", actual) format!("'{}' should not contain ~", actual.out)
); );
} }
@ -245,6 +246,6 @@ mod tilde_expansion {
"# "#
); );
assert_eq!(actual, "1~1"); assert_eq!(actual.out, "1~1");
} }
} }

View File

@ -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"# r#"echo "nushelll" | chop"#
); );
assert_eq!(actual, "nushell"); assert_eq!(actual.out, "nushell");
} }
mod parse { mod parse {
use nu_test_support::nu_error; use nu_test_support::nu;
/* /*
The debug command's signature is: The debug command's signature is:
@ -58,49 +58,49 @@ mod parse {
#[test] #[test]
fn errors_if_flag_passed_is_not_exact() { fn errors_if_flag_passed_is_not_exact() {
let actual = nu_error!(cwd: ".", "debug -ra"); let actual = nu!(cwd: ".", "debug -ra");
assert!( assert!(
actual.contains("unexpected flag"), actual.err.contains("unexpected flag"),
format!( format!(
"error message '{}' should contain 'unexpected flag'", "error message '{}' should contain 'unexpected flag'",
actual actual.err
) )
); );
let actual = nu_error!(cwd: ".", "debug --rawx"); let actual = nu!(cwd: ".", "debug --rawx");
assert!( assert!(
actual.contains("unexpected flag"), actual.err.contains("unexpected flag"),
format!( format!(
"error message '{}' should contain 'unexpected flag'", "error message '{}' should contain 'unexpected flag'",
actual actual.err
) )
); );
} }
#[test] #[test]
fn errors_if_flag_is_not_supported() { fn errors_if_flag_is_not_supported() {
let actual = nu_error!(cwd: ".", "debug --ferris"); let actual = nu!(cwd: ".", "debug --ferris");
assert!( assert!(
actual.contains("unexpected flag"), actual.err.contains("unexpected flag"),
format!( format!(
"error message '{}' should contain 'unexpected flag'", "error message '{}' should contain 'unexpected flag'",
actual actual.err
) )
); );
} }
#[test] #[test]
fn errors_if_passed_an_unexpected_argument() { fn errors_if_passed_an_unexpected_argument() {
let actual = nu_error!(cwd: ".", "debug ferris"); let actual = nu!(cwd: ".", "debug ferris");
assert!( assert!(
actual.contains("unexpected argument"), actual.err.contains("unexpected argument"),
format!( format!(
"error message '{}' should contain 'unexpected argument'", "error message '{}' should contain 'unexpected argument'",
actual actual.err
) )
); );
} }
@ -122,8 +122,8 @@ mod tilde_expansion {
); );
assert!( assert!(
!actual.contains('~'), !actual.out.contains('~'),
format!("'{}' should not contain ~", actual) 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] #[test]
@ -157,7 +157,7 @@ mod tilde_expansion {
)); ));
assert_eq!( assert_eq!(
actual, actual.out,
r#"["andres.txt","gedge.txt","jonathan.txt","yehuda.txt"]"# r#"["andres.txt","gedge.txt","jonathan.txt","yehuda.txt"]"#
); );
}) })

View File

@ -6,5 +6,5 @@ use nu_test_support::nu;
fn doesnt_break_on_utf8() { fn doesnt_break_on_utf8() {
let actual = nu!(cwd: ".", "echo ö"); let actual = nu!(cwd: ".", "echo ö");
assert_eq!(actual, "ö", "'{}' should contain ö", actual); assert_eq!(actual.out, "ö", "'{}' should contain ö", actual.out);
} }