-
-
Save addisonj/54f4fef040aa58053ce3afc2bbc30f10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Failure mode test suite for bash" | |
echo " running bash $BASH_VERSION" | |
try() { | |
trap 'echo FAILS' EXIT | |
case $1 in | |
simple) | |
printf " %-34s" "simple failed command" | |
/bin/false | |
;; | |
cmdsub) | |
printf " %-34s" "failed command substitution" | |
local x=$( /bin/false ) | |
;; | |
pipe) | |
printf " %-34s" "failed pipe command input" | |
/bin/false |cat | |
;; | |
pipecmdsub) | |
printf " %-34s" "failed pipe command substitution" | |
local x=$( /bin/false |cat ) | |
;; | |
esac | |
echo "[ $? ]" | |
trap '' EXIT | |
} | |
for flags in "" "-e" "-o pipefail" "-eo pipefail"; do | |
echo | |
[[ -z $flags ]] \ | |
&& echo "Running with no error-catching:" \ | |
|| echo "Running with \`set $flags\`:" | |
for failure in simple cmdsub pipe pipecmdsub; do | |
( | |
[[ -n $flags ]] && eval "set $flags" | |
try $failure | |
) | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment