[flutter_tools] refactor iOS tests for Device.startApp into new file (#52854)

This commit is contained in:
Jonah Williams
2020-03-18 17:43:25 -07:00
committed by GitHub
parent 2a93afa7a3
commit 73b6702dee
10 changed files with 473 additions and 454 deletions

View File

@@ -82,39 +82,14 @@ class FakeCommand {
/// resolves.
final Completer<void> completer;
static bool _listEquals<T>(List<T> a, List<T> b) {
if (a == null) {
return b == null;
}
if (b == null || a.length != b.length) {
return false;
}
for (int index = 0; index < a.length; index += 1) {
if (a[index] != b[index]) {
return false;
}
}
return true;
}
bool _matches(List<String> command, String workingDirectory, Map<String, String> environment) {
if (!_listEquals(command, this.command)) {
return false;
}
if (this.workingDirectory != null && workingDirectory != this.workingDirectory) {
return false;
void _matches(List<String> command, String workingDirectory, Map<String, String> environment) {
expect(command, equals(this.command));
if (this.workingDirectory != null) {
expect(this.workingDirectory, workingDirectory);
}
if (this.environment != null) {
if (environment == null) {
return false;
}
for (final String key in environment.keys) {
if (environment[key] != this.environment[key]) {
return false;
}
}
expect(this.environment, environment);
}
return true;
}
}
@@ -322,12 +297,7 @@ class _SequenceProcessManager extends FakeProcessManager {
reason: 'ProcessManager was told to execute $command (in $workingDirectory) '
'but the FakeProcessManager.list expected no more processes.'
);
expect(_commands.first._matches(command, workingDirectory, environment), isTrue,
reason: 'ProcessManager was told to execute $command '
'(in $workingDirectory, with environment $environment) '
'but the next process that was expected was ${_commands.first.command} '
'(in ${_commands.first.workingDirectory}, with environment ${_commands.first.environment})}.'
);
_commands.first._matches(command, workingDirectory, environment);
return _commands.removeAt(0);
}

View File

@@ -0,0 +1,42 @@
// 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 'package:flutter_tools/src/device.dart';
/// A fake implementation of the [DeviceLogReader].
class FakeDeviceLogReader extends DeviceLogReader {
@override
String get name => 'FakeLogReader';
StreamController<String> _cachedLinesController;
final List<String> _lineQueue = <String>[];
StreamController<String> get _linesController {
_cachedLinesController ??= StreamController<String>
.broadcast(onListen: () {
_lineQueue.forEach(_linesController.add);
_lineQueue.clear();
});
return _cachedLinesController;
}
@override
Stream<String> get logLines => _linesController.stream;
void addLine(String line) {
if (_linesController.hasListener) {
_linesController.add(line);
} else {
_lineQueue.add(line);
}
}
@override
Future<void> dispose() async {
_lineQueue.clear();
await _linesController.close();
}
}

View File

@@ -612,40 +612,6 @@ class MockIOSSimulator extends Mock implements IOSSimulator {
bool isSupportedForProject(FlutterProject flutterProject) => true;
}
class MockDeviceLogReader extends DeviceLogReader {
@override
String get name => 'MockLogReader';
StreamController<String> _cachedLinesController;
final List<String> _lineQueue = <String>[];
StreamController<String> get _linesController {
_cachedLinesController ??= StreamController<String>
.broadcast(onListen: () {
_lineQueue.forEach(_linesController.add);
_lineQueue.clear();
});
return _cachedLinesController;
}
@override
Stream<String> get logLines => _linesController.stream;
void addLine(String line) {
if (_linesController.hasListener) {
_linesController.add(line);
} else {
_lineQueue.add(line);
}
}
@override
Future<void> dispose() async {
_lineQueue.clear();
await _linesController.close();
}
}
void applyMocksToCommand(FlutterCommand command) {
command.applicationPackages = MockApplicationPackageStore();
}