logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

badopt_all.sh (723B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. plan="$#"
  5. printf '1..%d\n' "$plan"
  6. err=0
  7. count=0
  8. for cmd; do
  9. : $((count++))
  10. case "$cmd" in
  11. cmd/yes)
  12. # takes no option and loops
  13. printf 'ok %d - %s # skip\n' "$count" "$cmd"
  14. continue
  15. ;;
  16. esac
  17. timeout 3s ./"$cmd" -? >/dev/null 2>&1
  18. status=$?
  19. case "$status" in
  20. 124|126)
  21. printf 'not ok %d - %s\n' "$count" "$cmd"
  22. printf '# exit status: %d\n' "$status"
  23. err=1
  24. ;;
  25. *)
  26. printf 'ok %d - %s\n' "$count" "$cmd"
  27. ;;
  28. esac
  29. done
  30. if test "$plan" -ne "$count"; then
  31. printf >&2 'test-cmd/badopt_all.sh: error: Expected %d tests, ran %d\n' "$plan" "$count"
  32. err=1
  33. fi
  34. exit "$err"