[pigeon] Enable iOS Swift integration tests (#2858)

* [pigeon] Fix Java integration test script

Fixes a copy/paste error in run_tests.dart that would cause the command
for the new Java integration tests to run the Kotlin tests instead.

* Enable Swift iOS integration tests
This commit is contained in:
stuartmorgan
2022-11-30 07:46:37 -05:00
committed by GitHub
parent d5d3b46f3f
commit bddfe0485a
3 changed files with 61 additions and 22 deletions

View File

@ -6,14 +6,30 @@ import Flutter
import UIKit
/**
* This plugin is currently a no-op since only unit tests have been set up.
* In the future, this will register Pigeon APIs used in integration tests.
* This plugin handles the native side of the integration tests in
* example/integration_test/.
*/
public class TestPlugin: NSObject, FlutterPlugin {
public class TestPlugin: NSObject, FlutterPlugin, AllVoidHostApi, HostEverything {
public static func register(with registrar: FlutterPluginRegistrar) {
let plugin = TestPlugin()
AllVoidHostApiSetup.setUp(binaryMessenger: registrar.messenger(), api: plugin)
HostEverythingSetup.setUp(binaryMessenger: registrar.messenger(), api: plugin)
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
result(FlutterMethodNotImplemented)
// MARK: AllVoidHostApi implementation
func doit() {
// No-op
}
// MARK: HostEverything implementation
func giveMeEverything() -> Everything {
// Currently unused in integration tests, so just return an empty object.
return Everything()
}
func echo(everything: Everything) -> Everything {
return everything
}
}

View File

@ -165,6 +165,10 @@ run_ios_swift_unittests() {
dart run tool/run_tests.dart -t ios_swift_unittests --skip-generation
}
run_ios_swift_e2e_tests() {
dart run tool/run_tests.dart -t ios_swift_integration_tests --skip-generation
}
run_macos_swift_unittests() {
dart run tool/run_tests.dart -t macos_swift_unittests --skip-generation
}
@ -214,7 +218,7 @@ run_ios_unittests() {
popd
}
run_ios_e2e_tests() {
run_ios_e2e_legacy_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"
@ -262,9 +266,13 @@ 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_e2e_legacy_tests=true
should_run_ios_unittests=true
should_run_ios_swift_unittests=true
# Currently these are testing exactly the same thing as macos_swift_e2e_tests,
# so we don't need to run both by default. This should become `true` if any
# iOS-only tests are added (e.g., for a feature not supported by macOS).
should_run_ios_swift_e2e_tests=false
should_run_mock_handler_tests=true
should_run_macos_swift_unittests=true
should_run_macos_swift_e2e_tests=true
@ -280,9 +288,10 @@ while getopts "t:l?h" opt; do
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_e2e_legacy_tests=false
should_run_ios_unittests=false
should_run_ios_swift_unittests=false
should_run_ios_swift_e2e_tests=false
should_run_mock_handler_tests=false
should_run_macos_swift_unittests=false
should_run_macos_swift_e2e_tests=false
@ -296,10 +305,11 @@ while getopts "t:l?h" opt; do
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_e2e_legacy_tests) should_run_ios_e2e_legacy_tests=true ;;
# TODO(stuartmorgan): Rename to include "objc".
ios_unittests) should_run_ios_unittests=true ;;
ios_swift_unittests) should_run_ios_swift_unittests=true ;;
ios_swift_e2e_tests) should_run_ios_swift_e2e_tests=true ;;
mock_handler_tests) should_run_mock_handler_tests=true ;;
macos_swift_unittests) should_run_macos_swift_unittests=true ;;
macos_swift_e2e_tests) should_run_macos_swift_e2e_tests=true ;;
@ -320,9 +330,10 @@ while getopts "t:l?h" opt; do
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_e2e_legacy_tests - Legacy end-to-end Obj-C tests; build-only.
ios_unittests - Unit tests on generated Objc code.
ios_swift_unittests - Unit tests on generated Swift code.
ios_swift_e2e_tests - Integration tests on generated Swift code on iOS.
mock_handler_tests - Unit tests on generated Dart mock handler code.
macos_swift_unittests - Unit tests on generated Swift code on macOS.
macos_swift_e2e_tests - Integration tests on generated Swift code on macOS.
@ -373,8 +384,11 @@ fi
if [ "$should_run_ios_swift_unittests" = true ]; then
run_ios_swift_unittests
fi
if [ "$should_run_ios_e2e_tests" = true ]; then
run_ios_e2e_tests
if [ "$should_run_ios_swift_e2e_tests" = true ]; then
run_ios_swift_e2e_tests
fi
if [ "$should_run_ios_e2e_legacy_tests" = true ]; then
run_ios_e2e_legacy_tests
fi
if [ "$should_run_android_unittests" = true ]; then
run_android_unittests

