Have tests each create a separate tmpdir, and cd into it

This commit is contained in:
Brian Picciano 2023-08-31 22:07:36 +02:00
parent 48675ee095
commit bc798acffa

View File

@ -15,31 +15,41 @@ done
# cd into script's directory
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null
root=$(pwd)
tmp="$(mktemp --tmpdir -d isle-tests.XXXXXX)"
trap 'rm -rf $tmp' EXIT
TMPDIR="$(mktemp --tmpdir -d isle-tests.XXXXXX)"
trap 'rm -rf $TMPDIR' EXIT
export TMPDIR="$tmp"
export TMPDIR
echo "tmp dir is $TMPDIR"
echo -e '\nrunning all tests...\n'
test_files=$(
find . -type f -name '*.sh' \
| sed "s|^\./||" \
| grep -v entrypoint.sh \
| sort -n\
)
for file in $(find . -type f -name '*.sh' | grep -v entrypoint.sh | sort -n); do
echo -e "number of tests: $(echo "$test_files" | wc -l)\n"
for file in $test_files; do
echo "$file"
[ -z "$VERBOSE" ] && output="$tmp/$file.log" || output=/dev/stdout
[ -z "$VERBOSE" ] && output="$TMPDIR/$file.log" || output=/dev/stdout
if ! $SHELL -e -x "$file" >"$output" 2>&1; then
tmp="$TMPDIR/$file.tmp"
mkdir -p "$tmp"
if ! (cd "$tmp" && TMPDIR="$tmp" $SHELL -e -x "$root/$file" >"$output" 2>&1); then
echo "$file FAILED"
if [ -z "$VERBOSE" ]; then
echo "output of test is as follows"
echo "------------------------------"
cat "$tmp/$file.log"
cat "$TMPDIR/$file.log"
echo "------------------------------"
fi
exit 1
fi
done
echo -e '\ntests succeeded!'
echo -e '\nall tests succeeded!'