Skip to content

Commit

Permalink
Add script to test puzzles
Browse files Browse the repository at this point in the history
  • Loading branch information
alexg-axis committed Dec 1, 2021
1 parent 595a5a6 commit 0624f27
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ init:
# run today's puzzle
run:
./scripts/run.sh

# test today's puzzle
test:
./scripts/test.sh
35 changes: 35 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -e

export PATH="/usr/local/opt/[email protected]/bin:$PATH"

year="${AOC_YEAR:-$(date +%Y)}"
month="${AOC_MONTH:-$(date +%m)}"
day="${AOC_DAY:-$(date +%-d)}"

if [[ ! "$month" -eq 12 ]]; then
echo "It's not december quite yet. If you wish to run a previous puzzle"
echo "specify AOC_YEAR, AOC_MONTH and AOC_DAY"
exit 1
fi

if [[ ! -d "$year/$day" ]]; then
echo "Cannot find a puzzle in $year/$day. Have you forgot to initialize it?"
exit 1
fi

main_files="$(find "$year/$day" -depth 1 -iname "main*")"
for file in $main_files; do
name="$(basename "$file")"
directory="$(dirname "$file")"
pushd "$directory"
case "${name##*.}" in
"ts")
NO_COLOR=1 deno test --quiet --allow-read
;;
*)
echo "unsupported $file"
esac
popd
done

0 comments on commit 0624f27

Please sign in to comment.