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