forked from bazelbuild/rules_scala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_run.sh
executable file
·233 lines (203 loc) · 6.61 KB
/
test_run.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/bash
set -e
test_disappearing_class() {
git checkout test_expect_failure/disappearing_class/ClassProvider.scala
bazel build test_expect_failure/disappearing_class:uses_class
echo -e "package scala.test\n\nobject BackgroundNoise{}" > test_expect_failure/disappearing_class/ClassProvider.scala
set +e
bazel build test_expect_failure/disappearing_class:uses_class
RET=$?
git checkout test_expect_failure/disappearing_class/ClassProvider.scala
if [ $RET -eq 0 ]; then
echo "Class caching at play. This should fail"
exit 1
fi
set -e
}
md5_util() {
if [[ "$OSTYPE" == "darwin"* ]]; then
_md5_util="md5"
else
_md5_util="md5sum"
fi
echo "$_md5_util"
}
test_build_is_identical() {
bazel build test/...
$(md5_util) bazel-bin/test/*.jar > hash1
bazel clean
bazel build test/...
$(md5_util) bazel-bin/test/*.jar > hash2
diff hash1 hash2
}
test_transitive_deps() {
set +e
bazel build test_expect_failure/transitive/scala_to_scala:d
if [ $? -eq 0 ]; then
echo "'bazel build test_expect_failure/transitive/scala_to_scala:d' should have failed."
exit 1
fi
bazel build test_expect_failure/transitive/java_to_scala:d
if [ $? -eq 0 ]; then
echo "'bazel build test_expect_failure/transitive/java_to_scala:d' should have failed."
exit 1
fi
bazel build test_expect_failure/transitive/scala_to_java:d
if [ $? -eq 0 ]; then
echo "'bazel build test_transitive_deps/scala_to_java:d' should have failed."
exit 1
fi
set -e
exit 0
}
test_scala_library_suite() {
set +e
bazel build test_expect_failure/scala_library_suite:library_suite_dep_on_children
if [ $? -eq 0 ]; then
echo "'bazel build test_expect_failure/scala_library_suite:library_suite_dep_on_children' should have failed."
exit 1
fi
set -e
exit 0
}
test_scala_junit_test_can_fail() {
set +e
bazel test test_expect_failure/scala_junit_test:failing_test
if [ $? -eq 0 ]; then
echo "'bazel build test_expect_failure/scala_junit_test:failing_test' should have failed."
exit 1
fi
set -e
exit 0
}
test_repl() {
echo "import scala.test._; HelloLib.printMessage(\"foo\")" | bazel-bin/test/HelloLibRepl | grep "foo java" &&
echo "import scala.test._; TestUtil.foo" | bazel-bin/test/HelloLibTestRepl | grep "bar" &&
echo "import scala.test._; ScalaLibBinary.main(Array())" | bazel-bin/test/ScalaLibBinaryRepl | grep "A hui hou" &&
echo "import scala.test._; MoreScalaLibBinary.main(Array())" | bazel-bin/test/MoreScalaLibBinaryRepl | grep "More Hello"
echo "import scala.test._; A.main(Array())" | bazel-bin/test/ReplWithSources | grep "4 8 15"
}
test_benchmark_jmh() {
RES=$(bazel run -- test/jmh:test_benchmark -i1 -f1 -wi 1)
RESPONSE_CODE=$?
if [[ $RES != *Result*Benchmark* ]]; then
echo "Benchmark did not produce expected output:\n$RES"
exit 1
fi
exit $RESPONSE_CODE
}
NC='\033[0m'
GREEN='\033[0;32m'
RED='\033[0;31m'
function run_test() {
set +e
SECONDS=0
TEST_ARG=$@
echo "running test $TEST_ARG"
RES=$($TEST_ARG 2>&1)
RESPONSE_CODE=$?
DURATION=$SECONDS
if [ $RESPONSE_CODE -eq 0 ]; then
echo -e "${GREEN} Test $TEST_ARG successful ($DURATION sec) $NC"
else
echo "$RES"
echo -e "${RED} Test $TEST_ARG failed $NC ($DURATION sec) $NC"
exit $RESPONSE_CODE
fi
}
xmllint_test() {
find -L ./bazel-testlogs -iname "*.xml" | xargs -n1 xmllint > /dev/null
}
multiple_junit_suffixes() {
bazel test //test:JunitMultipleSuffixes
matches=$(grep -c -e 'Discovered classes' -e 'scala.test.junit.JunitSuffixIT' -e 'scala.test.junit.JunitSuffixE2E' ./bazel-testlogs/test/JunitMultipleSuffixes/test.log)
if [ $matches -eq 3 ]; then
return 0
else
return 1
fi
}
multiple_junit_prefixes() {
bazel test //test:JunitMultiplePrefixes
matches=$(grep -c -e 'Discovered classes' -e 'scala.test.junit.TestJunitCustomPrefix' -e 'scala.test.junit.OtherCustomPrefixJunit' ./bazel-testlogs/test/JunitMultiplePrefixes/test.log)
if [ $matches -eq 3 ]; then
return 0
else
return 1
fi
}
multiple_junit_patterns() {
bazel test //test:JunitPrefixesAndSuffixes
matches=$(grep -c -e 'Discovered classes' -e 'scala.test.junit.TestJunitCustomPrefix' -e 'scala.test.junit.JunitSuffixE2E' ./bazel-testlogs/test/JunitPrefixesAndSuffixes/test.log)
if [ $matches -eq 3 ]; then
return 0
else
return 1
fi
}
junit_generates_xml_logs() {
bazel test //test:JunitTestWithDeps
test -e ./bazel-testlogs/test/JunitTestWithDeps/test.xml
}
test_junit_test_must_have_prefix_or_suffix() {
set +e
bazel test test_expect_failure/scala_junit_test:no_prefix_or_suffix
if [ $? -eq 0 ]; then
echo "'bazel build test_expect_failure/scala_junit_test:no_prefix_or_suffix' should have failed."
exit 1
fi
set -e
exit 0
}
test_junit_test_errors_when_no_tests_found() {
set +e
bazel test test_expect_failure/scala_junit_test:no_tests_found
if [ $? -eq 0 ]; then
echo "'bazel build test_expect_failure/scala_junit_test:no_tests_found' should have failed."
exit 1
fi
set -e
exit 0
}
test_resources() {
RESOURCE_NAME="resource.txt"
TARGET=$1
OUTPUT_JAR="bazel-bin/test/src/main/scala/scala/test/resources/$TARGET.jar"
FULL_TARGET="test/src/main/scala/scala/test/resources/$TARGET.jar"
bazel build $FULL_TARGET
jar tf $OUTPUT_JAR | grep $RESOURCE_NAME
}
scala_library_jar_without_srcs_must_include_direct_file_resources(){
test_resources "noSrcsWithDirectFileResources"
}
scala_library_jar_without_srcs_must_include_filegroup_resources(){
test_resources "noSrcsWithFilegroupResources"
}
run_test bazel build test/...
run_test bazel test test/...
run_test bazel run test/src/main/scala/scala/test/twitter_scrooge:justscrooges
run_test bazel run test:JavaBinary
run_test bazel run test:JavaBinary2
run_test bazel run test:MixJavaScalaLibBinary
run_test bazel run test:MixJavaScalaSrcjarLibBinary
run_test bazel run test:ScalaBinary
run_test bazel run test:ScalaLibBinary
run_test test_disappearing_class
run_test find -L ./bazel-testlogs -iname "*.xml"
run_test xmllint_test
run_test test_build_is_identical
run_test test_transitive_deps
run_test test_scala_library_suite
run_test test_repl
run_test bazel run test:JavaOnlySources
run_test test_benchmark_jmh
run_test multiple_junit_suffixes
run_test multiple_junit_prefixes
run_test test_scala_junit_test_can_fail
run_test junit_generates_xml_logs
run_test multiple_junit_patterns
run_test test_junit_test_must_have_prefix_or_suffix
run_test test_junit_test_errors_when_no_tests_found
run_test scala_library_jar_without_srcs_must_include_direct_file_resources
run_test scala_library_jar_without_srcs_must_include_filegroup_resources
run_test bazel run test/src/main/scala/scala/test/large_classpath:largeClasspath