nushell/crates/nu-command/tests/commands/do_.rs
WindSoilder 530ff3893e
Eval external command result immediately when using do command with -c (#6645)
* make capture error works better in do command

* remove into string test because we have no way to generate Value::Error for now
2022-09-30 07:14:02 -05:00

62 lines
1.3 KiB
Rust

use nu_test_support::{nu, pipeline};
#[test]
fn capture_errors_works() {
let actual = nu!(
cwd: ".", pipeline(
r#"
do -c {$env.use}
"#
));
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}
"#
));
assert!(actual.err.contains("External command runs to failed"));
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`
"#
));
assert!(actual.err.contains("External command runs to failed"));
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`
"#
));
assert!(actual.err.contains("External command runs to failed"));
assert_eq!(actual.out, "");
}
#[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, "");
}