-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestday
executable file
·78 lines (74 loc) · 1.91 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
72
73
74
75
76
77
78
#!/bin/zsh
# Copyright 2024 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. Delegates to ./run to run the day's program
# which defaults to dayXX.ps unless EXTENSION=.yz is set to choose a different
# language.
indent() {
pr -to $1
}
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))
program="$day/${day:t}${EXTENSION-.ps}"
if [[ ! -f $program ]]; then
altprogram="$day/${(C)program:t}"
echo $altprogram
if [[ -f $altprogram ]]; then
program="$altprogram"
fi
fi
echo "# Subtest: $day"
indent+=4
for input in $day/input.*.txt ; do
filecount+=1
desc="$filecount - $input"
expected="${input:r}.expected"
# Handle multi-line problem output, e.g. ASCII rasters
if grep --quiet '\\n' $expected ; then
tmpexpected=$(mktemp -t "$day_${expected:t}")
sed -e $'s/\\\\n/\\\n/g' $expected >| $tmpexpected
expected="$tmpexpected"
fi
out=$($BASEDIR/run $program $input | diff -B - $expected)
if [[ $? -eq 0 && -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