Skip to content

Commit

Permalink
Turn on add-to-app iOS platform unit tests (flutter#61007)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmagman authored Jul 9, 2020
1 parent 2a3d3c8 commit 1e510ff
Show file tree
Hide file tree
Showing 64 changed files with 662 additions and 1,610 deletions.
11 changes: 0 additions & 11 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ task:
- name: hostonly_devicelab_tests-3_last-linux
<< : *LINUX_SHARD_TEMPLATE

# TODO(ianh): name: add_to_app_tests-linux

- name: docs-linux # linux-only
only_if: "changesInclude('.cirrus.yml', 'dev/**', 'packages/flutter/**', 'packages/flutter_test/**', 'packages/flutter_drive/**', 'packages/flutter_localizations/**', 'packages/flutter_goldens/**', 'bin/**') || $CIRRUS_PR == ''"
environment:
Expand Down Expand Up @@ -508,8 +506,6 @@ task:
CPU: 4
MEMORY: 6G

# TODO(ianh): name: add_to_app_tests-windows

- name: customer_testing-windows
environment:
# As of December 2019, the customer_testing-windows shard got faster with more CPUs up to 4
Expand Down Expand Up @@ -624,13 +620,6 @@ task:
- name: hostonly_devicelab_tests-3_last-macos
<< : *MACOS_SHARD_TEMPLATE

- name: add_to_app_tests-macos
only_if: "changesInclude('.cirrus.yml', 'dev/**', 'bin/**') || $CIRRUS_PR == ''" # https://github.com/flutter/flutter/issues/41940
skip: true # https://github.com/flutter/flutter/pull/42444
script:
- ulimit -S -n 2048 # https://github.com/flutter/flutter/issues/2976
- dart --enable-asserts dev/bots/test.dart

- name: customer_testing-macos
script:
- ulimit -S -n 2048 # https://github.com/flutter/flutter/issues/2976
Expand Down
12 changes: 0 additions & 12 deletions dev/bots/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ Future<void> main(List<String> args) async {
await _runSmokeTests();
print('═' * 80);
await selectShard(const <String, ShardRunner>{
'add_to_app_tests': _runAddToAppTests,
'add_to_app_life_cycle_tests': _runAddToAppLifeCycleTests,
'build_tests': _runBuildTests,
'firebase_test_lab_tests': _runFirebaseTestLabTests,
Expand Down Expand Up @@ -525,17 +524,6 @@ Future<void> _flutterBuildDart2js(String relativePathToApplication, String targe
);
}

Future<void> _runAddToAppTests() async {
if (Platform.isMacOS) {
print('${green}Running add-to-app iOS integration tests$reset...');
final String addToAppDir = path.join(flutterRoot, 'dev', 'integration_tests', 'ios_add2app');
await runCommand('./build_and_test.sh',
<String>[],
workingDirectory: addToAppDir,
);
}
}

Future<void> _runAddToAppLifeCycleTests() async {
if (Platform.isMacOS) {
print('${green}Running add-to-app life cycle iOS integration tests$reset...');
Expand Down
83 changes: 42 additions & 41 deletions dev/devicelab/bin/tasks/module_test_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:io';

import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/ios.dart';
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;

Expand All @@ -30,6 +31,18 @@ Future<void> main() async {
);
});

// Copy test dart files to new module app.
final Directory flutterModuleLibSource = Directory(path.join(flutterDirectory.path, 'dev', 'integration_tests', 'ios_host_app', 'flutterapp', 'lib'));
final Directory flutterModuleLibDestination = Directory(path.join(projectDir.path, 'lib'));

// These test files don't have a .dart prefix so the analyzer will ignore them. They aren't in a
// package and don't work on their own outside of the test module just created.
final File main = File(path.join(flutterModuleLibSource.path, 'main'));
main.copySync(path.join(flutterModuleLibDestination.path, 'main.dart'));

final File marquee = File(path.join(flutterModuleLibSource.path, 'marquee'));
marquee.copySync(path.join(flutterModuleLibDestination.path, 'marquee.dart'));

section('Build ephemeral host app in release mode without CocoaPods');

await inDirectory(projectDir, () async {
Expand Down Expand Up @@ -181,42 +194,6 @@ Future<void> main() async {
return TaskResult.failure('Building ephemeral host app Podfile.lock does not contain expected pods');
}

section('Clean build');

await inDirectory(projectDir, () async {
await flutter('clean');
});

section('Make iOS host app editable');

await inDirectory(projectDir, () async {
await flutter(
'make-host-app-editable',
options: <String>['ios'],
);
});

section('Build editable host app');

await inDirectory(projectDir, () async {
await flutter(
'build',
options: <String>['ios', '--no-codesign'],
);
});

final bool editableHostAppBuilt = exists(Directory(path.join(
projectDir.path,
'build',
'ios',
'iphoneos',
'Runner.app',
)));

if (!editableHostAppBuilt) {
return TaskResult.failure('Failed to build editable host .app');
}

section('Add to existing iOS Objective-C app');

final Directory objectiveCHostApp = Directory(path.join(tempDir.path, 'hello_host_app'));
Expand Down Expand Up @@ -277,10 +254,34 @@ Future<void> main() async {
);
}

section('Run platform unit tests');
await testWithNewiOSSimulator('TestAdd2AppSim', (String deviceId) =>
inDirectory(objectiveCHostApp, () =>
exec(
'xcodebuild',
<String>[
'-workspace',
'Host.xcworkspace',
'-scheme',
'Host',
'-configuration',
'Debug',
'-destination',
'id=$deviceId',
'test',
'CODE_SIGNING_ALLOWED=NO',
'CODE_SIGNING_REQUIRED=NO',
'CODE_SIGN_IDENTITY=-',
'EXPANDED_CODE_SIGN_IDENTITY=-',
'COMPILER_INDEX_STORE_ENABLE=NO',
],
)
)
);

section('Fail building existing Objective-C iOS app if flutter script fails');
int xcodebuildExitCode = 0;
await inDirectory(objectiveCHostApp, () async {
xcodebuildExitCode = await exec(
final int xcodebuildExitCode = await inDirectory<int>(objectiveCHostApp, () =>
exec(
'xcodebuild',
<String>[
'-workspace',
Expand All @@ -298,8 +299,8 @@ Future<void> main() async {
'COMPILER_INDEX_STORE_ENABLE=NO',
],
canFail: true,
);
});
)
);

if (xcodebuildExitCode != 65) { // 65 returned on PhaseScriptExecution failure.
return TaskResult.failure('Host Objective-C app build succeeded though flutter script failed');
Expand Down
84 changes: 84 additions & 0 deletions dev/devicelab/lib/framework/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'dart:convert';

import 'utils.dart';

typedef SimulatorFunction = Future<void> Function(String deviceId);

void _checkExitCode(int code) {
if (code != 0) {
throw Exception(
Expand Down Expand Up @@ -99,3 +101,85 @@ Future<bool> containsBitcode(String pathToBinary) async {
});
return !emptyBitcodeMarkerFound;
}

/// Creates and boots a new simulator, passes the new simulator's identifier to
/// `testFunction`, then shuts down and deletes simulator.
Future<void> testWithNewiOSSimulator(
String deviceName,
SimulatorFunction testFunction, {
String deviceTypeId = 'com.apple.CoreSimulator.SimDeviceType.iPhone-11',
}) async {
// Xcode 11.4 simctl create makes the runtime argument optional, and defaults to latest.
// TODO(jmagman): Remove runtime parsing when devicelab upgrades to Xcode 11.4 https://github.com/flutter/flutter/issues/54889
final String availableRuntimes = await eval(
'xcrun',
<String>[
'simctl',
'list',
'runtimes',
],
workingDirectory: flutterDirectory.path,
);

String iOSSimRuntime;

final RegExp iOSRuntimePattern = RegExp(r'iOS .*\) - (.*)');

for (final String runtime in LineSplitter.split(availableRuntimes)) {
// These seem to be in order, so allow matching multiple lines so it grabs
// the last (hopefully latest) one.
final RegExpMatch iOSRuntimeMatch = iOSRuntimePattern.firstMatch(runtime);
if (iOSRuntimeMatch != null) {
iOSSimRuntime = iOSRuntimeMatch.group(1).trim();
continue;
}
}
if (iOSSimRuntime == null) {
throw 'No iOS simulator runtime found. Available runtimes:\n$availableRuntimes';
}

final String deviceId = await eval(
'xcrun',
<String>[
'simctl',
'create',
deviceName,
deviceTypeId,
iOSSimRuntime,
],
workingDirectory: flutterDirectory.path,
);
await eval(
'xcrun',
<String>[
'simctl',
'boot',
deviceId,
],
workingDirectory: flutterDirectory.path,
);

await testFunction(deviceId);

if (deviceId != null && deviceId != '') {
await eval(
'xcrun',
<String>[
'simctl',
'shutdown',
deviceId
],
canFail: true,
workingDirectory: flutterDirectory.path,
);
await eval(
'xcrun',
<String>[
'simctl',
'delete',
deviceId],
canFail: true,
workingDirectory: flutterDirectory.path,
);
}
}
69 changes: 0 additions & 69 deletions dev/integration_tests/ios_add2app/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions dev/integration_tests/ios_add2app/Podfile

This file was deleted.

28 changes: 0 additions & 28 deletions dev/integration_tests/ios_add2app/README.md

This file was deleted.

Loading

0 comments on commit 1e510ff

Please sign in to comment.