-
Notifications
You must be signed in to change notification settings - Fork 4
/
run_analysis_tests
executable file
·153 lines (132 loc) · 5.37 KB
/
run_analysis_tests
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
148
149
150
151
152
153
#!/bin/bash
trap ctrl_c INT
function ctrl_c() {
echo "Stopping execution of tests"
}
function getJARFileName() {
ls spoofax-sunshine/org.metaborg.sunshine2/target/org.metaborg.sunshine2*
}
function runTests() {
local dir="$1"
local jarFile="$2"
for file in $dir/*; do
if [ -d $file ]; then
runTests $file $jarFile
elif [ "${file: -4}" == ".app" ]; then
runTest $file $jarFile
fi
done
}
function runTest() {
local test="$1"
local jarFile="$2"
local testName=${test%.app}
local testReplaced=$(echo $testName | sed -e 's/\//__/g')
local resultFile="analysis-results/$testReplaced.txt"
rm test-environment/*
cp "$test" test-environment/
# cat "$test" >> "$resultFile"
java -Xmx4G -Xms4G -Xss64m -jar "$jarFile" build \
-l webdslstatix \
-p test-environment \
2>&1 | tee -a "$resultFile"
addResultSummary "$testReplaced" "$test"
}
function addResultSummary() {
local resultFile="$1"
local testFile="$2"
local errors=$(cat "analysis-results/$resultFile.txt" | grep "ERROR in file" | grep -v "built-in.app" | wc -l | xargs)
local summary="$errors error(s)\n\n"
local suffix=""
local pattern=""
if [[ "$resultFile" == *"analysis-fails"* ]]; then
if [ ! "$errors" -eq "0" ]; then
suffix="PASSED"
else
suffix="FAILED"
fi
# suffix="PASSED"
#
# while read line; do
# if echo "$line" | grep -q "^//"; then
# pattern=`echo "$line" | sed 's/^[/]*//'`
# echo $pattern | grep -q "^\^"
# negate=$?
# echo $pattern | grep -q "^#"
# count=$?
# if [[ $negate == 0 ]]; then
# summary="$summary\n\nError must not be shown: ${pattern:1}"
# if grep -qi "${pattern:1}" "analysis-results/$resultFile.txt"; then
# summary="$summary\nTEST DID NOT PASS: The error was present in analysis:"
# errorInFile=$(grep -i "${pattern:1}" "analysis-results/$resultFile.txt")
# summary="$summary\n\t$errorInFile"
# suffix="FAILED"
# else
# summary="$summary\nTEST PASSED: Error was not present in analysis"
# fi
# elif [[ $count == 0 ]]; then
# occurrences=`echo $pattern | perl -pe 's/^#([0-9]+) .*$/\1/'`
# pattern=`echo $pattern | perl -pe 's/^#[0-9]+ (.*)$/\1/'`
# summary="$summary\n\nError must be shown $occurrences times: $pattern"
# foundlines=`grep -i "$pattern" "analysis-results/$resultFile.txt" | wc -l`
# summary="$summary\nError was found $foundlines times"
# if [ $foundlines -ne $occurrences ]; then
# summary="$summary\nTEST DID NOT PASS"
# suffix="FAILED"
# else
# summary="$summary\nTEST PASSED"
# fi
# else
# summary="$summary\n\nError must be shown: $pattern"
# if ! grep -qi "$pattern" "analysis-results/$resultFile.txt"; then
# summary="$summary\nTEST FAILED: Error was not present in analysis"
# suffix="FAILED"
# else
# errorInFile=$(grep -i "$pattern" "analysis-results/$resultFile.txt")
# summary="$summary\nTEST PASSED: Error was present in analysis:"
# summary="$summary\n\t$errorInFile"
# fi
# fi
# else
# break
# fi
# done <"$testFile"
fi
if [[ "$resultFile" == *"analysis-succeeds"* ]]; then
if [ "$errors" -eq "0" ]; then
suffix="PASSED"
else
suffix="FAILED"
fi
fi
testFileContent=$(cat "$testFile")
summary="$summary\n\n---TEST-FILE-BEGIN---\n$testFileContent\n---TEST-FILE-END---\n\n\n"
echo -e "$summary\n\n\n" | cat - "analysis-results/$resultFile.txt" > tmp.txt && mv tmp.txt "analysis-results/$resultFile.txt"
mv -v "analysis-results/$resultFile.txt" "analysis-results/${resultFile#webdslstatix.test__}__${suffix}.txt"
}
function aggregateResultData() {
local name="$1"
local passed="0"
local failed="0"
for file in analysis-results/*$name*PASSED.txt; do
passed=$(($passed+1))
done
for file in analysis-results/*$name*FAILED.txt; do
failed=$(($failed+1))
done
printf "Result:\n- passed: $passed\n- failed: $failed\n\n" > analysis-results/$name.txt
}
function main() {
local jarFile="$(getJARFileName)"
mkdir -p analysis-results
mkdir -p test-environment/.servletapp/src-webdsl-template
cp webdslstatix.test/stripped-built-in.app test-environment/.servletapp/src-webdsl-template/built-in.app
mkdir -p test-environment/lib
touch test-environment/lib/stxlibs
echo '["webdsl-built-in"]' > test-environment/lib/stxlibs
cp webdslstatix.example/webdsl-built-in.stxlib test-environment/lib/webdsl-built-in.stxlib
runTests "webdslstatix.test/analysis/1-original-compiler-tests" "$jarFile"
aggregateResultData "1-original-compiler-tests"
echo "DONE!"
}
main