mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add a Flutter version comparison function (#12959)
* add git version comparison function * use [] in dartdoc * Make method instance method
This commit is contained in:
parent
473d75a6e3
commit
9a0d4cf75b
@ -167,6 +167,20 @@ class FlutterVersion {
|
||||
return _branch;
|
||||
}
|
||||
|
||||
/// Returns true if `tentativeDescendantRevision` is a direct descendant to
|
||||
/// the `tentativeAncestorRevision` revision on the Flutter framework repo
|
||||
/// tree.
|
||||
bool checkRevisionAncestry({
|
||||
String tentativeDescendantRevision,
|
||||
String tentativeAncestorRevision,
|
||||
}) {
|
||||
final ProcessResult result = processManager.runSync(
|
||||
<String>['git', 'merge-base', '--is-ancestor', tentativeAncestorRevision, tentativeDescendantRevision],
|
||||
workingDirectory: Cache.flutterRoot,
|
||||
);
|
||||
return result.exitCode == 0;
|
||||
}
|
||||
|
||||
/// The amount of time we wait before pinging the server to check for the
|
||||
/// availability of a newer version of Flutter.
|
||||
@visibleForTesting
|
||||
|
||||
@ -26,11 +26,17 @@ final DateTime _stampOutOfDate = _testClock.agoBy(FlutterVersion.kCheckAgeConsid
|
||||
|
||||
void main() {
|
||||
group('$FlutterVersion', () {
|
||||
ProcessManager mockProcessManager;
|
||||
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
FlutterVersion.kPauseToLetUserReadTheMessage = Duration.ZERO;
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
mockProcessManager = new MockProcessManager();
|
||||
});
|
||||
|
||||
testFlutterVersion('prints nothing when Flutter installation looks fresh', () async {
|
||||
fakeData(localCommitDate: _upToDateVersion);
|
||||
await FlutterVersion.instance.checkFlutterVersionFreshness();
|
||||
@ -143,6 +149,30 @@ void main() {
|
||||
await version.checkFlutterVersionFreshness();
|
||||
_expectVersionMessage('');
|
||||
});
|
||||
|
||||
testUsingContext('versions comparison', () async {
|
||||
when(mockProcessManager.runSync(
|
||||
<String>['git', 'merge-base', '--is-ancestor', 'abcdef', '123456'],
|
||||
workingDirectory: any,
|
||||
)).thenReturn(new ProcessResult(1, 0, '', ''));
|
||||
|
||||
expect(
|
||||
FlutterVersion.instance.checkRevisionAncestry(
|
||||
tentativeDescendantRevision: '123456',
|
||||
tentativeAncestorRevision: 'abcdef',
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
verify(mockProcessManager.runSync(
|
||||
<String>['git', 'merge-base', '--is-ancestor', 'abcdef', '123456'],
|
||||
workingDirectory: any,
|
||||
));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
FlutterVersion: () => new FlutterVersion(_testClock),
|
||||
ProcessManager: () => mockProcessManager,
|
||||
});
|
||||
});
|
||||
|
||||
group('$VersionCheckStamp', () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user