Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dev/automated_tests/flutter_run_test/flutter_run_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';

import 'package:flutter_test/flutter_test.dart';

void main() {
group('example', () {
test('passed', () {
print('This is print');
stderr.writeln('This is writeln');
expect(true, true);
});
test('failed', () {
Expand Down
24 changes: 19 additions & 5 deletions dev/devicelab/bin/tasks/flutter_run_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as path;
Expand All @@ -19,9 +20,10 @@ const Pattern passedMessageMatch = '+0: example passed';
const Pattern failedMessageMatch = '+1: example failed [E]';
const Pattern skippedMessageMatch = '+1 -1: example skipped';
const Pattern finishedMessageMatch = '+1 ~1 -1: Some tests failed.';
const Pattern printMessageMatch = 'This is print';
const Pattern writelnMessageMatch = 'This is writeln';

Future<void> main() async {
deviceOperatingSystem = DeviceOperatingSystem.android;
await task(createFlutterRunTask);
}

Expand All @@ -31,35 +33,47 @@ Future<TaskResult> createFlutterRunTask() async {
bool failedTest = false;
bool skippedTest = false;
bool finishedMessage = false;
bool printMessage = false;
bool writelnMessage = false;
final Device device = await devices.workingDevice;
await device.unlock();
final List<String> options = <String>[
'-t', runTestSource.absolute.path, '-d', device.deviceId,
'-t', runTestSource.absolute.path, '-d', device.deviceId, '-v',
];
await inDirectory<void>(flutterGalleryDir, () async {
startProcess(
final Process run = await startProcess(
path.join(flutterDirectory.path, 'bin', 'flutter'),
flutterCommandArgs('run', options),
environment: null,
);

final Completer<void> finished = Completer<void>();
final StreamSubscription<void> subscription = device.logcat.listen((String line) {
final StreamSubscription<void> subscription = run.stdout
.transform<String>(utf8.decoder)
.transform<String>(const LineSplitter())
.listen((String line) {
print('stdout: $line');
// tests execute in order.
if (line.contains(passedMessageMatch)) {
passedTest = true;
} else if (line.contains(failedMessageMatch)) {
failedTest = true;
} else if (line.contains(skippedMessageMatch)) {
skippedTest = true;
} else if (line.contains(printMessageMatch)) {
printMessage = true;
} else if (line.contains(writelnMessageMatch)) {
writelnMessage = true;
} else if (line.contains(finishedMessageMatch)) {
finishedMessage = true;
finished.complete();
}
});
await finished.future.timeout(const Duration(minutes: 1));
subscription.cancel();
run.kill();
});
return passedTest && failedTest && skippedTest && finishedMessage
return passedTest && failedTest && skippedTest && finishedMessage && printMessage && writelnMessage

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails on stable (neither line is printed).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

? TaskResult.success(<String, dynamic>{})
: TaskResult.failure('Test did not execute as expected.');
}
10 changes: 9 additions & 1 deletion packages/flutter_tools/lib/src/ios/ios_deploy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ class IOSDeployDebugger {
// https://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L51
static final RegExp _lldbRun = RegExp(r'\(lldb\)\s*run');

// (lldb) run
// https://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L51
static final RegExp _lldbProcessExit = RegExp(r'Process \d* exited with status =');

/// Launch the app on the device, and attach the debugger.
///
/// Returns whether or not the debugger successfully attached.
Expand Down Expand Up @@ -306,11 +310,15 @@ class IOSDeployDebugger {
return;
}
if (line.contains('PROCESS_STOPPED') ||
line.contains('PROCESS_EXITED')) {
line.contains('PROCESS_EXITED') ||
_lldbProcessExit.hasMatch(line)) {
// The app exited or crashed, so stop echoing the output.
// Don't pass any further ios-deploy debugging messages to the log reader after it exits.
_debuggerState = _IOSDeployDebuggerState.detached;
_logger.printTrace(line);
if (!debuggerCompleter.isCompleted) {
debuggerCompleter.complete(false);
}
return;
}
if (_debuggerState != _IOSDeployDebuggerState.attached) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ void main () {
'', '']);
});

testWithoutContext('app exit', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['ios-deploy'],
stdout: '(lldb) run\r\nsuccess\r\nLog on attach\r\nProcess 100 exited with status = 0\r\nLog after process exit',
),
]);
final IOSDeployDebugger iosDeployDebugger = IOSDeployDebugger.test(
processManager: processManager,
logger: logger,
);
final List<String> receivedLogLines = <String>[];
final Stream<String> logLines = iosDeployDebugger.logLines
..listen(receivedLogLines.add);

expect(await iosDeployDebugger.launchAndAttach(), isTrue);
await logLines.toList();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could also await logLines.last

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it doesn't like that:

dart:async                                          Stream.last
test/general.shard/ios/ios_deploy_test.dart 117:24  main.<fn>.<fn>.<fn>
===== asynchronous gap ===========================
dart:async                                          _asyncThenWrapperHelper
test/general.shard/ios/ios_deploy_test.dart         main.<fn>.<fn>.<fn>
dart:async                                          runZoned
test/src/common.dart 207:14                         testWithoutContext.<fn>
test/src/common.dart 177:18                         test.<fn>

Bad state: No element

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, because it is empty...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toList seems easier than Listen/onDone

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting the streams to work in these tests was 3x more work than the actual change.

expect(receivedLogLines, <String>['Log on attach']);
});

testWithoutContext('attach failed', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
Expand Down