Unverified Commit 1ad6edb8 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove MockProcessManager from channel_test and other tests (#74780)

parent 675fd554
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:convert'; import 'dart:convert';
import 'dart:io';
import 'package:flutter_tools/src/android/android_sdk.dart'; import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/artifacts.dart';
...@@ -11,7 +10,6 @@ import 'package:flutter_tools/src/cache.dart'; ...@@ -11,7 +10,6 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/devices.dart'; import 'package:flutter_tools/src/commands/devices.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:mockito/mockito.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import '../../src/common.dart'; import '../../src/common.dart';
...@@ -45,7 +43,7 @@ void main() { ...@@ -45,7 +43,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => null, AndroidSdk: () => null,
DeviceManager: () => NoDevicesManager(), DeviceManager: () => NoDevicesManager(),
ProcessManager: () => MockProcessManager(), ProcessManager: () => FakeProcessManager.any(),
Cache: () => cache, Cache: () => cache,
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
}); });
...@@ -57,7 +55,7 @@ void main() { ...@@ -57,7 +55,7 @@ void main() {
expect(platformTypes, <String>['android', 'web']); expect(platformTypes, <String>['android', 'web']);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
DeviceManager: () => _FakeDeviceManager(), DeviceManager: () => _FakeDeviceManager(),
ProcessManager: () => MockProcessManager(), ProcessManager: () => FakeProcessManager.any(),
Cache: () => cache, Cache: () => cache,
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
}); });
...@@ -106,7 +104,7 @@ void main() { ...@@ -106,7 +104,7 @@ void main() {
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
DeviceManager: () => _FakeDeviceManager(), DeviceManager: () => _FakeDeviceManager(),
ProcessManager: () => MockProcessManager(), ProcessManager: () => FakeProcessManager.any(),
Cache: () => cache, Cache: () => cache,
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
}); });
...@@ -127,39 +125,11 @@ webby (mobile) • webby • web-javascript • Web SDK (1.2.4) (emulato ...@@ -127,39 +125,11 @@ webby (mobile) • webby • web-javascript • Web SDK (1.2.4) (emulato
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
DeviceManager: () => _FakeDeviceManager(), DeviceManager: () => _FakeDeviceManager(),
ProcessManager: () => MockProcessManager(), ProcessManager: () => FakeProcessManager.any(),
}); });
}); });
} }
class MockProcessManager extends Mock implements ProcessManager {
@override
Future<ProcessResult> run(
List<dynamic> command, {
String workingDirectory,
Map<String, String> environment,
bool includeParentEnvironment = true,
bool runInShell = false,
Encoding stdoutEncoding = systemEncoding,
Encoding stderrEncoding = systemEncoding,
}) async {
return ProcessResult(0, 0, '', '');
}
@override
ProcessResult runSync(
List<dynamic> command, {
String workingDirectory,
Map<String, String> environment,
bool includeParentEnvironment = true,
bool runInShell = false,
Encoding stdoutEncoding = systemEncoding,
Encoding stderrEncoding = systemEncoding,
}) {
return ProcessResult(0, 0, '', '');
}
}
class _FakeDeviceManager extends DeviceManager { class _FakeDeviceManager extends DeviceManager {
_FakeDeviceManager(); _FakeDeviceManager();
......
...@@ -12,7 +12,6 @@ import 'package:flutter_tools/src/base/platform.dart'; ...@@ -12,7 +12,6 @@ import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/user_messages.dart'; import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/doctor.dart'; import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:mockito/mockito.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import '../../src/common.dart'; import '../../src/common.dart';
...@@ -27,9 +26,11 @@ final Platform linuxPlatform = FakePlatform( ...@@ -27,9 +26,11 @@ final Platform linuxPlatform = FakePlatform(
void main() { void main() {
FileSystem fileSystem; FileSystem fileSystem;
FakeProcessManager fakeProcessManager;
setUp(() { setUp(() {
fileSystem = MemoryFileSystem.test(); fileSystem = MemoryFileSystem.test();
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
}); });
testWithoutContext('NoAndroidStudioValidator shows Android Studio as "not available" when not available.', () async { testWithoutContext('NoAndroidStudioValidator shows Android Studio as "not available" when not available.', () async {
...@@ -48,10 +49,15 @@ void main() { ...@@ -48,10 +49,15 @@ void main() {
}); });
testUsingContext('AndroidStudioValidator gives doctor error on java crash', () async { testUsingContext('AndroidStudioValidator gives doctor error on java crash', () async {
when(globals.processManager.canRun(any)).thenReturn(true); fakeProcessManager.addCommand(FakeCommand(
when(globals.processManager.runSync(any)).thenAnswer((Invocation _) { command: const <String>[
throw const ProcessException('java', <String>['--version']); '/opt/android-studio-with-cheese-5.0/jre/bin/java',
}); '-version',
],
onRun: () {
throw const ProcessException('java', <String>['-version']);
},
));
const String installPath = '/opt/android-studio-with-cheese-5.0'; const String installPath = '/opt/android-studio-with-cheese-5.0';
const String studioHome = '$home/.AndroidStudioWithCheese5.0'; const String studioHome = '$home/.AndroidStudioWithCheese5.0';
const String homeFile = '$studioHome/system/.home'; const String homeFile = '$studioHome/system/.home';
...@@ -68,9 +74,10 @@ void main() { ...@@ -68,9 +74,10 @@ void main() {
return message.isError && message.message.contains('ProcessException'); return message.isError && message.message.contains('ProcessException');
}).isNotEmpty, true); }).isNotEmpty, true);
} }
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
ProcessManager: () => MockProcessManager(), ProcessManager: () => fakeProcessManager,
Platform: () => linuxPlatform, Platform: () => linuxPlatform,
FileSystemUtils: () => FileSystemUtils( FileSystemUtils: () => FileSystemUtils(
fileSystem: fileSystem, fileSystem: fileSystem,
...@@ -78,5 +85,3 @@ void main() { ...@@ -78,5 +85,3 @@ void main() {
), ),
}); });
} }
class MockProcessManager extends Mock implements ProcessManager {}
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:io' hide File;
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
...@@ -11,16 +9,18 @@ import 'package:flutter_tools/src/cache.dart'; ...@@ -11,16 +9,18 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/commands/channel.dart'; import 'package:flutter_tools/src/commands/channel.dart';
import 'package:flutter_tools/src/version.dart'; import 'package:flutter_tools/src/version.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('channel', () { group('channel', () {
final MockProcessManager mockProcessManager = MockProcessManager(); FakeProcessManager fakeProcessManager;
setUp(() {
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
});
setUpAll(() { setUpAll(() {
Cache.disableLocking(); Cache.disableLocking();
...@@ -49,38 +49,21 @@ void main() { ...@@ -49,38 +49,21 @@ void main() {
}); });
testUsingContext('sorted by stability', () async { testUsingContext('sorted by stability', () async {
final Process processAll = createMockProcess(
stdout: 'origin/beta\n'
'origin/master\n'
'origin/dev\n'
'origin/stable\n');
final Process processWithExtra = createMockProcess(
stdout: 'origin/beta\n'
'origin/master\n'
'origin/dependabot/bundler\n'
'origin/dev\n'
'origin/v1.4.5-hotfixes\n'
'origin/stable\n');
final Process processWithMissing = createMockProcess(
stdout: 'origin/beta\n'
'origin/dependabot/bundler\n'
'origin/v1.4.5-hotfixes\n'
'origin/stable\n');
final ChannelCommand command = ChannelCommand(); final ChannelCommand command = ChannelCommand();
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
when(mockProcessManager.start( fakeProcessManager.addCommand(
<String>['git', 'branch', '-r'], const FakeCommand(
workingDirectory: anyNamed('workingDirectory'), command: <String>['git', 'branch', '-r'],
environment: anyNamed('environment'), stdout: 'origin/beta\n'
)).thenAnswer((_) => Future<Process>.value(processAll)); 'origin/master\n'
'origin/dev\n'
'origin/stable\n',
),
);
await runner.run(<String>['channel']); await runner.run(<String>['channel']);
verify(mockProcessManager.start( expect(fakeProcessManager.hasRemainingExpectations, isFalse);
<String>['git', 'branch', '-r'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
expect(testLogger.errorText, hasLength(0)); expect(testLogger.errorText, hasLength(0));
// format the status text for a simpler assertion. // format the status text for a simpler assertion.
final Iterable<String> rows = testLogger.statusText final Iterable<String> rows = testLogger.statusText
...@@ -91,17 +74,22 @@ void main() { ...@@ -91,17 +74,22 @@ void main() {
// clear buffer for next process // clear buffer for next process
testLogger.clear(); testLogger.clear();
when(mockProcessManager.start( // Extra branches.
<String>['git', 'branch', '-r'], fakeProcessManager.addCommand(
workingDirectory: anyNamed('workingDirectory'), const FakeCommand(
environment: anyNamed('environment'), command: <String>['git', 'branch', '-r'],
)).thenAnswer((_) => Future<Process>.value(processWithExtra)); stdout: 'origin/beta\n'
'origin/master\n'
'origin/dependabot/bundler\n'
'origin/dev\n'
'origin/v1.4.5-hotfixes\n'
'origin/stable\n',
),
);
await runner.run(<String>['channel']); await runner.run(<String>['channel']);
verify(mockProcessManager.start( expect(fakeProcessManager.hasRemainingExpectations, isFalse);
<String>['git', 'branch', '-r'], expect(rows, containsAllInOrder(kOfficialChannels));
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
expect(testLogger.errorText, hasLength(0)); expect(testLogger.errorText, hasLength(0));
// format the status text for a simpler assertion. // format the status text for a simpler assertion.
final Iterable<String> rows2 = testLogger.statusText final Iterable<String> rows2 = testLogger.statusText
...@@ -112,17 +100,19 @@ void main() { ...@@ -112,17 +100,19 @@ void main() {
// clear buffer for next process // clear buffer for next process
testLogger.clear(); testLogger.clear();
when(mockProcessManager.start( // Missing branches.
<String>['git', 'branch', '-r'], fakeProcessManager.addCommand(
workingDirectory: anyNamed('workingDirectory'), const FakeCommand(
environment: anyNamed('environment'), command: <String>['git', 'branch', '-r'],
)).thenAnswer((_) => Future<Process>.value(processWithMissing)); stdout: 'origin/beta\n'
'origin/dependabot/bundler\n'
'origin/v1.4.5-hotfixes\n'
'origin/stable\n',
),
);
await runner.run(<String>['channel']); await runner.run(<String>['channel']);
verify(mockProcessManager.start( expect(fakeProcessManager.hasRemainingExpectations, isFalse);
<String>['git', 'branch', '-r'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
expect(testLogger.errorText, hasLength(0)); expect(testLogger.errorText, hasLength(0));
// check if available official channels are in order of stability // check if available official channels are in order of stability
int prev = -1; int prev = -1;
...@@ -136,33 +126,28 @@ void main() { ...@@ -136,33 +126,28 @@ void main() {
} }
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager, ProcessManager: () => fakeProcessManager,
FileSystem: () => MemoryFileSystem.test(),
}); });
testUsingContext('removes duplicates', () async { testUsingContext('removes duplicates', () async {
final Process process = createMockProcess( fakeProcessManager.addCommand(
const FakeCommand(
command: <String>['git', 'branch', '-r'],
stdout: 'origin/dev\n' stdout: 'origin/dev\n'
'origin/beta\n' 'origin/beta\n'
'origin/stable\n' 'origin/stable\n'
'upstream/dev\n' 'upstream/dev\n'
'upstream/beta\n' 'upstream/beta\n'
'upstream/stable\n'); 'upstream/stable\n',
when(mockProcessManager.start( ),
<String>['git', 'branch', '-r'], );
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) => Future<Process>.value(process));
final ChannelCommand command = ChannelCommand(); final ChannelCommand command = ChannelCommand();
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['channel']); await runner.run(<String>['channel']);
verify(mockProcessManager.start( expect(fakeProcessManager.hasRemainingExpectations, isFalse);
<String>['git', 'branch', '-r'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
expect(testLogger.errorText, hasLength(0)); expect(testLogger.errorText, hasLength(0));
// format the status text for a simpler assertion. // format the status text for a simpler assertion.
...@@ -174,127 +159,71 @@ void main() { ...@@ -174,127 +159,71 @@ void main() {
expect(rows, <String>['dev', 'beta', 'stable']); expect(rows, <String>['dev', 'beta', 'stable']);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager, ProcessManager: () => fakeProcessManager,
FileSystem: () => MemoryFileSystem.test(),
}); });
testUsingContext('can switch channels', () async { testUsingContext('can switch channels', () async {
when(mockProcessManager.start( fakeProcessManager.addCommands(<FakeCommand>[
<String>['git', 'fetch'], const FakeCommand(
workingDirectory: anyNamed('workingDirectory'), command: <String>['git', 'fetch'],
environment: anyNamed('environment'), ),
)).thenAnswer((_) => Future<Process>.value(createMockProcess())); const FakeCommand(
when(mockProcessManager.start( command: <String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/beta'],
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/beta'], ),
workingDirectory: anyNamed('workingDirectory'), const FakeCommand(
environment: anyNamed('environment'), command: <String>['git', 'checkout', 'beta', '--']
)).thenAnswer((_) => Future<Process>.value(createMockProcess())); ),
when(mockProcessManager.start( ]);
<String>['git', 'checkout', 'beta', '--'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) => Future<Process>.value(createMockProcess()));
final ChannelCommand command = ChannelCommand(); final ChannelCommand command = ChannelCommand();
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['channel', 'beta']); await runner.run(<String>['channel', 'beta']);
verify(mockProcessManager.start( expect(fakeProcessManager.hasRemainingExpectations, isFalse);
<String>['git', 'fetch'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
verify(mockProcessManager.start(
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/beta'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
verify(mockProcessManager.start(
<String>['git', 'checkout', 'beta', '--'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
expect( expect(
testLogger.statusText, testLogger.statusText,
containsIgnoringWhitespace("Switching to flutter channel 'beta'..."), containsIgnoringWhitespace("Switching to flutter channel 'beta'..."),
); );
expect(testLogger.errorText, hasLength(0)); expect(testLogger.errorText, hasLength(0));
when(mockProcessManager.start( fakeProcessManager.addCommands(<FakeCommand>[
<String>['git', 'fetch'], const FakeCommand(
workingDirectory: anyNamed('workingDirectory'), command: <String>['git', 'fetch'],
environment: anyNamed('environment'), ),
)).thenAnswer((_) => Future<Process>.value(createMockProcess())); const FakeCommand(
when(mockProcessManager.start( command: <String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/stable'],
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/stable'], ),
workingDirectory: anyNamed('workingDirectory'), const FakeCommand(
environment: anyNamed('environment'), command: <String>['git', 'checkout', 'stable', '--']
)).thenAnswer((_) => Future<Process>.value(createMockProcess())); ),
when(mockProcessManager.start( ]);
<String>['git', 'checkout', 'stable', '--'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) => Future<Process>.value(createMockProcess()));
await runner.run(<String>['channel', 'stable']); await runner.run(<String>['channel', 'stable']);
verify(mockProcessManager.start( expect(fakeProcessManager.hasRemainingExpectations, isFalse);
<String>['git', 'fetch'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
verify(mockProcessManager.start(
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/stable'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
verify(mockProcessManager.start(
<String>['git', 'checkout', 'stable', '--'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(), FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => mockProcessManager, ProcessManager: () => fakeProcessManager,
}); });
testUsingContext('switching channels prompts to run flutter upgrade', () async { testUsingContext('switching channels prompts to run flutter upgrade', () async {
when(mockProcessManager.start( fakeProcessManager.addCommands(<FakeCommand>[
<String>['git', 'fetch'], const FakeCommand(
workingDirectory: anyNamed('workingDirectory'), command: <String>['git', 'fetch'],
environment: anyNamed('environment'), ),
)).thenAnswer((_) => Future<Process>.value(createMockProcess())); const FakeCommand(
when(mockProcessManager.start( command: <String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/beta'],
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/beta'], ),
workingDirectory: anyNamed('workingDirectory'), const FakeCommand(
environment: anyNamed('environment'), command: <String>['git', 'checkout', 'beta', '--']
)).thenAnswer((_) => Future<Process>.value(createMockProcess())); ),
when(mockProcessManager.start( ]);
<String>['git', 'checkout', 'beta', '--'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) => Future<Process>.value(createMockProcess()));
final ChannelCommand command = ChannelCommand(); final ChannelCommand command = ChannelCommand();
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['channel', 'beta']); await runner.run(<String>['channel', 'beta']);
verify(mockProcessManager.start(
<String>['git', 'fetch'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
verify(mockProcessManager.start(
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/beta'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
verify(mockProcessManager.start(
<String>['git', 'checkout', 'beta', '--'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
expect( expect(
testLogger.statusText, testLogger.statusText,
containsIgnoringWhitespace("Successfully switched to flutter channel 'beta'."), containsIgnoringWhitespace("Successfully switched to flutter channel 'beta'."),
...@@ -306,29 +235,26 @@ void main() { ...@@ -306,29 +235,26 @@ void main() {
"from this channel, run 'flutter upgrade'"), "from this channel, run 'flutter upgrade'"),
); );
expect(testLogger.errorText, hasLength(0)); expect(testLogger.errorText, hasLength(0));
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(), FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => mockProcessManager, ProcessManager: () => fakeProcessManager,
}); });
// This verifies that bug https://github.com/flutter/flutter/issues/21134 // This verifies that bug https://github.com/flutter/flutter/issues/21134
// doesn't return. // doesn't return.
testUsingContext('removes version stamp file when switching channels', () async { testUsingContext('removes version stamp file when switching channels', () async {
when(mockProcessManager.start( fakeProcessManager.addCommands(<FakeCommand>[
<String>['git', 'fetch'], const FakeCommand(
workingDirectory: anyNamed('workingDirectory'), command: <String>['git', 'fetch'],
environment: anyNamed('environment'), ),
)).thenAnswer((_) => Future<Process>.value(createMockProcess())); const FakeCommand(
when(mockProcessManager.start( command: <String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/beta'],
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/beta'], ),
workingDirectory: anyNamed('workingDirectory'), const FakeCommand(
environment: anyNamed('environment'), command: <String>['git', 'checkout', 'beta', '--']
)).thenAnswer((_) => Future<Process>.value(createMockProcess())); ),
when(mockProcessManager.start( ]);
<String>['git', 'checkout', 'beta', '--'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) => Future<Process>.value(createMockProcess()));
final File versionCheckFile = globals.cache.getStampFileFor( final File versionCheckFile = globals.cache.getStampFileFor(
VersionCheckStamp.flutterVersionCheckStampFile, VersionCheckStamp.flutterVersionCheckStampFile,
...@@ -348,32 +274,13 @@ void main() { ...@@ -348,32 +274,13 @@ void main() {
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['channel', 'beta']); await runner.run(<String>['channel', 'beta']);
verify(mockProcessManager.start(
<String>['git', 'fetch'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
verify(mockProcessManager.start(
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/beta'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
verify(mockProcessManager.start(
<String>['git', 'checkout', 'beta', '--'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
expect(testLogger.statusText, isNot(contains('A new version of Flutter'))); expect(testLogger.statusText, isNot(contains('A new version of Flutter')));
expect(testLogger.errorText, hasLength(0)); expect(testLogger.errorText, hasLength(0));
expect(versionCheckFile.existsSync(), isFalse); expect(versionCheckFile.existsSync(), isFalse);
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(), FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => mockProcessManager, ProcessManager: () => fakeProcessManager,
}); });
}); });
} }
class MockProcessManager extends Mock implements ProcessManager {}
class MockProcess extends Mock implements Process {}
...@@ -31,7 +31,6 @@ void main() { ...@@ -31,7 +31,6 @@ void main() {
// Create an l10n.yaml file // Create an l10n.yaml file
fileSystem.file('l10n.yaml').createSync(); fileSystem.file('l10n.yaml').createSync();
final FakeProcessManager mockProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test(); final BufferLogger mockBufferLogger = BufferLogger.test();
final Artifacts artifacts = Artifacts.test(); final Artifacts artifacts = Artifacts.test();
final Environment environment = Environment.test( final Environment environment = Environment.test(
...@@ -39,7 +38,7 @@ void main() { ...@@ -39,7 +38,7 @@ void main() {
fileSystem: fileSystem, fileSystem: fileSystem,
logger: mockBufferLogger, logger: mockBufferLogger,
artifacts: artifacts, artifacts: artifacts,
processManager: mockProcessManager, processManager: FakeProcessManager.any(),
); );
final BuildSystem buildSystem = MockBuildSystem(); final BuildSystem buildSystem = MockBuildSystem();
...@@ -72,7 +71,7 @@ void main() { ...@@ -72,7 +71,7 @@ void main() {
// Create an l10n.yaml file // Create an l10n.yaml file
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: true'); fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: true');
final FakeProcessManager mockProcessManager = FakeProcessManager.any(); final FakeProcessManager fakeProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test(); final BufferLogger mockBufferLogger = BufferLogger.test();
final Artifacts artifacts = Artifacts.test(); final Artifacts artifacts = Artifacts.test();
final Environment environment = Environment.test( final Environment environment = Environment.test(
...@@ -80,7 +79,7 @@ void main() { ...@@ -80,7 +79,7 @@ void main() {
fileSystem: fileSystem, fileSystem: fileSystem,
logger: mockBufferLogger, logger: mockBufferLogger,
artifacts: artifacts, artifacts: artifacts,
processManager: mockProcessManager, processManager: fakeProcessManager,
); );
final BuildSystem buildSystem = MockBuildSystem(); final BuildSystem buildSystem = MockBuildSystem();
...@@ -113,14 +112,13 @@ void main() { ...@@ -113,14 +112,13 @@ void main() {
// Create an l10n.yaml file // Create an l10n.yaml file
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: null'); fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: null');
final FakeProcessManager mockProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test(); final BufferLogger mockBufferLogger = BufferLogger.test();
final Environment environment = Environment.test( final Environment environment = Environment.test(
fileSystem.currentDirectory, fileSystem.currentDirectory,
fileSystem: fileSystem, fileSystem: fileSystem,
logger: mockBufferLogger, logger: mockBufferLogger,
artifacts: Artifacts.test(), artifacts: Artifacts.test(),
processManager: mockProcessManager, processManager: FakeProcessManager.any(),
); );
final BuildSystem buildSystem = MockBuildSystem(); final BuildSystem buildSystem = MockBuildSystem();
...@@ -150,14 +148,13 @@ void main() { ...@@ -150,14 +148,13 @@ void main() {
); );
pubspecFile.writeAsStringSync(content); pubspecFile.writeAsStringSync(content);
final FakeProcessManager mockProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test(); final BufferLogger mockBufferLogger = BufferLogger.test();
final Environment environment = Environment.test( final Environment environment = Environment.test(
fileSystem.currentDirectory, fileSystem.currentDirectory,
fileSystem: fileSystem, fileSystem: fileSystem,
logger: mockBufferLogger, logger: mockBufferLogger,
artifacts: Artifacts.test(), artifacts: Artifacts.test(),
processManager: mockProcessManager, processManager: FakeProcessManager.any(),
); );
final BuildSystem buildSystem = MockBuildSystem(); final BuildSystem buildSystem = MockBuildSystem();
...@@ -187,14 +184,13 @@ void main() { ...@@ -187,14 +184,13 @@ void main() {
// Create an l10n.yaml file // Create an l10n.yaml file
fileSystem.file('l10n.yaml').writeAsStringSync('helloWorld'); fileSystem.file('l10n.yaml').writeAsStringSync('helloWorld');
final FakeProcessManager mockProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test(); final BufferLogger mockBufferLogger = BufferLogger.test();
final Environment environment = Environment.test( final Environment environment = Environment.test(
fileSystem.currentDirectory, fileSystem.currentDirectory,
fileSystem: fileSystem, fileSystem: fileSystem,
logger: mockBufferLogger, logger: mockBufferLogger,
artifacts: Artifacts.test(), artifacts: Artifacts.test(),
processManager: mockProcessManager, processManager: FakeProcessManager.any(),
); );
final BuildSystem buildSystem = MockBuildSystem(); final BuildSystem buildSystem = MockBuildSystem();
...@@ -227,14 +223,13 @@ void main() { ...@@ -227,14 +223,13 @@ void main() {
// Create an l10n.yaml file // Create an l10n.yaml file
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: nonBoolValue'); fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: nonBoolValue');
final FakeProcessManager mockProcessManager = FakeProcessManager.any();
final BufferLogger mockBufferLogger = BufferLogger.test(); final BufferLogger mockBufferLogger = BufferLogger.test();
final Environment environment = Environment.test( final Environment environment = Environment.test(
fileSystem.currentDirectory, fileSystem.currentDirectory,
fileSystem: fileSystem, fileSystem: fileSystem,
logger: mockBufferLogger, logger: mockBufferLogger,
artifacts: Artifacts.test(), artifacts: Artifacts.test(),
processManager: mockProcessManager, processManager: FakeProcessManager.any(),
); );
final BuildSystem buildSystem = MockBuildSystem(); final BuildSystem buildSystem = MockBuildSystem();
......
...@@ -18,7 +18,6 @@ import 'package:flutter_tools/src/compile.dart'; ...@@ -18,7 +18,6 @@ import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/ios/devices.dart'; import 'package:flutter_tools/src/ios/devices.dart';
import 'package:flutter_tools/src/ios/simulators.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:package_config/package_config.dart'; import 'package:package_config/package_config.dart';
...@@ -580,17 +579,6 @@ class MockIOSDevice extends Mock implements IOSDevice { ...@@ -580,17 +579,6 @@ class MockIOSDevice extends Mock implements IOSDevice {
bool isSupportedForProject(FlutterProject flutterProject) => true; bool isSupportedForProject(FlutterProject flutterProject) => true;
} }
class MockIOSSimulator extends Mock implements IOSSimulator {
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.ios;
@override
bool isSupported() => true;
@override
bool isSupportedForProject(FlutterProject flutterProject) => true;
}
/// Common functionality for tracking mock interaction. /// Common functionality for tracking mock interaction.
class BasicMock { class BasicMock {
final List<String> messages = <String>[]; final List<String> messages = <String>[];
...@@ -710,9 +698,6 @@ class MockStdIn extends Mock implements IOSink { ...@@ -710,9 +698,6 @@ class MockStdIn extends Mock implements IOSink {
class MockStream extends Mock implements Stream<List<int>> {} class MockStream extends Mock implements Stream<List<int>> {}
class MockDevToolsServer extends Mock implements HttpServer {}
class MockInternetAddress extends Mock implements InternetAddress {}
class AlwaysTrueBotDetector implements BotDetector { class AlwaysTrueBotDetector implements BotDetector {
const AlwaysTrueBotDetector(); const AlwaysTrueBotDetector();
......
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