-
Notifications
You must be signed in to change notification settings - Fork 0
/
runTests.sh
executable file
·112 lines (100 loc) · 2.8 KB
/
runTests.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
#!/bin/bash
ogDir=$(pwd)
lansetDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
testDir="$lansetDir/tests"
interactiveTestDir="$lansetDir/tests/interactive"
outputDir="$lansetDir/out/tests"
jarFile="$lansetDir/lansetc.jar"
expectedOutDir="$lansetDir/tests/results/expectedOut"
tmpAcceptanceFile="/tmp/acceptance.sh"
interactiveInputDir="$lansetDir/tests/interactiveInput"
mkdir -p $outputDir
cd $outputDir
echo "#####Cleaning#####"
rm -f $tmpAcceptanceFile
rm -f *.class
rm -f *.out
rm -f *.err
echo
#Build
#TODO build in order
echo "#####Building#####"
for testFile in {$testDir,$interactiveTestDir}/*.lans; do
java -jar $jarFile $testFile
echo
done
#Run
#Prerequisite: test files name and program name must match
#TODO run only if the build has succeded
echo "#####Running normal tests#####"
for testFile in $testDir/*.lans; do
programName=$(basename $testFile | sed 's/.lans//g')
echo Running $programName
java $programName >> $programName.out 2>> $programName.err
if [ -s "$programName.err" ]
then
echo "$programName has printed some errors:"
cat $programName.err
echo "-----end of errors-----"
fi
expectedOutFile="$expectedOutDir/$programName.out"
realOutFile="$programName.out"
if [ ! -f $expectedOutFile ]
then
echo Creating new expected out for $programName
cp $programName.out $expectedOutFile
else
if cmp -s "$expectedOutFile" "$realOutFile"
then
echo Ok!
else
echo Differences found!
diff "$expectedOutFile" "$realOutFile"
echo "-----end of differences------"
echo "cp $outputDir/$realOutFile $expectedOutFile" >> $tmpAcceptanceFile
fi
fi
echo
done
echo "#####Running Interactive tests#####"
for testFile in $interactiveTestDir/*.lans; do
programName=$(basename $testFile | sed 's/.lans//g')
echo Running $programName
interactiveInputFile="$interactiveInputDir/$programName.in"
if [ -f $interactiveInputFile ]
then
java $programName >> $programName.out 2>> $programName.err < $interactiveInputFile
if [ -s "$programName.err" ]
then
echo "$programName has printed some errors:"
cat $programName.err
echo "-----end of errors-----"
fi
expectedOutFile="$expectedOutDir/$programName.out"
realOutFile="$programName.out"
if [ ! -f $expectedOutFile ]
then
echo Creating new expected out for $programName
cp $programName.out $expectedOutFile
else
if cmp -s "$expectedOutFile" "$realOutFile"
then
echo Ok!
else
echo Differences found!
diff "$expectedOutFile" "$realOutFile"
echo "-----end of differences------"
echo "cp $outputDir/$realOutFile $expectedOutFile" >> $tmpAcceptanceFile
fi
fi
else
echo Warning! The interactive test $programName does NOT have an input defined!
fi
echo
done
if [ -f $tmpAcceptanceFile ]
then
chmod 755 $tmpAcceptanceFile
echo "To accept all differences as good run $tmpAcceptanceFile"
fi
cd $ogDir