[flutter_tools] replace MockFlutterVersion usage with fake where possible, move from context (#77390)
This commit is contained in:
parent
db162a47f3
commit
721702717d
@ -720,7 +720,7 @@ class FlutterValidator extends DoctorValidator {
|
||||
messages.add(ValidationMessage(_userMessages.flutterRevision(
|
||||
version.frameworkRevisionShort,
|
||||
version.frameworkAge,
|
||||
version.frameworkDate,
|
||||
version.frameworkCommitDate,
|
||||
)));
|
||||
messages.add(ValidationMessage(_userMessages.engineRevision(version.engineRevisionShort)));
|
||||
messages.add(ValidationMessage(_userMessages.dartRevision(version.dartSdkVersion)));
|
||||
|
@ -144,8 +144,6 @@ class FlutterVersion {
|
||||
String _frameworkVersion;
|
||||
String get frameworkVersion => _frameworkVersion;
|
||||
|
||||
String get frameworkDate => frameworkCommitDate;
|
||||
|
||||
String get dartSdkVersion => globals.cache.dartSdkVersion;
|
||||
|
||||
String get engineRevision => globals.cache.engineRevision;
|
||||
@ -181,6 +179,8 @@ class FlutterVersion {
|
||||
'dartSdkVersion': dartSdkVersion,
|
||||
};
|
||||
|
||||
String get frameworkDate => frameworkCommitDate;
|
||||
|
||||
/// A date String describing the last framework commit.
|
||||
///
|
||||
/// If a git command fails, this will return a placeholder date.
|
||||
|
@ -53,12 +53,12 @@ final Platform macPlatform = FakePlatform(
|
||||
);
|
||||
|
||||
void main() {
|
||||
MockFlutterVersion mockFlutterVersion;
|
||||
FakeFlutterVersion flutterVersion;
|
||||
BufferLogger logger;
|
||||
FakeProcessManager fakeProcessManager;
|
||||
|
||||
setUp(() {
|
||||
mockFlutterVersion = MockFlutterVersion();
|
||||
flutterVersion = FakeFlutterVersion();
|
||||
logger = BufferLogger.test();
|
||||
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
|
||||
});
|
||||
@ -667,13 +667,12 @@ void main() {
|
||||
|
||||
await commandRunner.run(<String>['doctor']);
|
||||
|
||||
verify(mockFlutterVersion.fetchTagsAndUpdate()).called(1);
|
||||
|
||||
expect(flutterVersion.didFetchTagsAndUpdate, true);
|
||||
Cache.enableLocking();
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
FlutterVersion: () => mockFlutterVersion,
|
||||
FlutterVersion: () => flutterVersion,
|
||||
Doctor: () => NoOpDoctor(),
|
||||
}, initializeFlutterRoot: false);
|
||||
|
||||
|
@ -17,6 +17,7 @@ import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/mocks.dart';
|
||||
|
||||
void main() {
|
||||
FileSystem fileSystem;
|
||||
|
@ -20,6 +20,7 @@ import 'package:process/process.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fake_process_manager.dart';
|
||||
import '../../src/mocks.dart';
|
||||
|
||||
void main() {
|
||||
group('UpgradeCommandRunner', () {
|
||||
|
@ -14,6 +14,7 @@ import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/convert.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/drive/drive_service.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:flutter_tools/src/vmservice.dart';
|
||||
import 'package:package_config/package_config_types.dart';
|
||||
import 'package:test/fake.dart';
|
||||
@ -21,6 +22,7 @@ import 'package:vm_service/vm_service.dart' as vm_service;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fakes.dart';
|
||||
|
||||
|
||||
final vm_service.Isolate fakeUnpausedIsolate = vm_service.Isolate(
|
||||
@ -288,9 +290,13 @@ void main() {
|
||||
expect(json.decode(fileSystem.file('out.json').readAsStringSync()), <String, Object>{
|
||||
'platform': 'android',
|
||||
'name': 'test',
|
||||
'engineRevision': null,
|
||||
'engineRevision': 'abcdefghijklmnopqrstuvwxyz',
|
||||
'data': <String, Object>{'A': 'B'}
|
||||
});
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => FakeFlutterVersion(
|
||||
engineRevision: 'abcdefghijklmnopqrstuvwxyz',
|
||||
)
|
||||
});
|
||||
|
||||
testWithoutContext('Can connect to existing application and stop it during cleanup', () async {
|
||||
|
@ -15,11 +15,14 @@ import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/fakes.dart';
|
||||
|
||||
void main() {
|
||||
testWithoutContext('FlutterValidator shows an error message if gen_snapshot is '
|
||||
'downloaded and exits with code 1', () async {
|
||||
final MockFlutterVersion flutterVersion = MockFlutterVersion();
|
||||
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(
|
||||
frameworkVersion: '1.0.0',
|
||||
);
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
final Artifacts artifacts = Artifacts.test();
|
||||
final FlutterValidator flutterValidator = FlutterValidator(
|
||||
@ -46,7 +49,7 @@ void main() {
|
||||
|
||||
expect(await flutterValidator.validate(), matchDoctorValidation(
|
||||
validationType: ValidationType.partial,
|
||||
statusInfo: 'Channel unknown, Unknown, on Linux, locale en_US.UTF-8',
|
||||
statusInfo: 'Channel unknown, 1.0.0, on Linux, locale en_US.UTF-8',
|
||||
messages: containsAll(const <ValidationMessage>[
|
||||
ValidationMessage.error(
|
||||
'Downloaded executables cannot execute on host.\n'
|
||||
@ -60,13 +63,16 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterValidator does not run gen_snapshot binary check if it is not already downloaded', () async {
|
||||
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(
|
||||
frameworkVersion: '1.0.0',
|
||||
);
|
||||
final FlutterValidator flutterValidator = FlutterValidator(
|
||||
platform: FakePlatform(
|
||||
operatingSystem: 'windows',
|
||||
localeName: 'en_US.UTF-8',
|
||||
environment: <String, String>{},
|
||||
),
|
||||
flutterVersion: () => MockFlutterVersion(),
|
||||
flutterVersion: () => flutterVersion,
|
||||
userMessages: UserMessages(),
|
||||
artifacts: Artifacts.test(),
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
@ -79,16 +85,15 @@ void main() {
|
||||
// fail if the gen_snapshot binary is not present.
|
||||
expect(await flutterValidator.validate(), matchDoctorValidation(
|
||||
validationType: ValidationType.installed,
|
||||
statusInfo: 'Channel unknown, Unknown, on Windows, locale en_US.UTF-8',
|
||||
statusInfo: 'Channel unknown, 1.0.0, on Windows, locale en_US.UTF-8',
|
||||
messages: anything,
|
||||
));
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterValidator handles exception thrown by version checking', () async {
|
||||
final MockFlutterVersion flutterVersion = MockFlutterVersion();
|
||||
final FlutterValidator flutterValidator = FlutterValidator(
|
||||
platform: FakePlatform(operatingSystem: 'windows', localeName: 'en_US.UTF-8'),
|
||||
flutterVersion: () => flutterVersion,
|
||||
flutterVersion: () => FakeThrowingFlutterVersion(),
|
||||
userMessages: UserMessages(),
|
||||
artifacts: Artifacts.test(),
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
@ -97,10 +102,6 @@ void main() {
|
||||
flutterRoot: () => 'sdk/flutter',
|
||||
);
|
||||
|
||||
when(flutterVersion.channel).thenReturn('unknown');
|
||||
when(flutterVersion.frameworkVersion).thenReturn('0.0.0');
|
||||
when(flutterVersion.frameworkDate).thenThrow(VersionCheckError('version error'));
|
||||
|
||||
expect(await flutterValidator.validate(), matchDoctorValidation(
|
||||
validationType: ValidationType.partial,
|
||||
statusInfo: 'Channel unknown, 0.0.0, on Windows, locale en_US.UTF-8',
|
||||
@ -112,6 +113,9 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterValidator shows mirrors on pub and flutter cloud storage', () async {
|
||||
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(
|
||||
frameworkVersion: '1.0.0',
|
||||
);
|
||||
final Platform platform = FakePlatform(
|
||||
operatingSystem: 'windows',
|
||||
localeName: 'en_US.UTF-8',
|
||||
@ -120,7 +124,6 @@ void main() {
|
||||
'FLUTTER_STORAGE_BASE_URL': 'https://example.com/flutter',
|
||||
},
|
||||
);
|
||||
final MockFlutterVersion flutterVersion = MockFlutterVersion();
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
final Artifacts artifacts = Artifacts.test();
|
||||
final FlutterValidator flutterValidator = FlutterValidator(
|
||||
@ -136,7 +139,7 @@ void main() {
|
||||
|
||||
expect(await flutterValidator.validate(), matchDoctorValidation(
|
||||
validationType: ValidationType.installed,
|
||||
statusInfo: 'Channel unknown, Unknown, on Windows, locale en_US.UTF-8',
|
||||
statusInfo: 'Channel unknown, 1.0.0, on Windows, locale en_US.UTF-8',
|
||||
messages: containsAll(const <ValidationMessage>[
|
||||
ValidationMessage('Pub download mirror https://example.com/pub'),
|
||||
ValidationMessage('Flutter download mirror https://example.com/flutter'),
|
||||
@ -145,10 +148,16 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
class MockFlutterVersion extends Mock implements FlutterVersion {}
|
||||
class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
|
||||
FakeOperatingSystemUtils({this.name});
|
||||
|
||||
@override
|
||||
final String name;
|
||||
}
|
||||
|
||||
class FakeThrowingFlutterVersion extends FakeFlutterVersion {
|
||||
@override
|
||||
String get frameworkCommitDate {
|
||||
throw VersionCheckError('version error');
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ void main() {
|
||||
MockWindowsProject windowsProject;
|
||||
MockLinuxProject linuxProject;
|
||||
FakeSystemClock systemClock;
|
||||
FlutterVersion mockVersion;
|
||||
FlutterVersion flutterVersion;
|
||||
// A Windows-style filesystem. This is not populated by default, so tests
|
||||
// using it instead of fs must re-run any necessary setup (e.g.,
|
||||
// setUpProject).
|
||||
@ -126,15 +126,11 @@ void main() {
|
||||
fsWindows = MemoryFileSystem(style: FileSystemStyle.windows);
|
||||
systemClock = FakeSystemClock()
|
||||
..currentTime = DateTime(1970, 1, 1);
|
||||
mockVersion = MockFlutterVersion();
|
||||
flutterVersion = FakeFlutterVersion(frameworkVersion: '1.0.0');
|
||||
|
||||
// Add basic properties to the Flutter project and subprojects
|
||||
setUpProject(fs);
|
||||
flutterProject.directory.childFile('.packages').createSync(recursive: true);
|
||||
|
||||
when(mockVersion.frameworkVersion).thenAnswer(
|
||||
(Invocation _) => '1.0.0'
|
||||
);
|
||||
});
|
||||
|
||||
// Makes fake plugin packages for each plugin, adds them to flutterProject,
|
||||
@ -436,10 +432,6 @@ dependencies:
|
||||
|
||||
final DateTime dateCreated = DateTime(1970, 1, 1);
|
||||
systemClock.currentTime = dateCreated;
|
||||
const String version = '1.0.0';
|
||||
when(mockVersion.frameworkVersion).thenAnswer(
|
||||
(Invocation _) => version
|
||||
);
|
||||
|
||||
await refreshPluginsList(flutterProject);
|
||||
|
||||
@ -510,7 +502,7 @@ dependencies:
|
||||
|
||||
expect(jsonContent['dependencyGraph'], expectedDependencyGraph);
|
||||
expect(jsonContent['date_created'], dateCreated.toString());
|
||||
expect(jsonContent['version'], version);
|
||||
expect(jsonContent['version'], '1.0.0');
|
||||
|
||||
// Make sure tests are updated if a new object is added/removed.
|
||||
final List<String> expectedKeys = <String>[
|
||||
@ -525,7 +517,7 @@ dependencies:
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
SystemClock: () => systemClock,
|
||||
FlutterVersion: () => mockVersion
|
||||
FlutterVersion: () => flutterVersion
|
||||
});
|
||||
|
||||
testUsingContext('Changes to the plugin list invalidates the Cocoapod lockfiles', () async {
|
||||
@ -542,7 +534,7 @@ dependencies:
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
SystemClock: () => systemClock,
|
||||
FlutterVersion: () => mockVersion
|
||||
FlutterVersion: () => flutterVersion
|
||||
});
|
||||
|
||||
testUsingContext('No changes to the plugin list does not invalidate the Cocoapod lockfiles', () async {
|
||||
@ -565,7 +557,7 @@ dependencies:
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
SystemClock: () => systemClock,
|
||||
FlutterVersion: () => mockVersion
|
||||
FlutterVersion: () => flutterVersion
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -11,6 +11,7 @@ import 'package:flutter_tools/src/base/dds.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/resident_devtools_handler.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:package_config/package_config.dart';
|
||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||
@ -1585,7 +1586,7 @@ void main() {
|
||||
expect(json.decode(globals.fs.file('flutter_01.sksl.json').readAsStringSync()), <String, Object>{
|
||||
'platform': 'android',
|
||||
'name': 'FakeDevice',
|
||||
'engineRevision': '42.2', // From FakeFlutterVersion
|
||||
'engineRevision': 'abcdefg',
|
||||
'data': <String, Object>{'A': 'B'}
|
||||
});
|
||||
expect(fakeVmServiceHost.hasRemainingExpectations, false);
|
||||
@ -1593,7 +1594,8 @@ void main() {
|
||||
FileSystemUtils: () => FileSystemUtils(
|
||||
fileSystem: globals.fs,
|
||||
platform: globals.platform,
|
||||
)
|
||||
),
|
||||
FlutterVersion: () => FakeFlutterVersion(engineRevision: 'abcdefg')
|
||||
}));
|
||||
|
||||
testUsingContext('ResidentRunner ignores DevToolsLauncher when attaching with enableDevTools: false', () => testbed.run(() async {
|
||||
|
@ -14,10 +14,10 @@ import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/runner/flutter_command.dart';
|
||||
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
const String _kFlutterRoot = '/flutter/flutter';
|
||||
@ -25,20 +25,19 @@ const String _kProjectRoot = '/project';
|
||||
|
||||
void main() {
|
||||
group('FlutterCommandRunner', () {
|
||||
MemoryFileSystem fs;
|
||||
MemoryFileSystem fileSystem;
|
||||
Platform platform;
|
||||
FlutterCommandRunner runner;
|
||||
ProcessManager processManager;
|
||||
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
fs = MemoryFileSystem.test();
|
||||
fs.directory(_kFlutterRoot).createSync(recursive: true);
|
||||
fs.directory(_kProjectRoot).createSync(recursive: true);
|
||||
fs.currentDirectory = _kProjectRoot;
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
fileSystem.directory(_kFlutterRoot).createSync(recursive: true);
|
||||
fileSystem.directory(_kProjectRoot).createSync(recursive: true);
|
||||
fileSystem.currentDirectory = _kProjectRoot;
|
||||
|
||||
platform = FakePlatform(
|
||||
environment: <String, String>{
|
||||
@ -48,100 +47,60 @@ void main() {
|
||||
);
|
||||
|
||||
runner = createTestCommandRunner(DummyFlutterCommand()) as FlutterCommandRunner;
|
||||
processManager = MockProcessManager();
|
||||
});
|
||||
|
||||
group('run', () {
|
||||
testUsingContext('checks that Flutter installation is up-to-date', () async {
|
||||
final MockFlutterVersion version = globals.flutterVersion as MockFlutterVersion;
|
||||
bool versionChecked = false;
|
||||
when(version.checkFlutterVersionFreshness()).thenAnswer((_) async {
|
||||
versionChecked = true;
|
||||
});
|
||||
final FakeFlutterVersion version = globals.flutterVersion as FakeFlutterVersion;
|
||||
|
||||
await runner.run(<String>['dummy']);
|
||||
|
||||
expect(versionChecked, isTrue);
|
||||
expect(version.didCheckFlutterVersionFreshness, true);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Platform: () => platform,
|
||||
}, initializeFlutterRoot: false);
|
||||
FlutterVersion: () => FakeFlutterVersion(),
|
||||
});
|
||||
|
||||
testUsingContext('does not check that Flutter installation is up-to-date with --machine flag', () async {
|
||||
final MockFlutterVersion version = globals.flutterVersion as MockFlutterVersion;
|
||||
bool versionChecked = false;
|
||||
when(version.checkFlutterVersionFreshness()).thenAnswer((_) async {
|
||||
versionChecked = true;
|
||||
});
|
||||
final FakeFlutterVersion version = globals.flutterVersion as FakeFlutterVersion;
|
||||
|
||||
await runner.run(<String>['dummy', '--machine', '--version']);
|
||||
|
||||
expect(versionChecked, isFalse);
|
||||
expect(version.didCheckFlutterVersionFreshness, false);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Platform: () => platform,
|
||||
}, initializeFlutterRoot: false);
|
||||
FlutterVersion: () => FakeFlutterVersion(),
|
||||
});
|
||||
|
||||
testUsingContext('Fetches tags when --version is used', () async {
|
||||
final MockFlutterVersion version = globals.flutterVersion as MockFlutterVersion;
|
||||
final FakeFlutterVersion version = globals.flutterVersion as FakeFlutterVersion;
|
||||
|
||||
await runner.run(<String>['--version']);
|
||||
|
||||
verify(version.fetchTagsAndUpdate()).called(1);
|
||||
expect(version.didFetchTagsAndUpdate, true);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Platform: () => platform,
|
||||
}, initializeFlutterRoot: false);
|
||||
FlutterVersion: () => FakeFlutterVersion(),
|
||||
});
|
||||
|
||||
testUsingContext('Doesnt crash on invalid .packages file', () async {
|
||||
fs.file('pubspec.yaml').createSync();
|
||||
fs.file('.packages')
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('.packages')
|
||||
..createSync()
|
||||
..writeAsStringSync('Not a valid package');
|
||||
|
||||
await runner.run(<String>['dummy']);
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Platform: () => platform,
|
||||
}, initializeFlutterRoot: false);
|
||||
|
||||
group('version', () {
|
||||
testUsingContext('checks that Flutter toJson output reports the flutter framework version', () async {
|
||||
final ProcessResult result = ProcessResult(0, 0, 'random', '0');
|
||||
|
||||
when(processManager.runSync(FlutterVersion.gitLog('-n 1 --pretty=format:%H'.split(' ')),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync('git rev-parse --abbrev-ref --symbolic @{u}'.split(' '),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync('git rev-parse --abbrev-ref HEAD'.split(' '),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync('git ls-remote --get-url master'.split(' '),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync(FlutterVersion.gitLog('-n 1 --pretty=format:%ar'.split(' ')),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync('git fetch https://github.com/flutter/flutter.git --tags'.split(' '),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync('git tag --points-at random'.split(' '),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync('git describe --match *.*.* --long --tags random'.split(' '),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync(FlutterVersion.gitLog('-n 1 --pretty=format:%ad --date=iso'.split(' ')),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
|
||||
final FakeFlutterVersion version = FakeFlutterVersion();
|
||||
|
||||
// Because the hash depends on the time, we just use the 0.0.0-unknown here.
|
||||
expect(version.toJson()['frameworkVersion'], '0.10.3');
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => processManager,
|
||||
Platform: () => platform,
|
||||
}, initializeFlutterRoot: false);
|
||||
});
|
||||
|
||||
group('getRepoPackages', () {
|
||||
@ -150,16 +109,16 @@ void main() {
|
||||
setUp(() {
|
||||
oldFlutterRoot = Cache.flutterRoot;
|
||||
Cache.flutterRoot = _kFlutterRoot;
|
||||
fs.directory(fs.path.join(_kFlutterRoot, 'examples'))
|
||||
fileSystem.directory(fileSystem.path.join(_kFlutterRoot, 'examples'))
|
||||
.createSync(recursive: true);
|
||||
fs.directory(fs.path.join(_kFlutterRoot, 'packages'))
|
||||
fileSystem.directory(fileSystem.path.join(_kFlutterRoot, 'packages'))
|
||||
.createSync(recursive: true);
|
||||
fs.directory(fs.path.join(_kFlutterRoot, 'dev', 'tools', 'aatool'))
|
||||
fileSystem.directory(fileSystem.path.join(_kFlutterRoot, 'dev', 'tools', 'aatool'))
|
||||
.createSync(recursive: true);
|
||||
|
||||
fs.file(fs.path.join(_kFlutterRoot, 'dev', 'tools', 'pubspec.yaml'))
|
||||
fileSystem.file(fileSystem.path.join(_kFlutterRoot, 'dev', 'tools', 'pubspec.yaml'))
|
||||
.createSync();
|
||||
fs.file(fs.path.join(_kFlutterRoot, 'dev', 'tools', 'aatool', 'pubspec.yaml'))
|
||||
fileSystem.file(fileSystem.path.join(_kFlutterRoot, 'dev', 'tools', 'aatool', 'pubspec.yaml'))
|
||||
.createSync();
|
||||
});
|
||||
|
||||
@ -169,16 +128,17 @@ void main() {
|
||||
|
||||
testUsingContext('', () {
|
||||
final List<String> packagePaths = runner.getRepoPackages()
|
||||
.map((Directory d) => d.path).toList();
|
||||
.map((Directory d) => d.path).toList();
|
||||
expect(packagePaths, <String>[
|
||||
fs.directory(fs.path.join(_kFlutterRoot, 'dev', 'tools', 'aatool')).path,
|
||||
fs.directory(fs.path.join(_kFlutterRoot, 'dev', 'tools')).path,
|
||||
fileSystem.directory(fileSystem.path.join(_kFlutterRoot, 'dev', 'tools', 'aatool')).path,
|
||||
fileSystem.directory(fileSystem.path.join(_kFlutterRoot, 'dev', 'tools')).path,
|
||||
]);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Platform: () => platform,
|
||||
}, initializeFlutterRoot: false);
|
||||
FlutterVersion: () => FakeFlutterVersion(),
|
||||
});
|
||||
});
|
||||
|
||||
group('wrapping', () {
|
||||
@ -188,7 +148,7 @@ void main() {
|
||||
await runner.run(<String>['fake']);
|
||||
expect(fakeCommand.preferences.wrapText, isTrue);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Stdio: () => FakeStdio(hasFakeTerminal: true),
|
||||
}, initializeFlutterRoot: false);
|
||||
@ -199,7 +159,7 @@ void main() {
|
||||
await runner.run(<String>['fake']);
|
||||
expect(fakeCommand.preferences.wrapText, isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Stdio: () => FakeStdio(hasFakeTerminal: false),
|
||||
}, initializeFlutterRoot: false);
|
||||
@ -210,7 +170,7 @@ void main() {
|
||||
await runner.run(<String>['--no-wrap', 'fake']);
|
||||
expect(fakeCommand.preferences.wrapText, isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Stdio: () => FakeStdio(hasFakeTerminal: true),
|
||||
}, initializeFlutterRoot: false);
|
||||
@ -221,7 +181,7 @@ void main() {
|
||||
await runner.run(<String>['--wrap', 'fake']);
|
||||
expect(fakeCommand.preferences.wrapText, isTrue);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Stdio: () => FakeStdio(hasFakeTerminal: false),
|
||||
}, initializeFlutterRoot: false);
|
||||
@ -229,12 +189,6 @@ void main() {
|
||||
});
|
||||
});
|
||||
}
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
|
||||
class FakeFlutterVersion extends FlutterVersion {
|
||||
@override
|
||||
String get frameworkVersion => '0.10.3';
|
||||
}
|
||||
|
||||
class FakeFlutterCommand extends FlutterCommand {
|
||||
OutputPreferences preferences;
|
||||
|
@ -16,8 +16,6 @@ import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/tester/flutter_tester.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
@ -100,7 +98,7 @@ void main() {
|
||||
artifacts: Artifacts.test(),
|
||||
buildDirectory: 'build',
|
||||
logger: BufferLogger.test(),
|
||||
flutterVersion: MockFlutterVersion(),
|
||||
flutterVersion: FakeFlutterVersion(),
|
||||
operatingSystemUtils: FakeOperatingSystemUtils(),
|
||||
);
|
||||
logLines = <String>[];
|
||||
@ -183,9 +181,7 @@ FlutterTesterDevices setUpFlutterTesterDevices() {
|
||||
processManager: FakeProcessManager.any(),
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
config: Config.test(),
|
||||
flutterVersion: MockFlutterVersion(),
|
||||
flutterVersion: FakeFlutterVersion(),
|
||||
operatingSystemUtils: FakeOperatingSystemUtils(),
|
||||
);
|
||||
}
|
||||
|
||||
class MockFlutterVersion extends Mock implements FlutterVersion {}
|
||||
|
@ -112,7 +112,7 @@ void testUsingContext(
|
||||
Config: () => buildConfig(globals.fs),
|
||||
DeviceManager: () => FakeDeviceManager(),
|
||||
Doctor: () => FakeDoctor(globals.logger),
|
||||
FlutterVersion: () => MockFlutterVersion(),
|
||||
FlutterVersion: () => FakeFlutterVersion(),
|
||||
HttpClient: () => FakeHttpClient.any(),
|
||||
IOSSimulatorUtils: () {
|
||||
final MockIOSSimulatorUtils mock = MockIOSSimulatorUtils();
|
||||
@ -377,8 +377,6 @@ class FakeXcodeProjectInterpreter implements XcodeProjectInterpreter {
|
||||
List<String> xcrunCommand() => <String>['xcrun'];
|
||||
}
|
||||
|
||||
class MockFlutterVersion extends Mock implements FlutterVersion {}
|
||||
|
||||
class MockCrashReporter extends Mock implements CrashReporter {}
|
||||
|
||||
class LocalFileSystemBlockingSetCurrentDirectory extends LocalFileSystem {
|
||||
|
@ -448,14 +448,67 @@ class FakePub extends Fake implements Pub {
|
||||
}
|
||||
|
||||
class FakeFlutterVersion implements FlutterVersion {
|
||||
@override
|
||||
void fetchTagsAndUpdate() { }
|
||||
FakeFlutterVersion({
|
||||
this.channel = 'unknown',
|
||||
this.dartSdkVersion = '12',
|
||||
this.engineRevision = 'abcdefghijklmnopqrstuvwxyz',
|
||||
this.engineRevisionShort = 'abcde',
|
||||
this.repositoryUrl = 'https://github.com/flutter/flutter.git',
|
||||
this.frameworkVersion = '0.0.0',
|
||||
this.frameworkRevision = '11111111111111111111',
|
||||
this.frameworkRevisionShort = '11111',
|
||||
this.frameworkAge = '0 hours ago',
|
||||
this.frameworkCommitDate = '12/01/01'
|
||||
});
|
||||
|
||||
bool get didFetchTagsAndUpdate => _didFetchTagsAndUpdate;
|
||||
bool _didFetchTagsAndUpdate = false;
|
||||
|
||||
bool get didCheckFlutterVersionFreshness => _didCheckFlutterVersionFreshness;
|
||||
bool _didCheckFlutterVersionFreshness = false;
|
||||
|
||||
@override
|
||||
String get channel => 'master';
|
||||
final String channel;
|
||||
|
||||
@override
|
||||
Future<void> checkFlutterVersionFreshness() async { }
|
||||
final String dartSdkVersion;
|
||||
|
||||
@override
|
||||
final String engineRevision;
|
||||
|
||||
@override
|
||||
final String engineRevisionShort;
|
||||
|
||||
@override
|
||||
final String repositoryUrl;
|
||||
|
||||
@override
|
||||
final String frameworkVersion;
|
||||
|
||||
@override
|
||||
final String frameworkRevision;
|
||||
|
||||
@override
|
||||
final String frameworkRevisionShort;
|
||||
|
||||
@override
|
||||
final String frameworkAge;
|
||||
|
||||
@override
|
||||
final String frameworkCommitDate;
|
||||
|
||||
@override
|
||||
String get frameworkDate => frameworkCommitDate;
|
||||
|
||||
@override
|
||||
void fetchTagsAndUpdate() {
|
||||
_didFetchTagsAndUpdate = true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> checkFlutterVersionFreshness() async {
|
||||
_didCheckFlutterVersionFreshness = true;
|
||||
}
|
||||
|
||||
@override
|
||||
bool checkRevisionAncestry({String tentativeDescendantRevision, String tentativeAncestorRevision}) {
|
||||
@ -463,38 +516,13 @@ class FakeFlutterVersion implements FlutterVersion {
|
||||
}
|
||||
|
||||
@override
|
||||
String get dartSdkVersion => '12';
|
||||
|
||||
@override
|
||||
String get engineRevision => '42.2';
|
||||
|
||||
@override
|
||||
String get engineRevisionShort => '42';
|
||||
GitTagVersion get gitTagVersion {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> ensureVersionFile() async { }
|
||||
|
||||
@override
|
||||
String get frameworkAge => null;
|
||||
|
||||
@override
|
||||
String get frameworkCommitDate => null;
|
||||
|
||||
@override
|
||||
String get frameworkDate => null;
|
||||
|
||||
@override
|
||||
String get frameworkRevision => null;
|
||||
|
||||
@override
|
||||
String get frameworkRevisionShort => null;
|
||||
|
||||
@override
|
||||
String get frameworkVersion => null;
|
||||
|
||||
@override
|
||||
GitTagVersion get gitTagVersion => null;
|
||||
|
||||
@override
|
||||
String getBranchName({bool redactUnknownBranches = false}) {
|
||||
return 'master';
|
||||
@ -505,12 +533,9 @@ class FakeFlutterVersion implements FlutterVersion {
|
||||
return 'v0.0.0';
|
||||
}
|
||||
|
||||
@override
|
||||
String get repositoryUrl => null;
|
||||
|
||||
@override
|
||||
Map<String, Object> toJson() {
|
||||
return null;
|
||||
return <String, Object>{};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/ios/devices.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
@ -232,3 +233,4 @@ class MockStdIn extends Mock implements IOSink {
|
||||
}
|
||||
|
||||
class MockStream extends Mock implements Stream<List<int>> {}
|
||||
class MockFlutterVersion extends Mock implements FlutterVersion {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user