-
Notifications
You must be signed in to change notification settings - Fork 1
/
testday
executable file
·71 lines (66 loc) · 1.61 KB
/
testday
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/zsh
# Copyright 2022 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
# TAP (testanything.org) runner for Advent of Code days. Runs all days if none
# are provided on the command line. Assumes running
# make output.foo.txt
# from dayXX creates an output file which can be diffed with
# dayXX/input.foo.expected (where "foo" is usually "expected" or "actual").
indent() {
pr -to $1
}
# Exclude an infinite-loop example input
setopt extendedglob
BASEDIR=${0:h}
if [[ $# -eq 0 ]]; then
DAYS=($BASEDIR/day*(n))
else
DAYS=($@)
fi
echo "TAP version 14"
((indent=0))
((daycount=0))
((dayfails=0))
for day in $DAYS ; do
daycount+=1
((filecount=0))
((fails=0))
echo "# Subtest: $day"
indent+=4
for input in $day/input.*.txt~$day/*infinite* ; do
filecount+=1
desc="$filecount - $input"
expected="${input:r}.expected"
output="${input//input./output.}"
(cd $day && make ${output:t})
out=$(diff $output $expected)
if [[ -z "$out" ]]; then
echo "ok $desc" | indent $indent
else
fails+=1
echo "not ok $desc" | indent $indent
echo "---" | indent $(($indent + 2))
echo "diff: |" | indent $(($indent + 2))
echo $out | indent $(($indent + 4))
echo "..." | indent $(($indent + 2))
fi
done
echo "1..$filecount" | indent $indent
indent+=-4
desc="$daycount - $day"
if [[ $fails -gt 0 ]]; then
dayfails+=1
echo "not ok $desc"
else
echo "ok $desc"
fi
done
echo "1..$daycount"
if [[ $dayfails -gt 0 ]]; then
exit 1
fi
exit 0
fi