logo

utils-std

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

selfcheck.sh (1018B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. set -o pipefail
  5. WD="$(realpath "$(dirname "$0")")"
  6. tmpdir=
  7. err=0
  8. run_test() {
  9. env MALLOC_CHECK_=3 POSIX_ME_HARDER=1 POSIXLY_CORRECT=1 LC_ALL=C.UTF-8 "$1" 2>&1
  10. return $?
  11. }
  12. cd "$WD"
  13. rm "${WD}/selfcheck.out"
  14. for runner in test-cmd/*.sh
  15. do
  16. [ "$runner" = "test-cmd/tap.sh" ] && continue
  17. [ "$runner" = "test-cmd/init_env.sh" ] && continue
  18. echo "${PS4}${runner}"
  19. if command -v mktemp 2>/dev/null >/dev/null
  20. then
  21. cd "$WD"
  22. tmpdir="$(mktemp -d selfcheck.XXXXXX)"
  23. cd "$tmpdir"
  24. fi
  25. run_test "${WD}/${runner}" | tee -a "$WD/selfcheck.out" | grep -v '^ok'
  26. ret="$?"
  27. if [ "$ret" != 0 ]
  28. then
  29. printf '## %s exited with code %s\n' "$runner" "$ret"
  30. err=1
  31. fi
  32. if [ -n "$tmpdir" ]
  33. then
  34. cd "$WD"
  35. if ! rm -d "$tmpdir"
  36. then
  37. printf '## Error: %s left files:\n%s\n' "$runner" "$(ls -R "$tmpdir")"
  38. err=1
  39. fi
  40. fi
  41. done
  42. [ $err = 0 ] && rm "${WD}/selfcheck.out"
  43. exit $err