-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathx.sh
More file actions
executable file
·97 lines (78 loc) · 1.96 KB
/
x.sh
File metadata and controls
executable file
·97 lines (78 loc) · 1.96 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
if [ -z "$0" ]; then
echo "Usage: x.sh [name args]"
echo " name: will run that specific test file"
echo " args will be passed to the compiler"
echo "Example: ./x.sh t/ex01_19.dot"
exit
fi
cd "$(dirname "$0")"
rm -rf build
mkdir build
# -g to generate debug info
clang++ -Werror -std=c11 `llvm-config --cflags` -g -x c -I src src/*.c `llvm-config --ldflags --libs core analysis native bitwriter --system-libs` -O0 -lm -o ./build/dot
compile_result=$?
if [ $compile_result -ne "0" ]; then
echo "Error during compilation, exiting..."
exit
fi
success_count=0
fail_count=0
millis(){ python -c "import time; print(int(time.time()*1000))"; }
dotest() {
test_file=$1
rest_args=$2
file_name=$(basename ${test_file})
file_name="${file_name%.*}"
# echo "./build/dot $rest_args $test_file"
./build/dot $rest_args $test_file
./$file_name
actual=$?
before_underscore=${file_name%_}
expected=${before_underscore#*_}
re='^[0-9]+$'
if ! [[ $expected =~ $re ]] ; then
expected="0"
fi
rm $file_name
test_file_compact=${test_file}
str_len=${#test_file_compact}
pad="\t\t"
if [ "$str_len" -gt "22" ]
then
pad="\t"
fi
if [ "$actual" = "$expected" ]; then
echo -e "\e[0;32m${test_file_compact} $pad PASSED!"
let "success_count++"
else
echo -e "\e[31m${test_file_compact} $pad FAILED! Got $actual but $expected was expected."
let "fail_count++"
fi
tput init
}
echo
start=$(millis)
#do we need to run a single test?
if [[ $# > 0 ]]; then
test_file=$1
shift
rest_args=$*
dotest $test_file $rest_args
else
shopt -s globstar
for f in ./testsuite/**/*.dot ; do
dotest $f
done
fi
end=$(millis)
runtime=$(((end-start)))
echo
echo "Total time: ${runtime}ms"
echo -e "$success_count test(s) passed, $fail_count test(s) failed"
echo
if [ "$fail_count" -eq "0" ]; then
exit 0
else
exit 1
fi