From c5eb7888ac1172c52d6c96102ffdcdb5172ee559 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sun, 6 Dec 2020 16:34:20 +0100 Subject: [PATCH] add test script --- test.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 test.sh diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..734fbca --- /dev/null +++ b/test.sh @@ -0,0 +1,52 @@ +#!/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"; 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 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