View File

@ -68,11 +68,14 @@ const Map<String, _TestInfo> _tests = <String, _TestInfo>{
function: _runFlutterUnitTests,
description: 'Unit tests on generated Dart code.'),
'ios_unittests': _TestInfo(
function: _runIosUnitTests,
function: _runIOSUnitTests,
description: 'Unit tests on generated Objective-C code.'),
'ios_swift_unittests': _TestInfo(
function: _runIosSwiftUnitTests,
function: _runIOSSwiftUnitTests,
description: 'Unit tests on generated Swift code.'),
'ios_swift_integration_tests': _TestInfo(
function: _runIOSSwiftIntegrationTests,
description: 'Integration tests on generated Swift code.'),
'macos_swift_unittests': _TestInfo(
function: _runMacOSSwiftUnitTests,
description: 'Unit tests on generated Swift code on macOS.'),
@ -89,7 +92,8 @@ Future<int> _runAndroidJavaUnitTests() async {
}
Future<int> _runAndroidJavaIntegrationTests() async {
return _runAndroidIntegrationTests(_alternateLanguageTestPluginRelativePath);
return _runMobileIntegrationTests(
'Android', _alternateLanguageTestPluginRelativePath);
}
Future<int> _runAndroidKotlinUnitTests() async {
@ -107,14 +111,15 @@ Future<int> _runAndroidKotlinUnitTests() async {
}
Future<int> _runAndroidKotlinIntegrationTests() async {
return _runAndroidIntegrationTests(_testPluginRelativePath);
return _runMobileIntegrationTests('Android', _testPluginRelativePath);
}
Future<int> _runAndroidIntegrationTests(String testPluginPath) async {
final String? device = await getDeviceForPlatform('android');
Future<int> _runMobileIntegrationTests(
String platform, String testPluginPath) async {
final String? device = await getDeviceForPlatform(platform.toLowerCase());
if (device == null) {
print('No Android device available. Attach an Android device or start '
'an emulator to run integration tests');
print('No $platform device available. Attach an $platform device or start '
'an emulator/simulator to run integration tests');
return _noDeviceAvailableExitCode;
}
@ -218,7 +223,7 @@ Future<int> _runFlutterUnitTests() async {
return 0;
}
Future<int> _runIosUnitTests() async {
Future<int> _runIOSUnitTests() async {
throw UnimplementedError('See run_tests.sh.');
}
@ -244,7 +249,7 @@ Future<int> _runMacOSSwiftIntegrationTests() async {
);
}
Future<int> _runIosSwiftUnitTests() async {
Future<int> _runIOSSwiftUnitTests() async {
const String examplePath = './$_testPluginRelativePath/example';
final int compileCode = await runFlutterBuild(
examplePath,
@ -263,6 +268,10 @@ Future<int> _runIosSwiftUnitTests() async {
);
}
Future<int> _runIOSSwiftIntegrationTests() async {
return _runMobileIntegrationTests('iOS', _testPluginRelativePath);
}
Future<int> _runMockHandlerTests() async {
const String unitTestsPath = './mock_handler_tester';
final int generateCode = await runPigeon(