forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.sh
executable file
·392 lines (357 loc) · 13.6 KB
/
run_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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#!/bin/bash
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
###############################################################################
# run_tests.sh
#
# This runs all the different types of tests for pigeon. It should be run from
# the directory that contains the script.
###############################################################################
# exit when any command fails
set -e
# TODO(blasten): Enable on stable when possible.
# https://github.com/flutter/flutter/issues/75187
if [[ "$CHANNEL" == "stable" ]]; then
exit 0
fi
###############################################################################
# Variables
###############################################################################
flutter=$(which flutter)
flutter_bin=$(dirname $flutter)
framework_path="$flutter_bin/cache/artifacts/engine/ios/"
java_linter=checkstyle-8.41-all.jar
java_formatter=google-java-format-1.3-all-deps.jar
google_checks=google_checks.xml
google_checks_version=7190c47ca5515ad8cb827bc4065ae7664d2766c1
java_error_prone=error_prone_core-2.5.1-with-dependencies.jar
dataflow_shaded=dataflow-shaded-3.7.1.jar
jformat_string=jFormatString-3.0.0.jar
java_version=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
javac_jar=javac-9+181-r4173-1.jar
if [ $java_version == "8" ]; then
javac_bootclasspath="-J-Xbootclasspath/p:ci/$javac_jar"
else
javac_bootclasspath=
fi
run_pigeon="dart bin/pigeon.dart.dill --copyright_header ./copyright_header.txt"
###############################################################################
# Helper Functions
###############################################################################
# Create a temporary directory in a way that works on both Linux and macOS.
#
# The mktemp commands have slighly semantics on the BSD systems vs GNU systems.
mktmpdir() {
mktemp -d flutter_pigeon.XXXXXX 2>/dev/null || mktemp -d -t flutter_pigeon.
}
# test_pigeon_android(<path to pigeon file>)
#
# Compiles the pigeon file to a temp directory and attempts to compile the java
# code.
test_pigeon_android() {
echo "test_pigeon_android($1)"
temp_dir=$(mktmpdir)
$run_pigeon \
--input $1 \
--dart_out $temp_dir/pigeon.dart \
--java_out $temp_dir/Pigeon.java \
--java_package foo
java -jar ci/$java_formatter --replace "$temp_dir/Pigeon.java"
java -jar ci/$java_linter -c "ci/$google_checks" "$temp_dir/Pigeon.java"
if ! javac \
$javac_bootclasspath \
-XDcompilePolicy=simple \
-processorpath "ci/$java_error_prone:ci/$dataflow_shaded:ci/$jformat_string" \
'-Xplugin:ErrorProne -Xep:CatchingUnchecked:ERROR' \
-classpath "$flutter_bin/cache/artifacts/engine/android-x64/flutter.jar" \
$temp_dir/Pigeon.java; then
echo "javac $temp_dir/Pigeon.java failed"
exit 1
fi
rm -rf $temp_dir
}
# test_null_safe_dart(<path to pigeon file>)
#
# Compiles the pigeon file to a temp directory and attempts to run the dart
# analyzer on it.
test_pigeon_dart() {
echo "test_pigeon_dart($1, $2)"
local flutter_project_dir=$2
$run_pigeon \
--input $1 \
--dart_out $flutter_project_dir/lib/pigeon.dart
dart analyze $flutter_project_dir/lib/pigeon.dart --fatal-infos --fatal-warnings
rm $flutter_project_dir/lib/pigeon.dart
}
print_usage() {
echo "usage: ./run_tests.sh [-l] [-t test_name]
flags:
-t test_name: Run only specified test.
-l : List available tests.
"
}
gen_ios_unittests_code() {
local input=$1
local prefix=$2
local filename=${input##*/}
local name="${filename%.dart}"
$run_pigeon \
--input $input \
--objc_prefix "$prefix" \
--dart_out /dev/null \
--objc_header_out platform_tests/ios_unit_tests/ios/Runner/$name.gen.h \
--objc_source_out platform_tests/ios_unit_tests/ios/Runner/$name.gen.m
}
gen_android_unittests_code() {
local input=$1
local javaName=$2
local javaOut="platform_tests/android_unit_tests/android/app/src/main/java/com/example/android_unit_tests/$javaName.java"
$run_pigeon \
--input $input \
--dart_out /dev/null \
--java_out $javaOut \
--java_package "com.example.android_unit_tests"
java -jar ci/$java_formatter --replace $javaOut
java -jar ci/$java_linter -c "ci/$google_checks" "$javaOut"
}
###############################################################################
# Stages
###############################################################################
get_java_linter_formatter() {
if [ ! -f "ci/$java_linter" ]; then
curl -L https://github.com/checkstyle/checkstyle/releases/download/checkstyle-8.41/$java_linter >"ci/$java_linter"
fi
if [ ! -f "ci/$java_formatter" ]; then
curl -L https://github.com/google/google-java-format/releases/download/google-java-format-1.3/$java_formatter >"ci/$java_formatter"
fi
if [ ! -f "ci/$google_checks" ]; then
curl -L https://raw.githubusercontent.com/checkstyle/checkstyle/$google_checks_version/src/main/resources/$google_checks >"ci/$google_checks"
fi
if [ ! -f "ci/$java_error_prone" ]; then
curl https://repo1.maven.org/maven2/com/google/errorprone/error_prone_core/2.5.1/$java_error_prone >"ci/$java_error_prone"
fi
if [ ! -f "ci/$dataflow_shaded" ]; then
curl https://repo1.maven.org/maven2/org/checkerframework/dataflow-shaded/3.7.1/$dataflow_shaded >"ci/$dataflow_shaded"
fi
if [ ! -f "ci/$jformat_string" ]; then
curl https://repo1.maven.org/maven2/com/google/code/findbugs/jFormatString/3.0.0/$jformat_string >"ci/$jformat_string"
fi
if [ ! -f "ci/$javac_jar" ]; then
curl https://repo1.maven.org/maven2/com/google/errorprone/javac/9+181-r4173-1/$javac_jar >"ci/$javac_jar"
fi
}
run_dart_unittests() {
dart run tool/run_tests.dart -t dart_unittests
}
test_command_line() {
# Test with no arguments.
$run_pigeon 1>/dev/null
# Test one_language flag. With this flag specified, java_out can be generated
# without dart_out.
$run_pigeon \
--input pigeons/message.dart \
--one_language \
--java_out stdout \
| grep "public class Message">/dev/null
# Test dartOut in ConfigurePigeon overrides output.
$run_pigeon --input pigeons/configure_pigeon_dart_out.dart 1>/dev/null
# Make sure AST generation exits correctly.
$run_pigeon --input pigeons/message.dart --one_language --ast_out /dev/null
}
run_flutter_unittests() {
dart run tool/run_tests.dart -t flutter_unittests
}
run_mock_handler_tests() {
dart run tool/run_tests.dart -t mock_handler_tests
}
run_dart_compilation_tests() {
local temp_dir=$(mktmpdir)
local flutter_project_dir=$temp_dir/project
flutter create --platforms="android" $flutter_project_dir 1> /dev/null
test_pigeon_dart ./pigeons/all_void.dart $flutter_project_dir
test_pigeon_dart ./pigeons/async_handlers.dart $flutter_project_dir
test_pigeon_dart ./pigeons/host2flutter.dart $flutter_project_dir
test_pigeon_dart ./pigeons/list.dart $flutter_project_dir
test_pigeon_dart ./pigeons/message.dart $flutter_project_dir
test_pigeon_dart ./pigeons/void_arg_flutter.dart $flutter_project_dir
test_pigeon_dart ./pigeons/void_arg_host.dart $flutter_project_dir
test_pigeon_dart ./pigeons/voidflutter.dart $flutter_project_dir
test_pigeon_dart ./pigeons/voidhost.dart $flutter_project_dir
rm -rf $temp_dir
}
run_ios_unittests() {
gen_ios_unittests_code ./pigeons/all_void.dart ""
gen_ios_unittests_code ./pigeons/all_datatypes.dart ""
gen_ios_unittests_code ./pigeons/async_handlers.dart ""
gen_ios_unittests_code ./pigeons/background_platform_channels.dart "BC"
gen_ios_unittests_code ./pigeons/enum.dart "AC"
gen_ios_unittests_code ./pigeons/enum_args.dart "EA"
gen_ios_unittests_code ./pigeons/host2flutter.dart ""
gen_ios_unittests_code ./pigeons/list.dart "LST"
gen_ios_unittests_code ./pigeons/message.dart ""
gen_ios_unittests_code ./pigeons/multiple_arity.dart ""
gen_ios_unittests_code ./pigeons/non_null_fields.dart "NNF"
gen_ios_unittests_code ./pigeons/null_fields.dart ""
gen_ios_unittests_code ./pigeons/nullable_returns.dart "NR"
gen_ios_unittests_code ./pigeons/primitive.dart ""
gen_ios_unittests_code ./pigeons/void_arg_flutter.dart "VAF"
gen_ios_unittests_code ./pigeons/void_arg_host.dart "VAH"
gen_ios_unittests_code ./pigeons/voidflutter.dart "VF"
gen_ios_unittests_code ./pigeons/voidhost.dart "VH"
pushd $PWD
cd platform_tests/ios_unit_tests
flutter build ios --simulator
cd ios
xcodebuild \
-workspace Runner.xcworkspace \
-scheme RunnerTests \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 8' \
test
popd
}
run_ios_e2e_tests() {
DARTLE_H="e2e_tests/test_objc/ios/Runner/dartle.h"
DARTLE_M="e2e_tests/test_objc/ios/Runner/dartle.m"
DARTLE_DART="e2e_tests/test_objc/lib/dartle.dart"
PIGEON_JAVA="e2e_tests/test_objc/android/app/src/main/java/io/flutter/plugins/Pigeon.java"
$run_pigeon \
--input pigeons/message.dart \
--dart_out $DARTLE_DART \
--objc_header_out $DARTLE_H \
--objc_source_out $DARTLE_M \
--java_out $PIGEON_JAVA
dart format $DARTLE_DART
pushd $PWD
cd e2e_tests/test_objc
flutter build ios -t test_driver/e2e_test.dart --simulator
# TODO(gaaclarke): Transition to integration_test. `e2e` has been deprecated
# and has stopped working.
# cd ios
# xcodebuild \
# -workspace Runner.xcworkspace \
# -scheme RunnerTests \
# -sdk iphonesimulator \
# -destination 'platform=iOS Simulator,name=iPhone 8' \
# test
popd
}
run_android_unittests() {
pushd $PWD
gen_android_unittests_code ./pigeons/all_datatypes.dart AllDatatypes
gen_android_unittests_code ./pigeons/all_void.dart AllVoid
gen_android_unittests_code ./pigeons/android_unittests.dart Pigeon
gen_android_unittests_code ./pigeons/async_handlers.dart AsyncHandlers
gen_android_unittests_code ./pigeons/background_platform_channels.dart BackgroundPlatformChannels
gen_android_unittests_code ./pigeons/enum.dart Enum
gen_android_unittests_code ./pigeons/enum_args.dart EnumArgs
gen_android_unittests_code ./pigeons/host2flutter.dart Host2Flutter
gen_android_unittests_code ./pigeons/java_double_host_api.dart JavaDoubleHostApi
gen_android_unittests_code ./pigeons/list.dart PigeonList
gen_android_unittests_code ./pigeons/message.dart MessagePigeon
gen_android_unittests_code ./pigeons/multiple_arity.dart MultipleArity
gen_android_unittests_code ./pigeons/non_null_fields.dart NonNullFields
gen_android_unittests_code ./pigeons/null_fields.dart NullFields
gen_android_unittests_code ./pigeons/nullable_returns.dart NullableReturns
gen_android_unittests_code ./pigeons/primitive.dart Primitive
gen_android_unittests_code ./pigeons/void_arg_flutter.dart VoidArgFlutter
gen_android_unittests_code ./pigeons/void_arg_host.dart VoidArgHost
gen_android_unittests_code ./pigeons/voidflutter.dart VoidFlutter
gen_android_unittests_code ./pigeons/voidhost.dart VoidHost
cd platform_tests/android_unit_tests
if [ ! -f "android/gradlew" ]; then
flutter build apk --debug
fi
cd android
./gradlew test
popd
}
###############################################################################
# main
###############################################################################
should_run_android_unittests=true
should_run_dart_compilation_tests=true
should_run_dart_unittests=true
should_run_flutter_unittests=true
should_run_ios_e2e_tests=true
should_run_ios_unittests=true
should_run_mock_handler_tests=true
while getopts "t:l?h" opt; do
case $opt in
t)
should_run_android_unittests=false
should_run_dart_compilation_tests=false
should_run_dart_unittests=false
should_run_flutter_unittests=false
should_run_ios_e2e_tests=false
should_run_ios_unittests=false
should_run_mock_handler_tests=false
case $OPTARG in
android_unittests) should_run_android_unittests=true ;;
dart_compilation_tests) should_run_dart_compilation_tests=true ;;
dart_unittests) should_run_dart_unittests=true ;;
flutter_unittests) should_run_flutter_unittests=true ;;
ios_e2e_tests) should_run_ios_e2e_tests=true ;;
ios_unittests) should_run_ios_unittests=true ;;
mock_handler_tests) should_run_mock_handler_tests=true ;;
*)
echo "unrecognized test: $OPTARG"
exit 1
;;
esac
;;
l)
echo "available tests for -t:
android_unittests - Unit tests on generated Java code.
dart_compilation_tests - Compilation tests on generated Dart code.
dart_unittests - Unit tests on and analysis on Pigeon's implementation.
flutter_unittests - Unit tests on generated Dart code.
ios_e2e_tests - End-to-end objc tests run on iOS Simulator
ios_unittests - Unit tests on generated Objc code.
mock_handler_tests - Unit tests on generated Dart mock handler code.
"
exit 1
;;
\h)
print_usage
exit 1
;;
\?)
print_usage
exit 1
;;
?)
print_usage
exit 1
;;
esac
done
##############################################################################
dart pub get
dart --snapshot-kind=kernel --snapshot=bin/pigeon.dart.dill bin/pigeon.dart
if [ "$should_run_android_unittests" = true ]; then
get_java_linter_formatter
fi
test_command_line
if [ "$should_run_dart_unittests" = true ]; then
run_dart_unittests
fi
if [ "$should_run_flutter_unittests" = true ]; then
run_flutter_unittests
fi
if [ "$should_run_mock_handler_tests" = true ]; then
run_mock_handler_tests
fi
if [ "$should_run_dart_compilation_tests" = true ]; then
run_dart_compilation_tests
fi
if [ "$should_run_ios_unittests" = true ]; then
run_ios_unittests
fi
if [ "$should_run_ios_e2e_tests" = true ]; then
run_ios_e2e_tests
fi
if [ "$should_run_android_unittests" = true ]; then
run_android_unittests
fi