Isolate tests from user config (#12437)

# Description
This is an attempt to isolate the unit tests from whatever might be in
the user's config. If the
user's config is broken in some way or incompatible with this version
(for example, especially if
there are plugins that aren't built for this version), tests can
spuriously fail.

This makes tests more reliably pass the same way they would on CI even
if the user has config, and
should also make them run faster.

I think this is _good enough_, but I still think we should have a
specific config dir env variable for nushell specifically (rather than
having to use `XDG_CONFIG_HOME`, which would mess with other things) and
then we can just have `nu-test-support` set that to a temporary dir
containing the shipped default config files.

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
This commit is contained in:
Devyn Cairns
2024-04-09 15:27:46 -07:00
committed by GitHub
parent d7ba8872bf
commit d735607ac8
13 changed files with 105 additions and 82 deletions

View File

@ -47,7 +47,7 @@ fn ignore_shell_errors_works_for_external_with_semicolon() {
#[test]
fn ignore_program_errors_works_for_external_with_semicolon() {
let actual = nu!(r#"do -p { nu -c 'exit 1' }; "text""#);
let actual = nu!(r#"do -p { nu -n -c 'exit 1' }; "text""#);
assert_eq!(actual.err, "");
assert_eq!(actual.out, "text");

View File

@ -7,7 +7,7 @@ fn basic_exec() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
nu -c 'exec nu --testbin cococo a b c'
nu -n -c 'exec nu --testbin cococo a b c'
"#
));
@ -21,7 +21,7 @@ fn exec_complex_args() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
nu -c 'exec nu --testbin cococo b --bar=2 -sab --arwr - -DTEEE=aasd-290 -90 --'
nu -n -c 'exec nu --testbin cococo b --bar=2 -sab --arwr - -DTEEE=aasd-290 -90 --'
"#
));
@ -35,7 +35,7 @@ fn exec_fail_batched_short_args() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
nu -c 'exec nu --testbin cococo -ab 10'
nu -n -c 'exec nu --testbin cococo -ab 10'
"#
));
@ -49,7 +49,7 @@ fn exec_misc_values() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
nu -c 'let x = "abc"; exec nu --testbin cococo $x ...[ a b c ]'
nu -n -c 'let x = "abc"; exec nu --testbin cococo $x ...[ a b c ]'
"#
));

View File

@ -3,8 +3,8 @@ use nu_test_support::nu;
#[test]
fn interleave_external_commands() {
let result = nu!("interleave \
{ nu -c 'print hello; print world' | lines | each { 'greeter: ' ++ $in } } \
{ nu -c 'print nushell; print rocks' | lines | each { 'evangelist: ' ++ $in } } | \
{ nu -n -c 'print hello; print world' | lines | each { 'greeter: ' ++ $in } } \
{ nu -n -c 'print nushell; print rocks' | lines | each { 'evangelist: ' ++ $in } } | \
each { print }; null");
assert!(result.out.contains("greeter: hello"), "{}", result.out);
assert!(result.out.contains("greeter: world"), "{}", result.out);

View File

@ -18,7 +18,7 @@ fn early_return_if_false() {
fn return_works_in_script_without_def_main() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
"nu early_return.nu"
"nu -n early_return.nu"
));
assert!(actual.err.is_empty());
@ -28,7 +28,7 @@ fn return_works_in_script_without_def_main() {
fn return_works_in_script_with_def_main() {
let actual = nu!(
cwd: "tests/fixtures/formats",
pipeline("nu early_return_outside_main.nu")
pipeline("nu -n early_return_outside_main.nu")
);
assert!(actual.err.is_empty());
}

View File

@ -93,7 +93,7 @@ fn save_stderr_and_stdout_to_afame_file() {
r#"
$env.FOO = "bar";
$env.BAZ = "ZZZ";
do -c {nu -c 'nu --testbin echo_env FOO; nu --testbin echo_env_stderr BAZ'} | save -r save_test_5/new-file.txt --stderr save_test_5/new-file.txt
do -c {nu -n -c 'nu --testbin echo_env FOO; nu --testbin echo_env_stderr BAZ'} | save -r save_test_5/new-file.txt --stderr save_test_5/new-file.txt
"#,
);
assert!(actual
@ -115,7 +115,7 @@ fn save_stderr_and_stdout_to_diff_file() {
r#"
$env.FOO = "bar";
$env.BAZ = "ZZZ";
do -c {nu -c 'nu --testbin echo_env FOO; nu --testbin echo_env_stderr BAZ'} | save -r save_test_6/log.txt --stderr save_test_6/err.txt
do -c {nu -n -c 'nu --testbin echo_env FOO; nu --testbin echo_env_stderr BAZ'} | save -r save_test_6/log.txt --stderr save_test_6/err.txt
"#,
);
@ -208,7 +208,7 @@ fn save_append_works_on_stderr() {
r#"
$env.FOO = " New";
$env.BAZ = " New Err";
do -i {nu -c 'nu --testbin echo_env FOO; nu --testbin echo_env_stderr BAZ'} | save -a -r save_test_11/log.txt --stderr save_test_11/err.txt"#,
do -i {nu -n -c 'nu --testbin echo_env FOO; nu --testbin echo_env_stderr BAZ'} | save -a -r save_test_11/log.txt --stderr save_test_11/err.txt"#,
);
let actual = file_contents(expected_file);
@ -229,7 +229,7 @@ fn save_not_overrides_err_by_default() {
r#"
$env.FOO = " New";
$env.BAZ = " New Err";
do -i {nu -c 'nu --testbin echo_env FOO; nu --testbin echo_env_stderr BAZ'} | save -r save_test_12/log.txt --stderr save_test_12/err.txt"#,
do -i {nu -n -c 'nu --testbin echo_env FOO; nu --testbin echo_env_stderr BAZ'} | save -r save_test_12/log.txt --stderr save_test_12/err.txt"#,
);
assert!(actual.err.contains("Destination file already exists"));
@ -252,7 +252,7 @@ fn save_override_works_stderr() {
r#"
$env.FOO = "New";
$env.BAZ = "New Err";
do -i {nu -c 'nu --testbin echo_env FOO; nu --testbin echo_env_stderr BAZ'} | save -f -r save_test_13/log.txt --stderr save_test_13/err.txt"#,
do -i {nu -n -c 'nu --testbin echo_env FOO; nu --testbin echo_env_stderr BAZ'} | save -f -r save_test_13/log.txt --stderr save_test_13/err.txt"#,
);
let actual = file_contents(expected_file);