-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.zsh
executable file
·68 lines (59 loc) · 1.39 KB
/
test.zsh
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
#!/bin/zsh
# Usage: ./test.zsh file|directory [-f] [out_extension]
# If -f is provided, break at the first failure
# out_extension is "ans" by default
COL_RESET="\033[0m"
COL_PASS="\033[1;32m"
COL_FAIL="\033[1;31m"
COL_CASE="\033[0;33m"
ext_out=${3:-"ans"}
case_header() {
echo $1 | awk -F'/' "{printf \"Case $COL_CASE\" \$NF \".in$COL_RESET: \"}"
}
test_case() {
_case=$1
_hard_fail=$2
# Print without directory
_diff=$(
./main <$_case.in \
| diff \
--color=always \
- $_case.$ext_out \
| tail -n +2
)
if [ -z "$_diff" ]; then
case_header $_case
echo "${COL_PASS}pass$COL_RESET"
else
echo; case_header $_case
echo "${COL_FAIL}fail$COL_RESET"
echo "$_diff"; echo
if [ $_hard_fail -eq 1 ]; then
exit 1
fi
fi
}
# Compile
g++ -std=c++17 -g main.cpp -o main
# Check if $1 is a directory
maybe_dir=${1:-debug/data}
hard_fail=0
if [ $2 ]; then hard_fail=1; fi
if [ $maybe_dir = "-f" ]; then
maybe_dir="debug/data"
hard_fail=1
fi
if [ -d $maybe_dir ]; then
# Do the thing many times
for case in $(
ls -rt $maybe_dir/* \
| grep -E '.*\.in' \
| sed 's/\.in//' \
| sort -n
); do
test_case $case $hard_fail
done
else
# Do the thing once
test_case $maybe_dir $hard_fail
fi