Merge branch 'main' into no_export_env

This commit is contained in:
WindSoilder
2022-09-19 14:35:00 +08:00
145 changed files with 2184 additions and 1039 deletions

View File

@ -6,7 +6,7 @@ fn checks_all_rows_are_true() {
cwd: ".", pipeline(
r#"
echo [ "Andrés", "Andrés", "Andrés" ]
| all? $it == "Andrés"
| all $it == "Andrés"
"#
));
@ -18,7 +18,7 @@ fn checks_all_rows_are_false_with_param() {
let actual = nu!(
cwd: ".", pipeline(
r#"
[1, 2, 3, 4] | all? { |a| $a >= 5 }
[1, 2, 3, 4] | all { |a| $a >= 5 }
"#
));
@ -30,7 +30,7 @@ fn checks_all_rows_are_true_with_param() {
let actual = nu!(
cwd: ".", pipeline(
r#"
[1, 2, 3, 4] | all? { |a| $a < 5 }
[1, 2, 3, 4] | all { |a| $a < 5 }
"#
));
@ -49,7 +49,7 @@ fn checks_all_columns_of_a_table_is_true() {
[ Darren, Schroeder, 10/11/2013, 1 ]
[ Yehuda, Katz, 10/11/2013, 1 ]
]
| all? likes > 0
| all likes > 0
"#
));
@ -61,7 +61,7 @@ fn checks_if_all_returns_error_with_invalid_command() {
let actual = nu!(
cwd: ".", pipeline(
r#"
[red orange yellow green blue purple] | all? ($it | st length) > 4
[red orange yellow green blue purple] | all ($it | st length) > 4
"#
));

View File

@ -6,7 +6,7 @@ fn checks_any_row_is_true() {
cwd: ".", pipeline(
r#"
echo [ "Ecuador", "USA", "New Zealand" ]
| any? $it == "New Zealand"
| any $it == "New Zealand"
"#
));
@ -25,7 +25,7 @@ fn checks_any_column_of_a_table_is_true() {
[ Darren, Schroeder, 10/11/2013, 1 ]
[ Yehuda, Katz, 10/11/2013, 1 ]
]
| any? rusty_at == 10/12/2013
| any rusty_at == 10/12/2013
"#
));
@ -37,7 +37,7 @@ fn checks_if_any_returns_error_with_invalid_command() {
let actual = nu!(
cwd: ".", pipeline(
r#"
[red orange yellow green blue purple] | any? ($it | st length) > 4
[red orange yellow green blue purple] | any ($it | st length) > 4
"#
));

View File

@ -36,7 +36,7 @@ fn more_columns_than_table_has() {
[3, white]
[8, yellow]
[4, white]
] | drop column 3 | columns | empty?
] | drop column 3 | columns | is-empty
"#)
);

View File

@ -65,7 +65,7 @@ fn each_implicit_it_in_block() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
echo [[foo bar]; [a b] [c d] [e f]] | each { |it| nu --testbin cococo $it.foo } | str collect
echo [[foo bar]; [a b] [c d] [e f]] | each { |it| nu --testbin cococo $it.foo } | str join
"#
));

View File

@ -11,8 +11,8 @@ fn reports_emptiness() {
[([[check]; [{}] ])]
]
| get are_empty
| all? {
empty? check
| all {
is-empty check
}
"#
));

View File

@ -11,7 +11,7 @@ fn flatten_nested_tables_with_columns() {
[[origin, people]; [Nu, ('nuno' | wrap name)]]
| flatten --all | flatten --all
| get name
| str collect ','
| str join ','
"#
));
@ -27,7 +27,7 @@ fn flatten_nested_tables_that_have_many_columns() {
[[origin, people]; [USA, (echo [[name, meal]; ['Katz', 'nurepa']])]]
| flatten --all | flatten --all
| get meal
| str collect ','
| str join ','
"#
));

View File

@ -26,7 +26,7 @@ fn moves_a_column_before() {
| rename chars
| get chars
| str trim
| str collect
| str join
"#
));
@ -59,9 +59,9 @@ fn moves_columns_before() {
| move column99 column3 --before column2
| rename _ chars_1 chars_2
| select chars_2 chars_1
| upsert new_col {|f| $f | transpose | get column1 | str trim | str collect}
| upsert new_col {|f| $f | transpose | get column1 | str trim | str join}
| get new_col
| str collect
| str join
"#
));
@ -95,9 +95,9 @@ fn moves_a_column_after() {
| move letters and_more --before column2
| rename _ chars_1 chars_2
| select chars_1 chars_2
| upsert new_col {|f| $f | transpose | get column1 | str trim | str collect}
| upsert new_col {|f| $f | transpose | get column1 | str trim | str join}
| get new_col
| str collect
| str join
"#
));
@ -130,7 +130,7 @@ fn moves_columns_after() {
| move letters and_more --after column1
| columns
| select 1 2
| str collect
| str join
"#
));

View File

@ -373,7 +373,7 @@ fn parse_script_success_with_complex_internal_stream() {
#ls **/* | some_filter | grep-nu search
#open file.txt | grep-nu search
] {
if ($entrada | empty?) {
if ($entrada | is-empty) {
if ($in | column? name) {
grep -ihHn $search ($in | get name)
} else {
@ -422,7 +422,7 @@ fn parse_script_failure_with_complex_internal_stream() {
#ls **/* | some_filter | grep-nu search
#open file.txt | grep-nu search
]
if ($entrada | empty?) {
if ($entrada | is-empty) {
if ($in | column? name) {
grep -ihHn $search ($in | get name)
} else {
@ -471,7 +471,7 @@ fn parse_script_success_with_complex_external_stream() {
#ls **/* | some_filter | grep-nu search
#open file.txt | grep-nu search
] {
if ($entrada | empty?) {
if ($entrada | is-empty) {
if ($in | column? name) {
grep -ihHn $search ($in | get name)
} else {
@ -520,7 +520,7 @@ fn parse_module_success_with_complex_external_stream() {
#ls **/* | some_filter | grep-nu search
#open file.txt | grep-nu search
] {
if ($entrada | empty?) {
if ($entrada | is-empty) {
if ($in | column? name) {
grep -ihHn $search ($in | get name)
} else {
@ -569,7 +569,7 @@ fn parse_with_flag_all_success_for_complex_external_stream() {
#ls **/* | some_filter | grep-nu search
#open file.txt | grep-nu search
] {
if ($entrada | empty?) {
if ($entrada | is-empty) {
if ($in | column? name) {
grep -ihHn $search ($in | get name)
} else {
@ -618,7 +618,7 @@ fn parse_with_flag_all_failure_for_complex_external_stream() {
#ls **/* | some_filter | grep-nu search
#open file.txt | grep-nu search
] {
if ($entrada | empty?) {
if ($entrada | is-empty) {
if ($in | column? name) {
grep -ihHn $search ($in | get name)
} else {
@ -667,7 +667,7 @@ fn parse_with_flag_all_failure_for_complex_list_stream() {
#ls **/* | some_filter | grep-nu search
#open file.txt | grep-nu search
] {
if ($entrada | empty?) {
if ($entrada | is-empty) {
if ($in | column? name) {
grep -ihHn $search ($in | get name)
} else {

View File

@ -208,6 +208,22 @@ fn parses_utf16_ini() {
assert_eq!(actual.out, "-236")
}
#[cfg(feature = "database")]
#[test]
fn parses_arrow_ipc() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open-df caco3_plastics.arrow
| into nu
| first 1
| get origin
"#
));
assert_eq!(actual.out, "SPAIN")
}
#[test]
fn errors_if_file_not_found() {
let actual = nu!(

View File

@ -13,7 +13,7 @@ fn regular_columns() {
]
| reject type first_name
| columns
| str collect ", "
| str join ", "
"#
));
@ -56,7 +56,7 @@ fn complex_nested_columns() {
| reject nu."0xATYKARNU" nu.committers
| get nu
| columns
| str collect ", "
| str join ", "
"#,
));
@ -75,7 +75,7 @@ fn ignores_duplicate_columns_rejected() {
]
| reject "first name" "first name"
| columns
| str collect ", "
| str join ", "
"#
));

View File

@ -69,7 +69,7 @@ mod columns {
format!("{} | {}", table(), pipeline(r#"
roll left
| columns
| str collect "-"
| str join "-"
"#)));
assert_eq!(actual.out, "origin-stars-commit_author");
@ -82,7 +82,7 @@ mod columns {
format!("{} | {}", table(), pipeline(r#"
roll right --by 2
| columns
| str collect "-"
| str join "-"
"#)));
assert_eq!(actual.out, "origin-stars-commit_author");
@ -97,7 +97,7 @@ mod columns {
let actual = nu!(
cwd: ".",
format!("{} | roll right --by 3 --cells-only | columns | str collect '-' ", four_bitstring)
format!("{} | roll right --by 3 --cells-only | columns | str join '-' ", four_bitstring)
);
assert_eq!(actual.out, expected_value.1);

View File

@ -25,7 +25,7 @@ fn counter_clockwise() {
]
| where column0 == EXPECTED
| get column1 column2 column3
| str collect "-"
| str join "-"
"#,
));
@ -35,7 +35,7 @@ fn counter_clockwise() {
rotate --ccw
| where column0 == EXPECTED
| get column1 column2 column3
| str collect "-"
| str join "-"
"#)));
assert_eq!(actual.out, expected.out);
@ -66,7 +66,7 @@ fn clockwise() {
]
| where column3 == EXPECTED
| get column0 column1 column2
| str collect "-"
| str join "-"
"#,
));
@ -76,7 +76,7 @@ fn clockwise() {
rotate
| where column3 == EXPECTED
| get column0 column1 column2
| str collect "-"
| str join "-"
"#)));
assert_eq!(actual.out, expected.out);

View File

@ -186,6 +186,20 @@ fn external_arg_with_variable_name() {
})
}
#[test]
fn external_command_escape_args() {
Playground::setup("external failed command with semicolon", |dirs, _| {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
^echo "\"abcd"
"#
));
assert_eq!(actual.out, r#""abcd"#);
})
}
#[cfg(windows)]
#[test]
fn explicit_glob_windows() {
@ -244,72 +258,6 @@ fn failed_command_with_semicolon_will_not_execute_following_cmds_windows() {
})
}
#[cfg(windows)]
#[test]
#[ignore = "fails on local Windows machines"]
// This test case might fail based on the running shell on Windows - CMD vs PowerShell, the reason is
//
// Test command 1 - `dir * `
// Test command 2 - `dir '*'`
// Test command 3 - `dir "*"`
//
// In CMD, command 2 and 3 will give you an error of 'File Not Found'
// In Poweshell, all three commands will do the path expansion with any errors whatsoever
//
// With current Windows CI build(Microsoft Windows 2022 with version 10.0.20348),
// the unit test runs agaisnt PowerShell
fn double_quote_does_not_expand_path_glob_windows() {
Playground::setup("double quote do not run the expansion", |dirs, sandbox| {
sandbox.with_files(vec![
EmptyFile("D&D_volume_1.txt"),
EmptyFile("D&D_volume_2.txt"),
EmptyFile("foo.sh"),
]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
dir "*.txt"
"#
));
assert!(actual.out.contains("D&D_volume_1.txt"));
assert!(actual.out.contains("D&D_volume_2.txt"));
})
}
#[cfg(windows)]
#[test]
#[ignore = "fails on local Windows machines"]
// This test case might fail based on the running shell on Windows - CMD vs PowerShell, the reason is
//
// Test command 1 - `dir * `
// Test command 2 - `dir '*'`
// Test command 3 - `dir "*"`
//
// In CMD, command 2 and 3 will give you an error of 'File Not Found'
// In Poweshell, all three commands will do the path expansion with any errors whatsoever
//
// With current Windows CI build(Microsoft Windows 2022 with version 10.0.20348),
// the unit test runs agaisnt PowerShell
fn single_quote_does_not_expand_path_glob_windows() {
Playground::setup("single quote do not run the expansion", |dirs, sandbox| {
sandbox.with_files(vec![
EmptyFile("D&D_volume_1.txt"),
EmptyFile("D&D_volume_2.txt"),
EmptyFile("foo.sh"),
]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
dir '*.txt'
"#
));
assert!(actual.out.contains("D&D_volume_1.txt"));
assert!(actual.out.contains("D&D_volume_2.txt"));
});
}
#[cfg(windows)]
#[test]
fn can_run_batch_files() {

View File

@ -96,7 +96,7 @@ fn column_names_with_spaces() {
]
| select "last name"
| get "last name"
| str collect " "
| str join " "
"#
));
@ -115,7 +115,7 @@ fn ignores_duplicate_columns_selected() {
]
| select "first name" "last name" "first name"
| columns
| str collect " "
| str join " "
"#
));
@ -159,3 +159,27 @@ fn selects_many_rows() {
assert_eq!(actual.out, "2");
});
}
#[test]
fn select_ignores_errors_succesfully1() {
let actual = nu!(
cwd: ".", pipeline(
r#"
[{a: 1, b: 2} {a: 3, b: 5} {a: 3}] | select -i b
"#
));
assert!(actual.err.is_empty());
}
#[test]
fn select_ignores_errors_succesfully2() {
let actual = nu!(
cwd: ".", pipeline(
r#"
[{a: 1} {a: 2} {a: 3}] | select -i b
"#
));
assert!(actual.err.is_empty());
}

View File

@ -36,7 +36,7 @@ fn condition_is_met() {
| lines
| skip 2
| str trim
| str collect (char nl)
| str join (char nl)
| from csv
| skip until "Chicken Collection" == "Red Chickens"
| skip 1

View File

@ -36,7 +36,7 @@ fn condition_is_met() {
| lines
| skip 2
| str trim
| str collect (char nl)
| str join (char nl)
| from csv
| skip while "Chicken Collection" != "Red Chickens"
| skip 1

View File

@ -143,6 +143,7 @@ fn sources_unicode_file_in_non_utf8_dir() {
// How do I create non-UTF-8 path???
}
#[ignore]
#[test]
fn can_source_dynamic_path() {
Playground::setup("can_source_dynamic_path", |dirs, sandbox| {
@ -269,39 +270,26 @@ fn source_env_dont_cd_overlay() {
}
#[test]
fn source_env_nice_parse_error() {
Playground::setup("source_env_nice_parse_error", |dirs, sandbox| {
fn source_env_is_scoped() {
Playground::setup("source_env_is_scoped", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
r#"
let x
"#,
def foo [] { 'foo' }
alias bar = 'bar'
"#,
)]);
let inp = &[r#"source-env spam.nu"#];
let inp = &[r#"source-env spam.nu"#, r#"foo"#];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
assert!(actual.err.contains("cannot parse this file"));
assert!(actual.err.contains("───"));
})
}
assert!(actual.err.contains("did you mean"));
#[test]
fn source_env_nice_shell_error() {
Playground::setup("source_env_nice_shell_error", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
r#"
let-env FILE_PWD = 'foo'
"#,
)]);
let inp = &[r#"source-env spam.nu"#];
let inp = &[r#"source-env spam.nu"#, r#"bar"#];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
assert!(actual.err.contains("cannot evaluate this file"));
assert!(actual.err.contains("───"));
assert!(actual.err.contains("did you mean"));
})
}

View File

@ -5,7 +5,7 @@ fn test_1() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo 1..5 | into string | str collect
echo 1..5 | into string | str join
"#
)
);
@ -18,7 +18,7 @@ fn test_2() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo [a b c d] | str collect "<sep>"
echo [a b c d] | str join "<sep>"
"#
)
);
@ -31,7 +31,7 @@ fn construct_a_path() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo [sample txt] | str collect "."
echo [sample txt] | str join "."
"#
)
);
@ -44,7 +44,7 @@ fn sum_one_to_four() {
let actual = nu!(
cwd: ".", pipeline(
r#"
1..4 | each { |it| $it } | into string | str collect "+" | math eval
1..4 | each { |it| $it } | into string | str join "+" | math eval
"#
)
);

View File

@ -36,7 +36,7 @@ fn condition_is_met() {
| lines
| skip 2
| str trim
| str collect (char nl)
| str join (char nl)
| from csv
| skip while "Chicken Collection" != "Blue Chickens"
| take until "Chicken Collection" == "Red Chickens"

View File

@ -36,7 +36,7 @@ fn condition_is_met() {
| lines
| skip 2
| str trim
| str collect (char nl)
| str join (char nl)
| from csv
| skip 1
| take while "Chicken Collection" != "Blue Chickens"

View File

@ -1,4 +1,5 @@
use nu_test_support::fs::{AbsolutePath, Stub::FileWithContent};
use nu_test_support::fs::AbsolutePath;
use nu_test_support::fs::Stub::{FileWithContent, FileWithContentToBeTrimmed};
use nu_test_support::nu;
use nu_test_support::pipeline;
use nu_test_support::playground::Playground;
@ -63,3 +64,122 @@ fn use_keeps_doc_comments() {
assert!(actual.out.contains("this is an x parameter"));
})
}
#[test]
fn use_eval_export_env() {
Playground::setup("use_eval_export_env", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
r#"
export-env { let-env FOO = 'foo' }
"#,
)]);
let inp = &[r#"use spam.nu"#, r#"$env.FOO"#];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
assert_eq!(actual.out, "foo");
})
}
#[test]
fn use_eval_export_env_hide() {
Playground::setup("use_eval_export_env", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
r#"
export-env { hide-env FOO }
"#,
)]);
let inp = &[r#"let-env FOO = 'foo'"#, r#"use spam.nu"#, r#"$env.FOO"#];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
assert!(actual.err.contains("did you mean"));
})
}
#[test]
fn use_do_cd() {
Playground::setup("use_do_cd", |dirs, sandbox| {
sandbox
.mkdir("test1/test2")
.with_files(vec![FileWithContentToBeTrimmed(
"test1/test2/spam.nu",
r#"
export-env { cd test1/test2 }
"#,
)]);
let inp = &[r#"use test1/test2/spam.nu"#, r#"$env.PWD | path basename"#];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
assert_eq!(actual.out, "test2");
})
}
#[test]
fn use_do_cd_file_relative() {
Playground::setup("use_do_cd_file_relative", |dirs, sandbox| {
sandbox
.mkdir("test1/test2")
.with_files(vec![FileWithContentToBeTrimmed(
"test1/test2/spam.nu",
r#"
export-env { cd ($env.FILE_PWD | path join '..') }
"#,
)]);
let inp = &[r#"use test1/test2/spam.nu"#, r#"$env.PWD | path basename"#];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
assert_eq!(actual.out, "test1");
})
}
#[test]
fn use_dont_cd_overlay() {
Playground::setup("use_dont_cd_overlay", |dirs, sandbox| {
sandbox
.mkdir("test1/test2")
.with_files(vec![FileWithContentToBeTrimmed(
"test1/test2/spam.nu",
r#"
export-env {
overlay new spam
cd test1/test2
overlay hide spam
}
"#,
)]);
let inp = &[r#"use test1/test2/spam.nu"#, r#"$env.PWD | path basename"#];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
assert_eq!(actual.out, "use_dont_cd_overlay");
})
}
#[test]
fn use_export_env_combined() {
Playground::setup("use_is_scoped", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
r#"
alias bar = foo
export-env { let-env FOO = bar }
def foo [] { 'foo' }
"#,
)]);
let inp = &[r#"use spam.nu"#, r#"$env.FOO"#];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
assert_eq!(actual.out, "foo");
})
}

View File

@ -8,7 +8,7 @@ export def expect [
--to-eq,
right
] {
$left | zip $right | all? {|row|
$left | zip $right | all {|row|
$row.name.0 == $row.name.1 && $row.commits.0 == $row.commits.1
}
}
@ -51,7 +51,7 @@ fn zips_two_lists() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo [0 2 4 6 8] | zip [1 3 5 7 9] | flatten | into string | str collect '-'
echo [0 2 4 6 8] | zip [1 3 5 7 9] | flatten | into string | str join '-'
"#
));