Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement