logo

utils-std

Collection of commonly available Unix tools
commit: 580f1d1cca9b695017bed7f105f0b9a2fa4d1ef2
parent 0d0a25ab520f2f244a8f2c59d4b0d1b211be39e3
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu,  1 Aug 2024 02:30:14 +0200

selfcheck.sh: Run checks in temporary directories

Diffstat:

Mselfcheck.sh28+++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/selfcheck.sh b/selfcheck.sh @@ -4,16 +4,38 @@ set -o pipefail +WD="$(realpath "$(dirname "$0")")" +tmpdir= +err=0 + +cd "$WD" + printf '%s\n' test-cmd/*.sh | while read runner do [ "$runner" = "test-cmd/tap.sh" ] && continue echo "${PS4}${runner}" - if ! env MALLOC_CHECK_=3 POSIX_ME_HARDER=1 POSIXLY_CORRECT=1 LC_ALL=C.UTF-8 $runner 2>&1 + + if command -v mktemp 2>/dev/null >/dev/null + then + cd "$WD" + tmpdir="$(mktemp -d selfcheck.XXXXXX)" + cd "$tmpdir" + fi + + if ! env MALLOC_CHECK_=3 POSIX_ME_HARDER=1 POSIXLY_CORRECT=1 LC_ALL=C.UTF-8 "${WD}/${runner}" 2>&1 + then + err=1 + fi + + if [ -n "$tmpdir" ] then - exit 1 + cd "$WD" + if ! rm -d "$tmpdir" + then + printf '## Error: %s left files:\n%s\n' "$runner" "$(ls -R "$tmpdir")" + fi fi done | tee selfcheck.out | grep -v '^ok' -err=$? [ $err = 0 ] && rm selfcheck.out exit $err