2023-08-30 16:16:19 +00:00
|
|
|
set -e
|
|
|
|
|
2023-09-01 16:28:22 +00:00
|
|
|
# cd into script's directory
|
|
|
|
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null
|
|
|
|
root=$(pwd)
|
|
|
|
|
2023-09-04 17:53:33 +00:00
|
|
|
export UTILS="$root"/utils
|
|
|
|
|
2023-09-01 14:18:23 +00:00
|
|
|
REGEXS=()
|
|
|
|
|
2023-08-30 18:08:40 +00:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
2023-09-01 14:18:23 +00:00
|
|
|
-h|--help)
|
|
|
|
cat <<EOF
|
|
|
|
USAGE: [flags] [test regexs...]
|
|
|
|
FLAGS
|
2023-09-01 15:19:48 +00:00
|
|
|
--keep-tmp
|
2023-09-01 14:18:23 +00:00
|
|
|
--verbose (-v)
|
|
|
|
--help (-h)
|
|
|
|
EOF
|
2023-08-30 18:08:40 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
2023-09-01 15:19:48 +00:00
|
|
|
-v|--verbose)
|
|
|
|
VERBOSE=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--keep-tmp)
|
|
|
|
KEEP_TMP=1
|
|
|
|
shift
|
|
|
|
;;
|
2023-09-01 14:18:23 +00:00
|
|
|
*)
|
|
|
|
REGEXS+=("$1")
|
|
|
|
shift
|
|
|
|
;;
|
2023-08-30 18:08:40 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-09-05 21:14:40 +00:00
|
|
|
[ -n "$VERBOSE" ] && set -x
|
2023-08-30 16:16:19 +00:00
|
|
|
|
2023-09-05 21:14:40 +00:00
|
|
|
ROOT_TMPDIR="$(mktemp --tmpdir -d isle-tests.XXXXXX)"
|
|
|
|
if [ -z "$KEEP_TMP" ]; then trap 'rm -rf $ROOT_TMPDIR' EXIT; fi
|
|
|
|
|
|
|
|
TMPDIR="$ROOT_TMPDIR"
|
|
|
|
|
|
|
|
export ROOT_TMPDIR TMPDIR
|
|
|
|
echo "tmp dir is $ROOT_TMPDIR"
|
2023-08-30 16:16:19 +00:00
|
|
|
|
2023-09-04 17:53:33 +00:00
|
|
|
# Blackhole these directories so that tests don't accidentally use the host's
|
|
|
|
# real ones.
|
|
|
|
export XDG_RUNTIME_DIR=/dev/null
|
2024-06-17 12:13:53 +00:00
|
|
|
export XDG_STATE_HOME=/dev/null
|
2023-09-04 17:53:33 +00:00
|
|
|
|
2023-08-31 20:07:36 +00:00
|
|
|
test_files=$(
|
2023-09-01 16:28:22 +00:00
|
|
|
find ./cases -type f -name '*.sh' \
|
|
|
|
| sed "s|^\./cases/||" \
|
2023-08-31 20:07:36 +00:00
|
|
|
| grep -v entrypoint.sh \
|
2023-09-04 19:38:28 +00:00
|
|
|
| sort
|
2023-08-31 20:07:36 +00:00
|
|
|
)
|
2023-08-30 16:16:19 +00:00
|
|
|
|
2023-09-01 14:18:23 +00:00
|
|
|
for r in "${REGEXS[@]}"; do
|
2023-09-01 16:28:22 +00:00
|
|
|
test_files="$(echo "$test_files" | grep "$r")"
|
2023-09-01 14:18:23 +00:00
|
|
|
done
|
|
|
|
|
2023-08-31 20:07:36 +00:00
|
|
|
echo -e "number of tests: $(echo "$test_files" | wc -l)\n"
|
|
|
|
for file in $test_files; do
|
2023-09-04 18:56:48 +00:00
|
|
|
echo "Running test case: $file"
|
2023-08-30 18:08:40 +00:00
|
|
|
|
2023-09-04 19:38:28 +00:00
|
|
|
if [ -z "$VERBOSE" ]; then
|
|
|
|
output="$TMPDIR/$file.log"
|
|
|
|
mkdir -p "$(dirname "$output")"
|
2024-06-11 13:36:48 +00:00
|
|
|
exec 3>"$output"
|
2023-09-04 19:38:28 +00:00
|
|
|
else
|
2024-06-11 13:36:48 +00:00
|
|
|
exec 3>&1
|
2023-09-04 19:38:28 +00:00
|
|
|
fi
|
2023-08-30 18:08:40 +00:00
|
|
|
|
2023-09-01 14:18:23 +00:00
|
|
|
(
|
2023-09-04 17:53:33 +00:00
|
|
|
export TEST_CASE_FILE="$file"
|
2023-08-31 20:07:36 +00:00
|
|
|
|
2024-06-11 13:36:48 +00:00
|
|
|
if ! $SHELL -e -x "$root/cases/$file" >&3 2>&1; then
|
2023-09-01 14:18:23 +00:00
|
|
|
echo "$file FAILED"
|
|
|
|
if [ -z "$VERBOSE" ]; then
|
|
|
|
echo "output of test is as follows"
|
|
|
|
echo "------------------------------"
|
|
|
|
cat "$output"
|
|
|
|
echo "------------------------------"
|
|
|
|
fi
|
|
|
|
exit 1
|
2023-08-31 19:46:56 +00:00
|
|
|
fi
|
2023-09-04 18:56:48 +00:00
|
|
|
) || TESTS_FAILED=1
|
|
|
|
|
|
|
|
if [ -n "$TESTS_FAILED" ]; then break; fi
|
2023-08-30 16:16:19 +00:00
|
|
|
done
|
|
|
|
|
2023-09-04 18:56:48 +00:00
|
|
|
|
|
|
|
# Clean up any shared running clusters. Each cleanup script is responsible for
|
|
|
|
# figuring out if its shared cluster was actually instantiated during any tests.
|
|
|
|
|
2023-09-05 21:14:40 +00:00
|
|
|
if [ -e "$ROOT_TMPDIR/cleanup-pids" ]; then
|
|
|
|
echo "Cleaning up running pids"
|
|
|
|
tac "$ROOT_TMPDIR/cleanup-pids" | while read -r line; do
|
|
|
|
pid="$(echo "$line" | cut -d' ' -f1)"
|
|
|
|
descr="$(echo "$line" | cut -d' ' -f2-)"
|
|
|
|
echo "Killing $descr ($pid)"
|
|
|
|
kill "$pid"
|
|
|
|
done
|
|
|
|
|
|
|
|
# This is easier than checking if the pids are still running, and for some
|
|
|
|
# reason it doesn't occur until after the pids have died anyway
|
|
|
|
echo "Waiting for appimage mounts to unmount"
|
|
|
|
while [ "$(find "$ROOT_TMPDIR" -type d -name '*.mount_isle*' | wc -l)" -ge "1" ]; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
fi
|
2023-09-04 18:56:48 +00:00
|
|
|
|
|
|
|
if [ -z "$TESTS_FAILED" ]; then echo -e '\nall tests succeeded!'; fi
|