Unverified Commit 88e6d46d authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

MockProcessManager -> FakeProcessManager (#75544)

parent 8df58eb6
......@@ -33,7 +33,6 @@ import 'package:vm_service/vm_service.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/mocks.dart';
import '../../src/testbed.dart';
void main() {
......@@ -145,7 +144,6 @@ void main() {
MemoryFileSystem fs;
Artifacts artifacts;
MockCache mockCache;
MockProcessManager mockProcessManager;
TestUsage usage;
Directory tempDir;
......@@ -154,7 +152,6 @@ void main() {
mockCache = MockCache();
usage = TestUsage();
fs = MemoryFileSystem.test();
mockProcessManager = MockProcessManager();
tempDir = fs.systemTempDirectory.createTempSync('flutter_run_test.');
fs.currentDirectory = tempDir;
......@@ -201,7 +198,7 @@ void main() {
}, overrides: <Type, Generator>{
DeviceManager: () => mockDeviceManager,
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('fails when targeted device is not Android with --device-user', () async {
......@@ -289,7 +286,7 @@ void main() {
}, overrides: <Type, Generator>{
DeviceManager: () => mockDeviceManager,
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('updates cache before checking for devices', () async {
......@@ -333,7 +330,7 @@ void main() {
Cache: () => mockCache,
DeviceManager: () => mockDeviceManager,
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('passes device target platform to usage', () async {
......@@ -390,7 +387,7 @@ void main() {
Cache: () => mockCache,
DeviceManager: () => mockDeviceManager,
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
ProcessManager: () => FakeProcessManager.any(),
Usage: () => usage,
});
});
......
......@@ -10,17 +10,14 @@ import 'package:flutter_tools/src/android/gradle_errors.dart';
import 'package:flutter_tools/src/android/gradle_utils.dart';
import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/mocks.dart';
void main() {
group('gradleErrors', () {
......@@ -371,7 +368,7 @@ Command: /home/android/gradlew assembleRelease
expect(status, equals(GradleBuildStatus.exit));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => MockProcessManager(),
ProcessManager: () => FakeProcessManager.any(),
Usage: () => testUsage,
});
......@@ -406,7 +403,7 @@ Command: /home/android/gradlew assembleRelease
expect(status, equals(GradleBuildStatus.exit));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => MockProcessManager(),
ProcessManager: () => FakeProcessManager.any(),
Usage: () => testUsage,
});
......@@ -434,7 +431,7 @@ Command: /home/android/gradlew assembleRelease
expect(status, equals(GradleBuildStatus.exit));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => MockProcessManager(),
ProcessManager: () => FakeProcessManager.any(),
Usage: () => testUsage,
});
......@@ -468,7 +465,7 @@ Command: /home/android/gradlew assembleRelease
expect(status, equals(GradleBuildStatus.retryWithAarPlugins));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => MockProcessManager(),
ProcessManager: () => FakeProcessManager.any(),
Usage: () => testUsage,
});
});
......@@ -529,10 +526,10 @@ Command: /home/android/gradlew assembleRelease
});
group('flavor undefined', () {
MockProcessManager mockProcessManager;
FakeProcessManager fakeProcessManager;
setUp(() {
mockProcessManager = MockProcessManager();
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
});
testWithoutContext('pattern', () {
......@@ -563,20 +560,14 @@ Command: /home/android/gradlew assembleRelease
});
testUsingContext('handler - with flavor', () async {
when(mockProcessManager.run(
<String>[
'gradlew',
'app:tasks' ,
'--all',
'--console=auto',
fakeProcessManager.addCommand(const FakeCommand(
command: <String>[
'gradlew',
'app:tasks' ,
'--all',
'--console=auto',
],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) async {
return ProcessResult(
1,
0,
'''
stdout: '''
assembleRelease
assembleFlavor1
assembleFlavor1Release
......@@ -587,9 +578,7 @@ assembleProfile
assembles
assembleFooTest
''',
'',
);
});
));
await flavorUndefinedHandler.handler(
project: FlutterProject.current(),
......@@ -610,35 +599,28 @@ assembleFooTest
'You must specify a --flavor option to select one of them.'
)
);
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
GradleUtils: () => FakeGradleUtils(),
Platform: () => fakePlatform('android'),
ProcessManager: () => mockProcessManager,
ProcessManager: () => fakeProcessManager,
FileSystem: () => MemoryFileSystem.test(),
});
testUsingContext('handler - without flavor', () async {
when(mockProcessManager.run(
<String>[
fakeProcessManager.addCommand(const FakeCommand(
command: <String>[
'gradlew',
'app:tasks' ,
'--all',
'--console=auto',
],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) async {
return ProcessResult(
1,
0,
'''
stdout: '''
assembleRelease
assembleDebug
assembleProfile
''',
'',
);
});
));
await flavorUndefinedHandler.handler(
project: FlutterProject.current(),
......@@ -658,10 +640,11 @@ assembleProfile
'You cannot use the --flavor option.'
)
);
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
GradleUtils: () => FakeGradleUtils(),
Platform: () => fakePlatform('android'),
ProcessManager: () => mockProcessManager,
ProcessManager: () => fakeProcessManager,
FileSystem: () => MemoryFileSystem.test(),
});
});
......
......@@ -8,7 +8,6 @@ import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart' show ProcessResult;
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/process.dart';
......@@ -18,7 +17,6 @@ import 'package:flutter_tools/src/ios/mac.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -29,7 +27,6 @@ final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
Platform: _kNoColorTerminalPlatform,
};
class MockProcessManager extends Mock implements ProcessManager {}
class MockIosProject extends Mock implements IosProject {}
void main() {
......@@ -52,25 +49,33 @@ void main() {
});
group('screenshot', () {
MockProcessManager mockProcessManager;
FakeProcessManager fakeProcessManager;
File outputFile;
setUp(() {
mockProcessManager = MockProcessManager();
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
outputFile = MemoryFileSystem.test().file('image.png');
});
testWithoutContext('error if idevicescreenshot is not installed', () async {
// Let `idevicescreenshot` fail with exit code 1.
when(mockProcessManager.run(<String>['Artifact.idevicescreenshot.TargetPlatform.ios', outputFile.path],
environment: <String, String>{'DYLD_LIBRARY_PATH': 'Artifact.idevicescreenshot.TargetPlatform.ios'},
workingDirectory: null,
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(4, 1, '', '')));
fakeProcessManager.addCommand(FakeCommand(
command: <String>[
'Artifact.idevicescreenshot.TargetPlatform.ios',
outputFile.path,
'--udid',
'1234',
],
environment: const <String, String>{
'DYLD_LIBRARY_PATH': '/path/to/libraries',
},
exitCode: 1,
));
final IMobileDevice iMobileDevice = IMobileDevice(
artifacts: artifacts,
cache: cache,
processManager: mockProcessManager,
processManager: fakeProcessManager,
logger: logger,
);
......@@ -79,16 +84,21 @@ void main() {
'1234',
IOSDeviceInterface.usb,
), throwsA(anything));
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
});
testWithoutContext('idevicescreenshot captures and returns USB screenshot', () async {
when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer(
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', '')));
fakeProcessManager.addCommand(FakeCommand(
command: <String>[
'Artifact.idevicescreenshot.TargetPlatform.ios', outputFile.path, '--udid', '1234',
],
environment: const <String, String>{'DYLD_LIBRARY_PATH': '/path/to/libraries'},
));
final IMobileDevice iMobileDevice = IMobileDevice(
artifacts: artifacts,
cache: cache,
processManager: mockProcessManager,
processManager: fakeProcessManager,
logger: logger,
);
......@@ -97,20 +107,21 @@ void main() {
'1234',
IOSDeviceInterface.usb,
);
verify(mockProcessManager.run(<String>['Artifact.idevicescreenshot.TargetPlatform.ios', outputFile.path, '--udid', '1234'],
environment: <String, String>{'DYLD_LIBRARY_PATH': '/path/to/libraries'},
workingDirectory: null,
));
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
});
testWithoutContext('idevicescreenshot captures and returns network screenshot', () async {
when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer(
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', '')));
fakeProcessManager.addCommand(FakeCommand(
command: <String>[
'Artifact.idevicescreenshot.TargetPlatform.ios', outputFile.path, '--udid', '1234', '--network',
],
environment: const <String, String>{'DYLD_LIBRARY_PATH': '/path/to/libraries'},
));
final IMobileDevice iMobileDevice = IMobileDevice(
artifacts: artifacts,
cache: cache,
processManager: mockProcessManager,
processManager: fakeProcessManager,
logger: logger,
);
......@@ -119,10 +130,7 @@ void main() {
'1234',
IOSDeviceInterface.network,
);
verify(mockProcessManager.run(<String>['Artifact.idevicescreenshot.TargetPlatform.ios', outputFile.path, '--udid', '1234', '--network'],
environment: <String, String>{'DYLD_LIBRARY_PATH': '/path/to/libraries'},
workingDirectory: null,
));
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
});
});
});
......
......@@ -20,7 +20,6 @@ import 'package:process/process.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/mocks.dart';
void main() {
MemoryFileSystem fileSystem;
......@@ -79,23 +78,20 @@ void main() {
List<String> logLines;
String mainPath;
MockProcessManager mockProcessManager;
MockProcess mockProcess;
FakeProcessManager fakeProcessManager;
MockBuildSystem mockBuildSystem;
final Map<Type, Generator> startOverrides = <Type, Generator>{
Platform: () => FakePlatform(operatingSystem: 'linux'),
FileSystem: () => fileSystem,
ProcessManager: () => mockProcessManager,
ProcessManager: () => fakeProcessManager,
Artifacts: () => Artifacts.test(),
BuildSystem: () => mockBuildSystem,
};
setUp(() {
mockBuildSystem = MockBuildSystem();
mockProcessManager = MockProcessManager();
mockProcessManager.processFactory =
(List<String> commands) => mockProcess;
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
when(mockBuildSystem.build(
any,
......@@ -105,7 +101,7 @@ void main() {
});
device = FlutterTesterDevice('flutter-tester',
fileSystem: fileSystem,
processManager: mockProcessManager,
processManager: fakeProcessManager,
artifacts: Artifacts.test(),
buildDirectory: 'build',
logger: BufferLogger.test(),
......@@ -149,17 +145,27 @@ void main() {
expect(jitReleaseResult.started, isFalse);
});
testUsingContext('performs a build and starts in debug mode', () async {
final FlutterTesterApp app = FlutterTesterApp.fromCurrentDirectory(fileSystem);
final Uri observatoryUri = Uri.parse('http://127.0.0.1:6666/');
mockProcess = MockProcess(stdout: Stream<List<int>>.fromIterable(<List<int>>[
final String assetsPath = fileSystem.path.join('build', 'flutter_assets');
final String dillPath = fileSystem.path.join('build', 'flutter-tester-app.dill');
fakeProcessManager.addCommand(FakeCommand(
command: <String>[
'Artifact.flutterTester',
'--run-forever',
'--non-interactive',
'--enable-dart-profiling',
'--packages=.packages',
'--flutter-assets-dir=$assetsPath',
dillPath,
],
stdout:
'''
Observatory listening on $observatoryUri
Hello!
'''
.codeUnits,
]));
''',
));
final LaunchResult result = await device.startApp(app,
mainPath: mainPath,
......@@ -169,6 +175,7 @@ Hello!
expect(result.started, isTrue);
expect(result.observatoryUri, observatoryUri);
expect(logLines.last, 'Hello!');
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: startOverrides);
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment