Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo "Failure mode test suite for bash"
  4. echo " running bash $BASH_VERSION"
  5.  
  6. try() {
  7. trap 'echo FAILS' EXIT
  8. case $1 in
  9. simple)
  10. printf " %-34s" "simple failed command"
  11. /bin/false
  12. ;;
  13. cmdsub)
  14. printf " %-34s" "failed command substitution"
  15. local x=$( /bin/false )
  16. ;;
  17.  
  18. pipe)
  19. printf " %-34s" "failed pipe command input"
  20. /bin/false |cat
  21. ;;
  22.  
  23. pipecmdsub)
  24. printf " %-34s" "failed pipe command substitution"
  25. local x=$( /bin/false |cat )
  26. ;;
  27. esac
  28. echo "[ $? ]"
  29. trap '' EXIT
  30. }
  31.  
  32. for flags in "" "-e" "-o pipefail" "-eo pipefail"; do
  33. echo
  34. [[ -z $flags ]] \
  35. && echo "Running with no error-catching:" \
  36. || echo "Running with \`set $flags\`:"
  37. for failure in simple cmdsub pipe pipecmdsub; do
  38. (
  39. [[ -n $flags ]] && eval "set $flags"
  40. try $failure
  41. )
  42. done
  43. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement