2022-06-30 03:01:34 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn capture_errors_works() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
2022-09-30 14:14:02 +02:00
|
|
|
do -c {$env.use}
|
2022-06-30 03:01:34 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-11-24 04:58:15 +01:00
|
|
|
eprintln!("actual.err: {:?}", actual.err);
|
|
|
|
|
2022-09-30 14:14:02 +02:00
|
|
|
assert!(actual.err.contains("column_not_found"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn capture_errors_works_for_external() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
do -c {nu --testbin fail}
|
|
|
|
"#
|
|
|
|
));
|
2022-11-22 22:58:36 +01:00
|
|
|
assert!(actual.err.contains("External command failed"));
|
2022-09-30 14:14:02 +02:00
|
|
|
assert_eq!(actual.out, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn capture_errors_works_for_external_with_pipeline() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
do -c {nu --testbin fail} | echo `text`
|
|
|
|
"#
|
|
|
|
));
|
2022-11-22 22:58:36 +01:00
|
|
|
assert!(actual.err.contains("External command failed"));
|
2022-09-30 14:14:02 +02:00
|
|
|
assert_eq!(actual.out, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn capture_errors_works_for_external_with_semicolon() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
do -c {nu --testbin fail}; echo `text`
|
|
|
|
"#
|
|
|
|
));
|
2022-11-22 22:58:36 +01:00
|
|
|
assert!(actual.err.contains("External command failed"));
|
2022-09-30 14:14:02 +02:00
|
|
|
assert_eq!(actual.out, "");
|
2022-06-30 03:01:34 +02:00
|
|
|
}
|
2022-09-30 14:13:46 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn do_with_semicolon_break_on_failed_external() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
do { nu --not_exist_flag }; `text`
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "");
|
|
|
|
}
|
2022-10-12 15:41:20 +02:00
|
|
|
|
2022-11-22 22:58:36 +01:00
|
|
|
#[test]
|
|
|
|
fn ignore_shell_errors_works_for_external_with_semicolon() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
2022-11-24 04:58:15 +01:00
|
|
|
do -s { open asdfasdf.txt }; "text"
|
2022-11-22 22:58:36 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.err, "");
|
|
|
|
assert_eq!(actual.out, "text");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ignore_program_errors_works_for_external_with_semicolon() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
2023-02-16 03:30:56 +01:00
|
|
|
do -p { nu -c 'exit 1' }; "text"
|
2022-11-22 22:58:36 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.err, "");
|
|
|
|
assert_eq!(actual.out, "text");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ignore_error_should_work_for_external_command() {
|
|
|
|
let actual = nu!(cwd: ".", pipeline(
|
|
|
|
r#"do -i { nu --testbin fail asdf }; echo post"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.err, "");
|
|
|
|
assert_eq!(actual.out, "post");
|
|
|
|
}
|
|
|
|
|
2022-10-12 15:41:20 +02:00
|
|
|
#[test]
|
|
|
|
#[cfg(not(windows))]
|
2023-01-25 06:24:38 +01:00
|
|
|
fn capture_error_with_too_much_stderr_not_hang_nushell() {
|
2022-10-12 15:41:20 +02:00
|
|
|
use nu_test_support::fs::Stub::FileWithContent;
|
|
|
|
use nu_test_support::pipeline;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
Playground::setup("external with many stderr message", |dirs, sandbox| {
|
|
|
|
let bytes: usize = 81920;
|
|
|
|
let mut large_file_body = String::with_capacity(bytes);
|
|
|
|
for _ in 0..bytes {
|
2022-10-18 20:13:36 +02:00
|
|
|
large_file_body.push('a');
|
2022-10-12 15:41:20 +02:00
|
|
|
}
|
|
|
|
sandbox.with_files(vec![FileWithContent("a_large_file.txt", &large_file_body)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
2023-01-25 06:24:38 +01:00
|
|
|
do -c {sh -c "cat a_large_file.txt 1>&2"} | complete | get stderr
|
|
|
|
"#,
|
2022-10-12 15:41:20 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, large_file_body);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-15 21:29:29 +02:00
|
|
|
#[test]
|
|
|
|
#[cfg(not(windows))]
|
2023-01-25 06:24:38 +01:00
|
|
|
fn capture_error_with_too_much_stdout_not_hang_nushell() {
|
2022-10-15 21:29:29 +02:00
|
|
|
use nu_test_support::fs::Stub::FileWithContent;
|
|
|
|
use nu_test_support::pipeline;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
Playground::setup("external with many stdout message", |dirs, sandbox| {
|
|
|
|
let bytes: usize = 81920;
|
|
|
|
let mut large_file_body = String::with_capacity(bytes);
|
|
|
|
for _ in 0..bytes {
|
2022-10-18 20:13:36 +02:00
|
|
|
large_file_body.push('a');
|
2022-10-15 21:29:29 +02:00
|
|
|
}
|
|
|
|
sandbox.with_files(vec![FileWithContent("a_large_file.txt", &large_file_body)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
2023-01-25 06:24:38 +01:00
|
|
|
do -c {sh -c "cat a_large_file.txt"} | complete | get stdout
|
|
|
|
"#,
|
2022-10-15 21:29:29 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, large_file_body);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-12 15:41:20 +02:00
|
|
|
#[test]
|
|
|
|
#[cfg(not(windows))]
|
2023-01-25 06:24:38 +01:00
|
|
|
fn capture_error_with_both_stdout_stderr_messages_not_hang_nushell() {
|
2022-10-12 15:41:20 +02:00
|
|
|
use nu_test_support::fs::Stub::FileWithContent;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
Playground::setup(
|
|
|
|
"external with many stdout and stderr messages",
|
|
|
|
|dirs, sandbox| {
|
|
|
|
let script_body = r#"
|
|
|
|
x=$(printf '=%.0s' {1..40960})
|
|
|
|
echo $x
|
|
|
|
echo $x 1>&2
|
|
|
|
"#;
|
|
|
|
let mut expect_body = String::new();
|
|
|
|
for _ in 0..40960 {
|
2022-10-18 20:13:36 +02:00
|
|
|
expect_body.push('=');
|
2022-10-12 15:41:20 +02:00
|
|
|
}
|
|
|
|
|
2022-10-18 20:13:36 +02:00
|
|
|
sandbox.with_files(vec![FileWithContent("test.sh", script_body)]);
|
2022-10-12 15:41:20 +02:00
|
|
|
|
|
|
|
// check for stdout
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
2023-01-25 06:24:38 +01:00
|
|
|
do -c {bash test.sh} | complete | get stdout | str trim
|
|
|
|
"#,
|
2022-10-12 15:41:20 +02:00
|
|
|
));
|
|
|
|
assert_eq!(actual.out, expect_body);
|
|
|
|
// check for stderr
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
2023-01-25 06:24:38 +01:00
|
|
|
do -c {bash test.sh} | complete | get stderr | str trim
|
|
|
|
"#,
|
2022-10-12 15:41:20 +02:00
|
|
|
));
|
|
|
|
assert_eq!(actual.out, expect_body);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2023-02-02 00:04:53 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ignore_error_works_with_list_stream() {
|
|
|
|
let actual = nu!(cwd: ".", pipeline(r#"do -i { ["a", $nothing, "b"] | ansi strip }"#));
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
}
|