Includes frameworkVersion in JSON version output (#23891)
* Include framework version in JSON output and adds test
This commit is contained in:
parent
7342816084
commit
50fb729609
@ -108,6 +108,7 @@ class FlutterVersion {
|
||||
}
|
||||
|
||||
Map<String, Object> toJson() => <String, Object>{
|
||||
'frameworkVersion': frameworkVersion ?? 'unknown',
|
||||
'channel': channel,
|
||||
'repositoryUrl': repositoryUrl ?? 'unknown source',
|
||||
'frameworkRevision': frameworkRevision,
|
||||
|
@ -13,6 +13,7 @@ import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
@ -28,6 +29,7 @@ void main() {
|
||||
MemoryFileSystem fs;
|
||||
Platform platform;
|
||||
FlutterCommandRunner runner;
|
||||
ProcessManager processManager;
|
||||
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
@ -39,11 +41,15 @@ void main() {
|
||||
fs.directory(_kProjectRoot).createSync(recursive: true);
|
||||
fs.currentDirectory = _kProjectRoot;
|
||||
|
||||
platform = FakePlatform(environment: <String, String>{
|
||||
'FLUTTER_ROOT': _kFlutterRoot,
|
||||
});
|
||||
platform = FakePlatform(
|
||||
environment: <String, String>{
|
||||
'FLUTTER_ROOT': _kFlutterRoot,
|
||||
},
|
||||
version: '1 2 3 4 5',
|
||||
);
|
||||
|
||||
runner = createTestCommandRunner(DummyFlutterCommand());
|
||||
processManager = MockProcessManager();
|
||||
});
|
||||
|
||||
group('run', () {
|
||||
@ -73,6 +79,36 @@ void main() {
|
||||
}, 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('git log -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('git log -n 1 --pretty=format:%ar'.split(' '),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync('git describe --match v*.*.* --first-parent --long --tags'.split(' '),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync('git log -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,
|
||||
Platform: () => platform,
|
||||
ProcessManager: () => processManager,
|
||||
}, initializeFlutterRoot: false);
|
||||
});
|
||||
|
||||
group('getRepoPackages', () {
|
||||
setUp(() {
|
||||
fs.directory(fs.path.join(_kFlutterRoot, 'examples'))
|
||||
@ -144,6 +180,12 @@ void main() {
|
||||
});
|
||||
});
|
||||
}
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
|
||||
class FakeFlutterVersion extends FlutterVersion {
|
||||
@override
|
||||
String get frameworkVersion => '0.10.3';
|
||||
}
|
||||
|
||||
class FakeCommand extends FlutterCommand {
|
||||
OutputPreferences preferences;
|
||||
|
Loading…
x
Reference in New Issue
Block a user