-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-test
More file actions
executable file
·77 lines (66 loc) · 1.64 KB
/
run-test
File metadata and controls
executable file
·77 lines (66 loc) · 1.64 KB
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
#!/bin/bash
if [ ! -e testcases/config.json ]; then
echo "./testcases/config.json does not exist, please extract testcases to that directory."
exit 1
fi
if [ ! -e "$(which jq)" ]; then
echo 'You need the program "jq" to use this script.'
echo 'Run "sudo apt install jq" to install it.'
exit 1
fi
if [ ! -e "testcases/$1" -o -z "$1" ]; then
if [ ! -z "$1" ]; then
echo "Testcase $1 does not exist."
exit 1
fi
echo "Usage: $0 <testcase name>"
echo "Example: $0 basic_1"
exit 1
fi
list=$(jq ".$1[]" < "testcases/config.json")
if [ -z "$list" ]; then
echo "invalid config"
exit 1
fi
exename="code"
if [ ! -e "$exename" ]; then
echo "Please compile the ticket system and place the executable at \"$exename\""
exit 1
fi
function tmp () {
if [ Darwin = "$(uname -s)" ]; then
mktemp /tmp/ticket.XXXXXXXXXX
else
mktemp -p /tmp ticket.XXXXXXXXXX
fi
}
function tmpdir () {
if [ Darwin = "$(uname -s)" ]; then
mktemp -d /tmp/ticket.XXXXXXXXXX
else
mktemp -d -p /tmp ticket.XXXXXXXXXX
fi
}
testdir="$(tmpdir)"
cp "$exename" "$testdir/"
exe="$testdir/$exename"
cwd="$(pwd)"
basedir="$cwd/testcases/$1"
cd "$testdir"
for i in $list; do
outfile="$(tmp)"
echo "About to run input #$i..."
time "$exe" < "$basedir/$i.in" > "$outfile"
difffile="$(tmp)"
if diff -ZB "$outfile" "$basedir/$i.out" > "$difffile"; then true; else
cat "$difffile" | head -5
backup="test-$1-$i-$(date '+%s').log"
cp "$outfile" "$cwd/$backup"
echo "Test failed on input #$i."
echo "Output saved to $backup"
exit 1
fi
rm "$outfile" "$difffile"
done
rm -r "$testdir"
echo "Testcase complete, answer correct."