From 6068512549aef5a9e16e72e1db9333472f8b6de1 Mon Sep 17 00:00:00 2001 From: Jelle Helsen Date: Sun, 13 Aug 2023 21:27:46 +0200 Subject: [PATCH] added some tests to improve coverage --- tests/xargs_tests.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/xargs_tests.rs b/tests/xargs_tests.rs index 90374f03..45059ea6 100644 --- a/tests/xargs_tests.rs +++ b/tests/xargs_tests.rs @@ -324,3 +324,63 @@ fn xargs_exec_not_found() { .stderr(predicate::str::contains("Error:")) .stdout(predicate::str::is_empty()); } + +#[test] +fn xargs_exec_verbose() { + Command::cargo_bin("xargs") + .expect("found binary") + .args([ + "-n2", + "--verbose", + &path_to_testing_commandline(), + "-", + "--print_stdin", + "--no_print_cwd", + ]) + .write_stdin("a b c\nd") + .assert() + .success() + .stderr(predicate::str::contains("testing-commandline")) + .stdout(predicate::str::diff( + "stdin=\nargs=\n--print_stdin\n--no_print_cwd\na\nb\n\ + stdin=\nargs=\n--print_stdin\n--no_print_cwd\nc\nd\n", + )); +} + +#[test] +fn xargs_unterminated_quote() { + Command::cargo_bin("xargs") + .expect("found binary") + .args([ + "-n2", + &path_to_testing_commandline(), + "-", + "--print_stdin", + "--no_print_cwd", + ]) + .write_stdin("a \"b c\nd") + .assert() + .failure() + .code(1) + .stderr(predicate::str::contains("Error: Unterminated quote:")) + .stdout(predicate::str::is_empty()); +} + +#[test] +fn xargs_zero_lines() { + Command::cargo_bin("xargs") + .expect("found binary") + .args([ + "-L0", + &path_to_testing_commandline(), + "-", + "--print_stdin", + "--no_print_cwd", + ]) + .write_stdin("a \"b c\nd") + .assert() + .failure() + .code(1) + .stderr(predicate::str::contains("Value must be > 0, not: 0")) + .stdout(predicate::str::is_empty()); +}