-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_runner.sh
executable file
·82 lines (74 loc) · 1.82 KB
/
test_runner.sh
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
79
80
81
82
#!/bin/bash
# $1: "run" or "test"
# $2: source filename
if [[ ( ! $1 == "run" ) && ( ! $1 == "test" ) ]]; then
echo "1st arg must be 'run' or 'test'"
exit
fi
if [[ $2 == "" ]]; then
echo "2st arg must be source filename"
exit
fi
os=`uname | tr '[:upper:]' '[:lower:]'`
case $os in
'windowsnt') os='win';;
'darwin') os='mac';;
*) os='';;
esac
name="${2%.*}"
runcmd=""
if [[ $2 == *.cpp ]]; then
if [[ $os == 'win' ]]; then
g++ -Wl,--stack,100000000 $2 -o $name -O2 -Wall -Wextra -std=gnu++0x || exit
elif [[ $os == 'mac' ]]; then
g++ -Wl,-stack_size,0x10000000 $2 -o $name -O2 -Wall -Wextra -std=gnu++0x || exit
else
g++ -fstack-limit-symbol=__stack_limit -Wl,--defsym,__stack_limit=0x10000000 -fstack-check $2 -o $name -O2 -Wall -Wextra -std=gnu++0x || exit
fi
runcmd="./$name"
elif [[ $2 == *java ]]; then
# java class name must be the same as the file name
javac $2
runcmd="java $name"
elif [[ $2 == *py ]]; then
runcmd="python $2"
else
echo "unknown source type: $2"
exit
fi
if [ ! -d "input" ]; then
echo "No input folder found"
exit
elif [ ! "$(ls -A "input")" ]; then
echo "Empty input folder"
exit
fi
if [ ! -d "output" ]; then
mkdir output
fi
if [[ ( ! -d "answer" ) && "$1" == "test" ]]; then
mkdir answer
fi
for i in input/*; do
echo -n -e "$i:\t"
if [[ "$1" == "test" ]]; then
# test the src against all cases
$runcmd < $i > ${i//input/answer}
outfile=${i//input/output}
ansfile=${i//input/answer}
diffcmd="diff -q --strip-trailing-cr $outfile $ansfile"
comp=`eval $diffcmd`
if [[ "$comp" == "" ]]; then
echo "OK"
else
diff -y --strip-trailing-cr $outfile $ansfile
echo "INCORRECT"
fi
else
# generate AC outputs for all cases
ansfile=${i//input/output}
ansfile=${ansfile//.in/.ans}
$runcmd < $i > $ansfile
echo "DONE"
fi
done