aoc2020/test.sh

64 lines
1.0 KiB
Bash
Raw Normal View History

2020-12-06 16:34:20 +01:00
#!/usr/bin/bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
run_solution() {
if [ -d "$solution" ]; then
runfile=$solution/run.sh
[ -f "$runfile" ] || { echo "Error: $runfile not found" >&2; exit 1; }
2020-12-06 16:34:20 +01:00
"$runfile" "$input"
else
case "$(basename "$solution")" in
*.hs)
runhaskell -icommon "$solution" < "$input"
;;
*.py)
python "$solution" < "$input"
;;
*)
echo "Error: Unknown solution type: $solution" >&2
2020-12-06 16:34:20 +01:00
exit 1
;;
esac
fi
}
2020-12-11 21:20:23 +01:00
shopt -s dotglob nullglob
2020-12-06 16:34:20 +01:00
for day in day*; do
input=data/$day.input
expected=data/$day.expected
for solution in "$day"/*; do
echo -n "$solution... "
case "${solution##*/}" in
2020-12-13 18:15:17 +01:00
example*|.*)
echo SKIP
continue
esac
2020-12-06 16:34:20 +01:00
solution_output=$(mktemp)
trap "rm -f '$solution_output'" EXIT
2020-12-06 16:34:20 +01:00
run_solution "$solution" > "$solution_output"
if ! diff -u "$expected" "$solution_output"; then
echo FAIL
rv=$?
case "$rv" in
1)
exit 2
;;
*)
exit 1
;;
esac
else
echo ok
fi
rm "$solution_output"
2020-12-06 16:34:20 +01:00
done
done