diff --git a/tests/shell/pipeline/commands/external.rs b/tests/shell/pipeline/commands/external.rs index 172ac8cbfc..7268133ab0 100644 --- a/tests/shell/pipeline/commands/external.rs +++ b/tests/shell/pipeline/commands/external.rs @@ -1,4 +1,4 @@ -use nu_test_support::fs::Stub::EmptyFile; +use nu_test_support::fs::Stub::{EmptyFile, FileWithContent}; use nu_test_support::nu; use nu_test_support::playground::Playground; use pretty_assertions::assert_eq; @@ -627,7 +627,6 @@ fn exit_code_stops_execution_closure() { assert!(actual.err.contains("exited with code 1")); } -// TODO: need to add tests under display_error.exit_code = true #[test] fn exit_code_stops_execution_custom_command() { let actual = nu!("def cmd [] { nu -c 'exit 42'; 'ok1' }; cmd; print 'ok2'"); @@ -635,7 +634,6 @@ fn exit_code_stops_execution_custom_command() { assert!(!actual.err.contains("exited with code 42")); } -// TODO: need to add tests under display_error.exit_code = true #[test] fn exit_code_stops_execution_for_loop() { let actual = nu!("for x in [0 1] { nu -c 'exit 42'; print $x }"); @@ -643,6 +641,42 @@ fn exit_code_stops_execution_for_loop() { assert!(!actual.err.contains("exited with code 42")); } +#[test] +fn display_error_with_exit_code_stops() { + Playground::setup("errexit", |dirs, sandbox| { + sandbox.with_files(&[FileWithContent( + "tmp_env.nu", + "$env.config.display_errors.exit_code = true", + )]); + + let actual = nu!( + env_config: "tmp_env.nu", + cwd: dirs.test(), + "def cmd [] { nu -c 'exit 42'; 'ok1' }; cmd; print 'ok2'", + ); + assert!(actual.err.contains("exited with code")); + assert_eq!(actual.out, ""); + }); +} + +#[test] +fn display_error_exit_code_stops_execution_for_loop() { + Playground::setup("errexit", |dirs, sandbox| { + sandbox.with_files(&[FileWithContent( + "tmp_env.nu", + "$env.config.display_errors.exit_code = true", + )]); + + let actual = nu!( + env_config: "tmp_env.nu", + cwd: dirs.test(), + "for x in [0 1] { nu -c 'exit 42'; print $x }", + ); + assert!(actual.err.contains("exited with code")); + assert_eq!(actual.out, ""); + }); +} + #[test] fn arg_dont_run_subcommand_if_surrounded_with_quote() { let actual = nu!("nu --testbin cococo `(echo aa)`");