diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-10-05 22:00:15 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-10-05 22:00:15 -0400 |
commit | 86a478145287afa6352ede556b49b10daf75480e (patch) | |
tree | 56d4cc5b4374bdbc156222861e2ed90d59ed6fcb /tests/tests.sh | |
parent | 877b62e12ca391f377e13e6b5a18d477a581e657 (diff) | |
download | bfs-86a478145287afa6352ede556b49b10daf75480e.tar.xz |
tests: Test -exec with a nonexistent command
Diffstat (limited to 'tests/tests.sh')
-rwxr-xr-x | tests/tests.sh | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/tests.sh b/tests/tests.sh index 8c65c72..64bd04d 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -262,8 +262,10 @@ posix_tests=( test_L_depth test_exec + test_exec_nonexistent test_exec_nopath test_exec_plus + test_exec_plus_nonexistent test_exec_plus_status test_exec_plus_semicolon @@ -401,6 +403,7 @@ bsd_tests=( test_exec_substring + test_execdir_nonexistent test_execdir_pwd test_execdir_slash test_execdir_slash_pwd @@ -559,6 +562,7 @@ gnu_tests=( test_exec_plus_flush_fail test_execdir + test_execdir_nonexistent test_execdir_substring test_execdir_plus_semicolon test_execdir_pwd @@ -822,6 +826,7 @@ bfs_tests=( test_exec_flush_fprint_fail test_execdir_plus + test_execdir_plus_nonexistent test_fprint_duplicate_stdout test_fprint_error_stdout @@ -1770,6 +1775,17 @@ function test_exec() { bfs_diff basic -exec echo {} \; } +function test_exec_nonexistent() { + # Failure to execute the command should lead to an error message and + # non-zero exit status. See https://unix.stackexchange.com/q/704522/56202 + + local stderr=$(invoke_bfs basic -exec "$TESTS/nonexistent" {} \; 2>&1 >/dev/null) + [ -n "$stderr" ] || return 1 + + bfs_diff basic -print -exec "$TESTS/nonexistent" {} \; -print + (($? == EX_BFS)) +} + function test_exec_nopath() { ( unset PATH @@ -1789,6 +1805,14 @@ function test_exec_plus() { bfs_diff basic -exec "$TESTS/sort-args.sh" {} + } +function test_exec_plus_nonexistent() { + local stderr=$(invoke_bfs basic -exec "$TESTS/nonexistent" {} + 2>&1 >/dev/null) + [ -n "$stderr" ] || return 1 + + bfs_diff basic -exec "$TESTS/nonexistent" {} + -print + (($? == EX_BFS)) +} + function test_exec_plus_status() { # -exec ... {} + should always return true, but if the command fails, bfs # should exit with a non-zero status @@ -1845,6 +1869,14 @@ function test_execdir() { bfs_diff basic -execdir echo {} \; } +function test_execdir_nonexistent() { + local stderr=$(invoke_bfs basic -execdir "$TESTS/nonexistent" {} \; 2>&1 >/dev/null) + [ -n "$stderr" ] || return 1 + + bfs_diff basic -print -execdir "$TESTS/nonexistent" {} \; -print + (($? == EX_BFS)) +} + function test_execdir_plus() { local tree=$(invoke_bfs -D tree 2>&1 -quit) @@ -1855,6 +1887,14 @@ function test_execdir_plus() { bfs_diff basic -execdir "$TESTS/sort-args.sh" {} + } +function test_execdir_plus_nonexistent() { + local stderr=$(invoke_bfs basic -execdir "$TESTS/nonexistent" {} + 2>&1 >/dev/null) + [ -n "$stderr" ] || return 1 + + bfs_diff basic -execdir "$TESTS/nonexistent" {} + -print + (($? == EX_BFS)) +} + function test_execdir_substring() { bfs_diff basic -execdir echo '-{}-' \; } |