-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.sh
executable file
·61 lines (51 loc) · 1.58 KB
/
tests.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
#!/usr/bin/env bash
RED='\033[0;31m'
GREEN='\033[0;32m'
BROWN_ORANGE='\033[0;33m'
NC='\033[0m' # No Color
allTestsDir="$(pwd)/src/test/resources/"
courseTests="${allTestsDir}minijava-test-files/"
myTests="${allTestsDir}minijava-dev-tests/"
# Ensure test directories exist
function ensureDirExists {
if [ $# -ne 1 ]; then
echo "Missing directory argument."
exit -2
fi
dir=$1
if [ ! -d ${dir} ]; then
echo "${dir} doesn't exist. Either create it or update the variables in this script."
exit -1
fi
}
ensureDirExists ${allTestsDir}
ensureDirExists ${courseTests}
ensureDirExists ${myTests}
# Ensure jar exists
targetDir="$(pwd)/target"
jar="${targetDir}/minijava-semantical-analyzer-1.0.jar"
if [ ! -f ${jar} ]; then
echo "${jar} is missing. Run \'mvn package\'."
exit -1;
fi
echo -e "${BROWN_ORANGE}${0#$(pwd)/} assumes the convention that java source files which contain an error, \
have \"-error\" in the filename.${NC}"
# Testing
shopt -s nullglob # Causes the array to be empty if none mach.
courseTestFiles=(${allTestsDir}/minijava-*/*.java)
totalNumberOfTests=${#courseTestFiles[@]}
i=1
for file in "${courseTestFiles[@]}"
do
java -jar ${jar} ${file} > /dev/null 2>&1
result=$?
testFilename=${file#${courseTests}}
if [[ ${testFilename} == *"-error"* ]]; then
if [ ${result} -ne 1 ]; then
echo -e "\n${RED}\tSemantical check for ${testFilename} should have failed!${NC}"
fi
fi
printf "\r$i/${totalNumberOfTests}: ${testFilename}"
((i++))
done
printf "${GREEN}\rTests completed.${NC}"