mirror of
https://github.com/flutter/flutter.git
synced 2026-02-10 21:07:38 +08:00
The previous integration test only tested one workflow, so I re-designed the test to be able to test both workflows and validate the correct commands are being used. Follow up to https://github.com/flutter/flutter/pull/173443. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
157 lines
4.6 KiB
Dart
157 lines
4.6 KiB
Dart
// Copyright 2014 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.
|
|
|
|
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter_devicelab/framework/devices.dart';
|
|
import 'package:flutter_devicelab/framework/framework.dart';
|
|
import 'package:flutter_devicelab/framework/task_result.dart';
|
|
import 'package:flutter_devicelab/framework/utils.dart';
|
|
import 'package:path/path.dart' as path;
|
|
|
|
/// This is a test to validate that Xcode debugging still works now that LLDB is the default.
|
|
Future<void> main() async {
|
|
await task(() async {
|
|
deviceOperatingSystem = DeviceOperatingSystem.ios;
|
|
return createIosWorkflowTest()();
|
|
});
|
|
}
|
|
|
|
Future<void> enableLLDBDebugging() async {
|
|
final int configResult = await exec(path.join(flutterDirectory.path, 'bin', 'flutter'), <String>[
|
|
'config',
|
|
'--enable-lldb-debugging',
|
|
], canFail: true);
|
|
if (configResult != 0) {
|
|
print('Failed to enable configuration.');
|
|
}
|
|
}
|
|
|
|
TaskFunction createIosWorkflowTest({String? deviceIdOverride}) {
|
|
return () async {
|
|
// Create project
|
|
const String appName = 'ios_workflow_test';
|
|
final Directory tempDirectory = dir(Directory.systemTemp.createTempSync().path);
|
|
await exec(_flutterBin, <String>[
|
|
'create',
|
|
'--no-pub',
|
|
appName,
|
|
], workingDirectory: tempDirectory.path);
|
|
|
|
final Directory appDirectory = dir(path.join(tempDirectory.path, appName));
|
|
|
|
// Select device
|
|
if (deviceIdOverride == null) {
|
|
final Device device = await devices.workingDevice;
|
|
await device.unlock();
|
|
deviceIdOverride = device.deviceId;
|
|
}
|
|
|
|
// Test LLDB workflow
|
|
await enableLLDBDebugging();
|
|
final TaskResult lldbResult = await _validateWorkflow(
|
|
workflow: IosDebugWorkflow.lldb,
|
|
deviceId: deviceIdOverride!,
|
|
appDirectoryPath: appDirectory.path,
|
|
);
|
|
if (lldbResult.failed) {
|
|
return lldbResult;
|
|
}
|
|
|
|
// TODO(vashworth): Also test Xcode workflow once
|
|
// https://github.com/flutter/flutter/issues/173573 is fixed.
|
|
|
|
return TaskResult.success(null);
|
|
};
|
|
}
|
|
|
|
Future<TaskResult> _validateWorkflow({
|
|
required IosDebugWorkflow workflow,
|
|
required String deviceId,
|
|
required String appDirectoryPath,
|
|
}) async {
|
|
final List<String> options = <String>[
|
|
'--no-android-gradle-daemon',
|
|
'--verbose',
|
|
'--debug',
|
|
'--no-publish-port',
|
|
'-d',
|
|
deviceId,
|
|
];
|
|
final Process process = await startFlutter(
|
|
'run',
|
|
options: options,
|
|
workingDirectory: appDirectoryPath,
|
|
);
|
|
|
|
Pattern expectedLog;
|
|
Pattern unexpectedLog;
|
|
const Pattern xcodeExpectedLog = 'Action result status: not yet started';
|
|
final Pattern lldbExpectedLog = RegExp(r'Process .* resuming');
|
|
switch (workflow) {
|
|
case IosDebugWorkflow.xcode:
|
|
expectedLog = xcodeExpectedLog;
|
|
unexpectedLog = lldbExpectedLog;
|
|
case IosDebugWorkflow.lldb:
|
|
expectedLog = lldbExpectedLog;
|
|
unexpectedLog = xcodeExpectedLog;
|
|
}
|
|
|
|
// TODO(vashworth): Update to verify app launched all the way once
|
|
// https://github.com/flutter/flutter/issues/173365 is fixed.
|
|
final Pattern finishPattern = RegExp(
|
|
'Application launched on the device. Waiting for Dart VM Service url.',
|
|
);
|
|
|
|
String? foundUnexpectedLog;
|
|
String? foundExpectedLog;
|
|
|
|
final StreamSubscription<String> stdoutSubscription = process.stdout
|
|
.transform<String>(utf8.decoder)
|
|
.transform<String>(const LineSplitter())
|
|
.listen((String line) {
|
|
print('stdout: $line');
|
|
if (line.contains(finishPattern)) {
|
|
process.kill();
|
|
}
|
|
|
|
if (line.contains(expectedLog)) {
|
|
foundExpectedLog = line;
|
|
}
|
|
|
|
if (line.contains(unexpectedLog)) {
|
|
foundUnexpectedLog = line;
|
|
}
|
|
});
|
|
|
|
final StreamSubscription<String> stderrSubscription = process.stderr
|
|
.transform<String>(utf8.decoder)
|
|
.transform<String>(const LineSplitter())
|
|
.listen((String line) => print('stderr: $line'));
|
|
|
|
final int runFlutterResult = await process.exitCode.whenComplete(() {
|
|
stdoutSubscription.cancel();
|
|
stderrSubscription.cancel();
|
|
});
|
|
if (runFlutterResult != 0) {
|
|
print('Flutter run returned non-zero exit code: $runFlutterResult.');
|
|
return TaskResult.failure('failed');
|
|
}
|
|
|
|
if (foundUnexpectedLog != null) {
|
|
return TaskResult.failure('Unexpected logs found: $foundUnexpectedLog');
|
|
}
|
|
if (foundExpectedLog == null) {
|
|
return TaskResult.failure('Expected logs not found.');
|
|
}
|
|
|
|
return TaskResult.success(null);
|
|
}
|
|
|
|
enum IosDebugWorkflow { xcode, lldb }
|
|
|
|
final String _flutterBin = path.join(flutterDirectory.path, 'bin', 'flutter');
|