[pigeon] cleaned up run_test.sh (#325)

cleaned up run_test.sh, allowed you to specify what you want to run
This commit is contained in:
gaaclarke
2021-04-15 13:23:40 -07:00
committed by GitHub
parent ed4ec6fa83
commit 2085a1f240
2 changed files with 323 additions and 174 deletions

View File

@ -1,3 +1,4 @@
#!/bin/bash
############################################################################### ###############################################################################
# run_tests.sh # run_tests.sh
# #
@ -6,22 +7,7 @@
############################################################################### ###############################################################################
# exit when any command fails # exit when any command fails
set -ex set -e
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
# TODO(blasten): Enable on stable when possible. # TODO(blasten): Enable on stable when possible.
# https://github.com/flutter/flutter/issues/75187 # https://github.com/flutter/flutter/issues/75187
@ -36,8 +22,23 @@ flutter=$(which flutter)
flutter_bin=$(dirname $flutter) flutter_bin=$(dirname $flutter)
framework_path="$flutter_bin/cache/artifacts/engine/ios/" 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
############################################################################### ###############################################################################
# Functions # Helper Functions
############################################################################### ###############################################################################
# Create a temporary directory in a way that works on both Linux and macOS. # Create a temporary directory in a way that works on both Linux and macOS.
@ -49,9 +50,10 @@ mktmpdir() {
# test_pigeon_ios(<path to pigeon file>) # test_pigeon_ios(<path to pigeon file>)
# #
# Compiles the pigeon file to a temp directory and attempts to compile the code # Compiles the pigeon file to a temp directory and attempts to compile the objc
# and runs the dart analyzer on the generated dart code. # code.
test_pigeon_ios() { test_pigeon_ios() {
echo "test_pigeon_ios($1)"
temp_dir=$(mktmpdir) temp_dir=$(mktmpdir)
pub run pigeon \ pub run pigeon \
@ -76,8 +78,10 @@ test_pigeon_ios() {
# test_pigeon_android(<path to pigeon file>) # test_pigeon_android(<path to pigeon file>)
# #
# Compiles the pigeon file to a temp directory and attempts to compile the code. # Compiles the pigeon file to a temp directory and attempts to compile the java
# code.
test_pigeon_android() { test_pigeon_android() {
echo "test_pigeon_android($1)"
temp_dir=$(mktmpdir) temp_dir=$(mktmpdir)
pub run pigeon \ pub run pigeon \
@ -86,12 +90,12 @@ test_pigeon_android() {
--java_out $temp_dir/Pigeon.java \ --java_out $temp_dir/Pigeon.java \
--java_package foo --java_package foo
java -jar ci/$JAVA_FORMATTER --replace "$temp_dir/Pigeon.java" java -jar ci/$java_formatter --replace "$temp_dir/Pigeon.java"
java -jar ci/$JAVA_LINTER -c "ci/$GOOGLE_CHECKS" "$temp_dir/Pigeon.java" java -jar ci/$java_linter -c "ci/$google_checks" "$temp_dir/Pigeon.java"
if ! javac \ if ! javac \
$JAVAC_BOOTCLASSPATH \ $javac_bootclasspath \
-XDcompilePolicy=simple \ -XDcompilePolicy=simple \
-processorpath "ci/$JAVA_ERROR_PRONE:ci/$DATAFLOW_SHADED:ci/$JFORMAT_STRING" \ -processorpath "ci/$java_error_prone:ci/$dataflow_shaded:ci/$jformat_string" \
'-Xplugin:ErrorProne -Xep:CatchingUnchecked:ERROR' \ '-Xplugin:ErrorProne -Xep:CatchingUnchecked:ERROR' \
-classpath "$flutter_bin/cache/artifacts/engine/android-x64/flutter.jar" \ -classpath "$flutter_bin/cache/artifacts/engine/android-x64/flutter.jar" \
$temp_dir/Pigeon.java; then $temp_dir/Pigeon.java; then
@ -99,69 +103,93 @@ test_pigeon_android() {
exit 1 exit 1
fi fi
dartfmt -w $temp_dir/pigeon.dart
dartanalyzer $temp_dir/pigeon.dart --fatal-infos --fatal-warnings --packages ./e2e_tests/test_objc/.packages
rm -rf $temp_dir rm -rf $temp_dir
} }
# test_null_safe_dart(<path to pigeon file>) # test_null_safe_dart(<path to pigeon file>)
# #
# Compiles the pigeon file to a temp directory and attempts to run the dart # Compiles the pigeon file to a temp directory and attempts to run the dart
# analyzer on it with null safety turned on. # analyzer on it with and without null safety turned on.
test_null_safe_dart() { test_pigeon_dart() {
temp_dir=$(mktmpdir) echo "test_pigeon_dart($1)"
temp_dir_1=$(mktmpdir)
temp_dir_2=$(mktmpdir)
pub run pigeon \ pub run pigeon \
--input $1 \ --input $1 \
--dart_out $temp_dir/pigeon.dart --dart_out $temp_dir_1/pigeon.dart &
null_safe_gen_pid=$!
dartanalyzer $temp_dir/pigeon.dart --fatal-infos --fatal-warnings --packages ./e2e_tests/test_objc/.packages pub run pigeon \
rm -rf $temp_dir --no-dart_null_safety \
--input $1 \
--dart_out $temp_dir_2/pigeon.dart &
non_null_safe_gen_pid=$!
wait $null_safe_gen_pid
wait $non_null_safe_gen_pid
# `./e2e_tests/test_objc/.packages` is used to get access to Flutter since
# Pigeon doesn't depend on Flutter.
dartanalyzer $temp_dir_1/pigeon.dart --fatal-infos --fatal-warnings --packages ./e2e_tests/test_objc/.packages &
null_safe_analyze_pid=$!
dartanalyzer $temp_dir_2/pigeon.dart --fatal-infos --fatal-warnings --packages ./e2e_tests/test_objc/.packages &
non_null_safe_analyze_pid=$!
wait $null_safe_analyze_pid
wait $non_null_safe_analyze_pid
rm -rf $temp_dir_1
rm -rf $temp_dir_2
}
print_usage() {
echo "usage: ./run_tests.sh [-l] [-t test_name]
flags:
-t test_name: Run only specified test.
-l : List available tests.
"
} }
############################################################################### ###############################################################################
# Get java linter / formatter # Stages
############################################################################### ###############################################################################
if [ ! -f "ci/$JAVA_LINTER" ]; then get_java_linter_formatter() {
curl -L https://github.com/checkstyle/checkstyle/releases/download/checkstyle-8.41/$JAVA_LINTER > "ci/$JAVA_LINTER" if [ ! -f "ci/$java_linter" ]; then
curl -L https://github.com/checkstyle/checkstyle/releases/download/checkstyle-8.41/$java_linter >"ci/$java_linter"
fi fi
if [ ! -f "ci/$JAVA_FORMATTER" ]; then 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" curl -L https://github.com/google/google-java-format/releases/download/google-java-format-1.3/$java_formatter >"ci/$java_formatter"
fi fi
if [ ! -f "ci/$GOOGLE_CHECKS" ]; then 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" curl -L https://raw.githubusercontent.com/checkstyle/checkstyle/$google_checks_version/src/main/resources/$google_checks >"ci/$google_checks"
fi fi
if [ ! -f "ci/$JAVA_ERROR_PRONE" ]; then 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" curl https://repo1.maven.org/maven2/com/google/errorprone/error_prone_core/2.5.1/$java_error_prone >"ci/$java_error_prone"
fi fi
if [ ! -f "ci/$DATAFLOW_SHADED" ]; then if [ ! -f "ci/$dataflow_shaded" ]; then
curl https://repo1.maven.org/maven2/org/checkerframework/dataflow-shaded/3.7.1/$DATAFLOW_SHADED > "ci/$DATAFLOW_SHADED" curl https://repo1.maven.org/maven2/org/checkerframework/dataflow-shaded/3.7.1/$dataflow_shaded >"ci/$dataflow_shaded"
fi fi
if [ ! -f "ci/$JFORMAT_STRING" ]; then 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" curl https://repo1.maven.org/maven2/com/google/code/findbugs/jFormatString/3.0.0/$jformat_string >"ci/$jformat_string"
fi fi
if [ ! -f "ci/$JAVAC_JAR" ]; then 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" curl https://repo1.maven.org/maven2/com/google/errorprone/javac/9+181-r4173-1/$javac_jar >"ci/$javac_jar"
fi fi
}
run_dart_unittests() {
###############################################################################
# Dart analysis and unit tests
###############################################################################
pub get
dart analyze bin dart analyze bin
dart analyze lib dart analyze lib
dart test dart test
}
############################################################################### test_running_without_arguments() {
# Execute without arguments test
###############################################################################
pub run pigeon 1>/dev/null pub run pigeon 1>/dev/null
}
############################################################################### run_flutter_unittests() {
# Run unit tests on generated Dart code.
###############################################################################
pushd $PWD pushd $PWD
pub run pigeon \ pub run pigeon \
--input pigeons/message.dart \ --input pigeons/message.dart \
@ -170,10 +198,9 @@ cd platform_tests/flutter_null_safe_unit_tests
flutter pub get flutter pub get
flutter test test/null_safe_test.dart flutter test test/null_safe_test.dart
popd popd
}
############################################################################### run_mock_handler_tests() {
# Mock handler flutter tests.
###############################################################################
pushd $PWD pushd $PWD
pub run pigeon \ pub run pigeon \
--input pigeons/message.dart \ --input pigeons/message.dart \
@ -184,10 +211,9 @@ dartfmt -w mock_handler_tester/test/test.dart
cd mock_handler_tester cd mock_handler_tester
flutter test flutter test
popd popd
}
############################################################################### run_dart_compilation_tests() {
# Compilation tests (Code is generated and compiled)
###############################################################################
# Make sure the artifacts are present. # Make sure the artifacts are present.
flutter precache flutter precache
# Make sure flutter dependencies are available. # Make sure flutter dependencies are available.
@ -195,29 +221,53 @@ pushd $PWD
cd e2e_tests/test_objc/ cd e2e_tests/test_objc/
flutter pub get flutter pub get
popd popd
test_pigeon_ios ./pigeons/async_handlers.dart test_pigeon_dart ./pigeons/all_datatypes.dart
test_null_safe_dart ./pigeons/message.dart test_pigeon_dart ./pigeons/async_handlers.dart
test_pigeon_android ./pigeons/voidflutter.dart test_pigeon_dart ./pigeons/host2flutter.dart
test_pigeon_android ./pigeons/voidhost.dart test_pigeon_dart ./pigeons/list.dart
test_pigeon_android ./pigeons/host2flutter.dart test_pigeon_dart ./pigeons/message.dart
test_pigeon_android ./pigeons/message.dart test_pigeon_dart ./pigeons/void_arg_flutter.dart
test_pigeon_android ./pigeons/void_arg_host.dart test_pigeon_dart ./pigeons/void_arg_host.dart
test_pigeon_android ./pigeons/void_arg_flutter.dart test_pigeon_dart ./pigeons/voidflutter.dart
test_pigeon_android ./pigeons/list.dart test_pigeon_dart ./pigeons/voidhost.dart
}
run_java_compilation_tests() {
# Make sure the artifacts are present.
flutter precache
# Make sure flutter dependencies are available.
pushd $PWD
# We use e2e_tests/test_objc in order to get access to Flutter.
cd e2e_tests/test_objc/
flutter pub get
popd
test_pigeon_android ./pigeons/all_datatypes.dart test_pigeon_android ./pigeons/all_datatypes.dart
test_pigeon_android ./pigeons/async_handlers.dart test_pigeon_android ./pigeons/async_handlers.dart
test_pigeon_ios ./pigeons/message.dart test_pigeon_android ./pigeons/host2flutter.dart
test_pigeon_ios ./pigeons/host2flutter.dart test_pigeon_android ./pigeons/list.dart
test_pigeon_ios ./pigeons/voidhost.dart test_pigeon_android ./pigeons/message.dart
test_pigeon_ios ./pigeons/voidflutter.dart test_pigeon_android ./pigeons/void_arg_flutter.dart
test_pigeon_ios ./pigeons/void_arg_host.dart test_pigeon_android ./pigeons/void_arg_host.dart
test_pigeon_ios ./pigeons/void_arg_flutter.dart test_pigeon_android ./pigeons/voidflutter.dart
test_pigeon_ios ./pigeons/list.dart test_pigeon_android ./pigeons/voidhost.dart
test_pigeon_ios ./pigeons/all_datatypes.dart }
############################################################################### run_objc_compilation_tests() {
# iOS unit tests on generated code. # Make sure the artifacts are present.
############################################################################### flutter precache
test_pigeon_ios ./pigeons/all_datatypes.dart
test_pigeon_ios ./pigeons/async_handlers.dart
test_pigeon_ios ./pigeons/host2flutter.dart
test_pigeon_ios ./pigeons/list.dart
test_pigeon_ios ./pigeons/message.dart
test_pigeon_ios ./pigeons/void_arg_flutter.dart
test_pigeon_ios ./pigeons/void_arg_host.dart
test_pigeon_ios ./pigeons/voidflutter.dart
test_pigeon_ios ./pigeons/voidhost.dart
}
run_ios_unittests() {
pub run pigeon \ pub run pigeon \
--no-dart_null_safety \ --no-dart_null_safety \
--input pigeons/message.dart \ --input pigeons/message.dart \
@ -245,10 +295,9 @@ xcodebuild \
-destination 'platform=iOS Simulator,name=iPhone 8' \ -destination 'platform=iOS Simulator,name=iPhone 8' \
test test
popd popd
}
############################################################################### run_ios_e2e_tests() {
# End-to-end (e2e) integration tests.
###############################################################################
DARTLE_H="e2e_tests/test_objc/ios/Runner/dartle.h" DARTLE_H="e2e_tests/test_objc/ios/Runner/dartle.h"
DARTLE_M="e2e_tests/test_objc/ios/Runner/dartle.m" DARTLE_M="e2e_tests/test_objc/ios/Runner/dartle.m"
DARTLE_DART="e2e_tests/test_objc/lib/dartle.dart" DARTLE_DART="e2e_tests/test_objc/lib/dartle.dart"
@ -272,9 +321,109 @@ xcodebuild \
-destination 'platform=iOS Simulator,name=iPhone 8' \ -destination 'platform=iOS Simulator,name=iPhone 8' \
test test
popd popd
}
run_formatter() {
cd ../..
pub global activate flutter_plugin_tools && pub global run flutter_plugin_tools format 2>/dev/null
}
############################################################################### ###############################################################################
# Run the formatter on generated code. # main
############################################################################### ###############################################################################
cd ../.. should_run_dart_compilation_tests=true
pub global activate flutter_plugin_tools && pub global run flutter_plugin_tools format should_run_dart_unittests=true
should_run_flutter_unittests=true
should_run_formatter=true
should_run_ios_e2e_tests=true
should_run_ios_unittests=true
should_run_java_compilation_tests=true
should_run_mock_handler_tests=true
should_run_objc_compilation_tests=true
while getopts "t:l?h" opt; do
case $opt in
t)
should_run_dart_compilation_tests=false
should_run_dart_unittests=false
should_run_flutter_unittests=false
should_run_formatter=false
should_run_ios_e2e_tests=false
should_run_ios_unittests=false
should_run_java_compilation_tests=false
should_run_mock_handler_tests=false
should_run_objc_compilation_tests=false
case $OPTARG in
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 ;;
java_compilation_tests) should_run_java_compilation_tests=true ;;
mock_handler_tests) should_run_mock_handler_tests=true ;;
objc_compilation_tests) should_run_objc_compilation_tests=true ;;
*)
echo "unrecognized test: $OPTARG"
exit 1
;;
esac
;;
l)
echo "available tests for -t:
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.
java_compilation_tests - Compilation tests on generated Java code.
mock_handler_tests - Unit tests on generated Dart mock handler code.
objc_compilation_tests - Compilation tests on generated Objc code.
"
exit 1
;;
\h)
print_usage
exit 1
;;
\?)
print_usage
exit 1
;;
?)
print_usage
exit 1
;;
esac
done
if [ "$should_run_java_compilation_tests" = true ]; then
get_java_linter_formatter
fi
pub get
test_running_without_arguments
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_java_compilation_tests" = true ]; then
run_java_compilation_tests
fi
if [ "$should_run_objc_compilation_tests" = true ]; then
run_objc_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_formatter" = true ]; then
run_formatter
fi