advent-of-code/test.sh
Xiretza 5b1515f6ee test.sh: write errors to stdout
stdout is swallowed by the result verification
2021-11-30 17:06:48 +01:00

52 lines
920 B
Bash
Executable file

#!/usr/bin/bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/2020"
run_solution() {
if [ -d "$solution" ]; then
runfile=$solution/run.sh
[ -f "$runfile" ] || { echo "Error: $runfile not found" >&2; exit 1; }
"$runfile" "$input"
else
case "$(basename "$solution")" in
*.hs)
runhaskell -icommon "$solution" < "$input"
;;
*.py)
python "$solution" < "$input"
;;
*)
echo "Error: Unknown solution type: $solution" >&2
exit 1
;;
esac
fi
}
for day in day*; do
input=data/$day.input
expected=data/$day.expected
for solution in "$day"/*; do
echo -n "$solution... "
solution_output=$(mktemp)
trap "rm $solution_output" EXIT
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
done
done