-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_runner.sh
executable file
·147 lines (120 loc) · 2.8 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
dune build
to_log (){
echo "$1" >> $logname
}
echo_green (){
printf "${GREEN}$1${NC}\n"
}
echo_yellow (){
printf "${YELLOW}$1${NC}\n"
}
echo_red (){
printf "${RED}$1${NC}\n"
}
echo_line (){
echo "-------------------------------------------------------------"
}
get_output (){
output=$(dune exec -- sifun -e "$1")
echo "$output"
}
get_type (){
type=$(dune exec -- sifun -t -e "$1")
echo "$type"
}
get_type_haskell (){
# runghc -XRankNTypes -XScopedTypeVariables $1
out=$(echo ":q" | ghci -XRankNTypes -XScopedTypeVariables -ghci-script $1)
type=${out##*:: }
type=${type%%Loaded*}
echo "$type" | xargs
}
get_reduced (){
reduced=$(dune exec -- sifun -e "$1")
echo "${reduced#*|}" | xargs
}
run_test (){
tempfile=${1/sf.in/tmp}
start=`date +%s.%N`
dune exec -- sifun -t $1 > $tempfile
end=`date +%s.%N`
echo "$end - $start" | bc -l
}
run_test_hs (){
start=`date +%s.%N`
get_type_haskell $1 > /dev/null
end=`date +%s.%N`
echo "$end - $start" | bc -l
}
compare_output (){
tempfile=${1/sf.in/tmp}
expected_file=${1/sf.in/out}
haskell_file=${1/sf/hs}
runtime=$(run_test $1)
if [ -s $haskell_file ]; then
runtime_haskell=$(run_test_hs $haskell_file)
else
runtime_haskell=""
fi
output=$(cat "$tempfile")
expected=$(cat "$expected_file")
echo -ne "${1##*/}\t"
if ! [ -s $1 ]; then
echo_yellow "EMPTY"
elif [[ $expected == ":time" ]]; then
echo_yellow "TIME_ONLY\t$runtime\t$runtime_haskell"
to_log "$runtime,$runtime_haskell"
elif [[ $output == $expected ]]; then
echo_green "OK\t\t$runtime\t$runtime_haskell"
else
echo_red "ERROR\t\t$runtime\t$runtime_haskell"
diff --color $expected_file $tempfile
fi
rm $tempfile
}
compare_all (){
files="$1/*.sf.in"
for i in $files; do
if [ -f "$i" ]; then
compare_output $i
fi
done
}
get_test_dir (){
if [ -z "$1" ]; then
test_dir=$(dirname $0)
else
test_dir=$1
fi
}
run_unit_tests (){
$($(dirname $0)/test_coverage.sh)
}
main (){
get_test_dir $1
echo -e "Running tests in $test_dir\n"
echo -e "Name\t\tResult\t\tSiFun Time\tHaskell Time"
echo_line
compare_all $test_dir
echo_line
}
while getopts "n:t:" options; do
case "${options}" in
n)
NUM=${OPTARG}
;;
t)
TESTDIR=${OPTARG}
;;
esac
done
for i in $(seq $NUM); do
echo -e "Running $i batch..."
logname="log-$(date +"%F-%H-%M-%S").log"
main $TESTDIR
done