-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-runner
executable file
·77 lines (65 loc) · 1.48 KB
/
test-runner
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
#!/usr/bin/env bash
colored_text() {
printf "\e[38;5;%sm%s\e[0m" $1 "$2"
}
_red() { colored_text 160 "$@"; }
red() { _red "$@"; printf '\n'; }
_green() { colored_text 46 "$@"; }
green() { _green "$@"; printf '\n'; }
_yellow() { colored_text 226 "$@"; }
yellow() { _yellow "$@"; printf '\n'; }
if ! which inotifywait &> /dev/null; then
echo "please install inotify-tools"
exit 1
fi
YEAR=$1
DAY=$2
PART=${3:-1}
if [[ $DAY -lt 10 ]]; then
DIR=day0$1
else
DIR=day$1
fi
cleanup() {
pkill -TERM -P $PID &> /dev/null
kill -SIGTERM $PID &> /dev/null
}
cd ~/aoc/$YEAR/$DIR
function validator() {
local SOLUTION="$(cat $1)"
local BUFFERED=
local LEN=0
local line
while IFS= read -r line; do
[[ $LEN -gt 0 ]] && printf "%s\n" "$BUFFERED"
((LEN++))
BUFFERED="$line"
done
if [[ $LEN -eq 1 ]] && [[ $BUFFERED =~ ^-?[0-9]*$ ]]; then
if [[ "$BUFFERED" == "$SOLUTION" ]]; then
green "$BUFFERED"
echo
exec spinner "" ./p${PART}.sh input.txt
else
red "$BUFFERED"
fi
else
printf "%s\n" "$BUFFERED"
fi
}
trap "cleanup" EXIT
while true; do
sleep 0.1
clear
if [[ -z "$4" ]]; then
./p${PART}.sh sample${PART}.txt \
| validator solution${PART}.txt &
PID=$!
else
spinner "" ./p${PART}.sh input.txt &
PID=$!
fi
inotifywait -qq ../../test-runner p1.sh p2.sh input.txt sample*.txt -e MODIFY -e MOVE_SELF
pkill -TERM -P $PID &> /dev/null
kill -SIGTERM $PID &> /dev/null
done