mirror of
https://github.com/flutter/flutter
synced 2024-10-13 03:32:55 +00:00
MockProcessManager -> FakeProcessManager in os_test (#76264)
This commit is contained in:
parent
d65c98b4a2
commit
90531179f5
|
@ -12,8 +12,6 @@ import 'package:flutter_tools/src/base/logger.dart';
|
|||
import 'package:flutter_tools/src/base/os.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
@ -23,11 +21,9 @@ const String kPath1 = '/bar/bin/$kExecutable';
|
|||
const String kPath2 = '/another/bin/$kExecutable';
|
||||
|
||||
void main() {
|
||||
MockProcessManager mockProcessManager;
|
||||
FakeProcessManager fakeProcessManager;
|
||||
|
||||
setUp(() {
|
||||
mockProcessManager = MockProcessManager();
|
||||
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
|
||||
});
|
||||
|
||||
|
@ -90,13 +86,21 @@ void main() {
|
|||
|
||||
group('which on Windows', () {
|
||||
testWithoutContext('throws tool exit if where throws an argument error', () async {
|
||||
when(mockProcessManager.runSync(<String>['where', kExecutable]))
|
||||
.thenThrow(ArgumentError('Cannot find executable for where'));
|
||||
fakeProcessManager.addCommand(
|
||||
FakeCommand(
|
||||
command: const <String>[
|
||||
'where',
|
||||
kExecutable,
|
||||
],
|
||||
exception: ArgumentError('Cannot find executable for where'),
|
||||
),
|
||||
);
|
||||
|
||||
final OperatingSystemUtils utils = OperatingSystemUtils(
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
logger: BufferLogger.test(),
|
||||
platform: FakePlatform(operatingSystem: 'windows'),
|
||||
processManager: mockProcessManager,
|
||||
processManager: fakeProcessManager,
|
||||
);
|
||||
|
||||
expect(() => utils.which(kExecutable), throwsA(isA<ToolExit>()));
|
||||
|
@ -416,17 +420,23 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
testWithoutContext('If unzip throws an ArgumentError, display an install message', () {
|
||||
group('display an install message when unzip throws an ArgumentError', () {
|
||||
testWithoutContext('Linux', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
when(mockProcessManager.runSync(
|
||||
<String>['unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path],
|
||||
)).thenThrow(ArgumentError());
|
||||
fakeProcessManager.addCommand(
|
||||
FakeCommand(
|
||||
command: <String>[
|
||||
'unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path,
|
||||
],
|
||||
exception: ArgumentError(),
|
||||
),
|
||||
);
|
||||
|
||||
final OperatingSystemUtils linuxOsUtils = OperatingSystemUtils(
|
||||
fileSystem: fileSystem,
|
||||
logger: BufferLogger.test(),
|
||||
platform: FakePlatform(operatingSystem: 'linux'),
|
||||
processManager: mockProcessManager,
|
||||
processManager: fakeProcessManager,
|
||||
);
|
||||
|
||||
expect(
|
||||
|
@ -435,12 +445,24 @@ void main() {
|
|||
message: 'Missing "unzip" tool. Unable to extract foo.zip.\n'
|
||||
'Consider running "sudo apt-get install unzip".'),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('macOS', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
fakeProcessManager.addCommand(
|
||||
FakeCommand(
|
||||
command: <String>[
|
||||
'unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path,
|
||||
],
|
||||
exception: ArgumentError(),
|
||||
),
|
||||
);
|
||||
|
||||
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
|
||||
fileSystem: fileSystem,
|
||||
logger: BufferLogger.test(),
|
||||
platform: FakePlatform(operatingSystem: 'macos'),
|
||||
processManager: mockProcessManager,
|
||||
processManager: fakeProcessManager,
|
||||
);
|
||||
|
||||
expect(
|
||||
|
@ -449,12 +471,24 @@ void main() {
|
|||
(message: 'Missing "unzip" tool. Unable to extract foo.zip.\n'
|
||||
'Consider running "brew install unzip".'),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('unknown OS', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
fakeProcessManager.addCommand(
|
||||
FakeCommand(
|
||||
command: <String>[
|
||||
'unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path,
|
||||
],
|
||||
exception: ArgumentError(),
|
||||
),
|
||||
);
|
||||
|
||||
final OperatingSystemUtils unknownOsUtils = OperatingSystemUtils(
|
||||
fileSystem: fileSystem,
|
||||
logger: BufferLogger.test(),
|
||||
platform: FakePlatform(operatingSystem: 'fuchsia'),
|
||||
processManager: mockProcessManager,
|
||||
processManager: fakeProcessManager,
|
||||
);
|
||||
|
||||
expect(
|
||||
|
@ -464,10 +498,9 @@ void main() {
|
|||
'Please install unzip.'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testWithoutContext('stream compression level', () {
|
||||
expect(OperatingSystemUtils.gzipLevel1.level, equals(1));
|
||||
});
|
||||
}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
|
|
Loading…
Reference in a new issue