-
Notifications
You must be signed in to change notification settings - Fork 19
/
testCompiler.sh
80 lines (75 loc) · 1.54 KB
/
testCompiler.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
#!/bin/bash/
function runTest() {
echo "Start running " $1 "tests..."
ext=" "
otherFile=""
cmd=""
totalNum=0
passNum=0
declare -a failedCases
i=1
if [ $1 == "c" ] || [ $1 == "jamc" ]
then
ext=".c"
otherFile=programs/c/empty.js
elif [ $1 == "js" ] || [ $1 == "jamjs" ]
then
ext=".js"
otherFile=programs/js/empty.c
fi
for dir in programs/$1/*
do
allFiles=`find $dir -maxdepth 3 -name "*"$ext | sort`
for file in $allFiles
do
let "totalNum++"
if [ $1 == "c" ] || [ $1 == "jamc" ]
then
cmd="node testCompiler.js $file $otherFile"
else
cmd="node testCompiler.js $otherFile $file"
fi
output=$(eval $cmd)
echo $file
if [[ $output == *"Compilation finished"* ]]; then
if [[ $file == *"invalid"* ]]; then
echo -e "\033[33;31mTest case failed: " $file
failedCases[i]=$file
let "i++"
tput sgr0
else
let "passNum++"
fi
else
if [[ $file == *"invalid"* ]]; then
let "passNum++"
else
echo -e "\033[33;31mTest case failed: " $file
failedCases[i]=$file
let "i++"
tput sgr0
fi
fi
done
done
if [ $passNum -eq $totalNum ]
then
echo -e "\033[33;32mAll" $1 "tests passed!"
tput sgr0
else
echo -e "\033[33;31mSome" $1 "test cases failed. Passed:" $passNum/$totalNum
tput sgr0
echo "Failed test cases:"
for case in ${failedCases[@]}
do
echo $case
done
fi
echo "-----------------------------------------"
echo $1 "tests done"
}
echo "Start running compiler tests"
runTest c
runTest jamc
runTest js
runTest jamjs