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