blob: b438fecd3a91e6fdea3b47e10a0d705aafaf0612 [file] [log] [blame]
Yegor93126a82017-04-04 10:45:43 -07001// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:convert';
6
Ian Hickson8f56f6f2017-07-21 16:39:04 -07007import 'package:collection/collection.dart' show ListEquality;
Jonah Williamsa871d592018-11-10 17:02:32 -08008import 'package:flutter_tools/src/base/time.dart';
Yegor93126a82017-04-04 10:45:43 -07009import 'package:mockito/mockito.dart';
10import 'package:process/process.dart';
Yegor93126a82017-04-04 10:45:43 -070011
12import 'package:flutter_tools/src/base/context.dart';
13import 'package:flutter_tools/src/base/io.dart';
14import 'package:flutter_tools/src/base/logger.dart';
15import 'package:flutter_tools/src/cache.dart';
16import 'package:flutter_tools/src/version.dart';
17
Ian Hicksond919e692019-07-13 11:51:44 -070018import '../src/common.dart';
19import '../src/context.dart';
Yegor93126a82017-04-04 10:45:43 -070020
Jonah Williamsa871d592018-11-10 17:02:32 -080021final SystemClock _testClock = SystemClock.fixed(DateTime(2015, 1, 1));
Greg Spencereb35f892018-11-14 16:51:12 -080022final DateTime _stampUpToDate = _testClock.ago(FlutterVersion.checkAgeConsideredUpToDate ~/ 2);
23final DateTime _stampOutOfDate = _testClock.ago(FlutterVersion.checkAgeConsideredUpToDate * 2);
Yegor93126a82017-04-04 10:45:43 -070024
25void main() {
Todd Volkert8d11f5c2018-03-28 10:58:28 -070026 MockProcessManager mockProcessManager;
27 MockCache mockCache;
xster9a0d4cf2017-11-14 18:50:15 -080028
Todd Volkert8d11f5c2018-03-28 10:58:28 -070029 setUp(() {
Alexandre Ardhuind927c932018-09-12 08:29:29 +020030 mockProcessManager = MockProcessManager();
31 mockCache = MockCache();
Todd Volkert8d11f5c2018-03-28 10:58:28 -070032 });
33
Greg Spencereb35f892018-11-14 16:51:12 -080034 for (String channel in FlutterVersion.officialChannels) {
35 DateTime getChannelUpToDateVersion() {
36 return _testClock.ago(FlutterVersion.versionAgeConsideredUpToDate(channel) ~/ 2);
Greg Spencera2ed3ec2018-11-13 17:18:06 -080037 }
38
Greg Spencereb35f892018-11-14 16:51:12 -080039 DateTime getChannelOutOfDateVersion() {
40 return _testClock.ago(FlutterVersion.versionAgeConsideredUpToDate(channel) * 2);
41 }
42
43 group('$FlutterVersion for $channel', () {
44 setUpAll(() {
45 Cache.disableLocking();
46 FlutterVersion.timeToPauseToLetUserReadTheMessage = Duration.zero;
47 });
48
49 testUsingContext('prints nothing when Flutter installation looks fresh', () async {
50 fakeData(
51 mockProcessManager,
52 mockCache,
53 localCommitDate: getChannelUpToDateVersion(),
54 // Server will be pinged because we haven't pinged within last x days
55 expectServerPing: true,
56 remoteCommitDate: getChannelOutOfDateVersion(),
57 expectSetStamp: true,
58 channel: channel,
59 );
60 await FlutterVersion.instance.checkFlutterVersionFreshness();
61 _expectVersionMessage('');
62 }, overrides: <Type, Generator>{
63 FlutterVersion: () => FlutterVersion(_testClock),
64 ProcessManager: () => mockProcessManager,
65 Cache: () => mockCache,
66 });
67
68 testUsingContext('prints nothing when Flutter installation looks out-of-date but is actually up-to-date', () async {
69 fakeData(
70 mockProcessManager,
71 mockCache,
72 localCommitDate: getChannelOutOfDateVersion(),
73 stamp: VersionCheckStamp(
74 lastTimeVersionWasChecked: _stampOutOfDate,
75 lastKnownRemoteVersion: getChannelOutOfDateVersion(),
76 ),
77 remoteCommitDate: getChannelOutOfDateVersion(),
78 expectSetStamp: true,
79 expectServerPing: true,
80 channel: channel,
81 );
82 final FlutterVersion version = FlutterVersion.instance;
83
84 await version.checkFlutterVersionFreshness();
85 _expectVersionMessage('');
86 }, overrides: <Type, Generator>{
87 FlutterVersion: () => FlutterVersion(_testClock),
88 ProcessManager: () => mockProcessManager,
89 Cache: () => mockCache,
90 });
91
92 testUsingContext('does not ping server when version stamp is up-to-date', () async {
93 fakeData(
94 mockProcessManager,
95 mockCache,
96 localCommitDate: getChannelOutOfDateVersion(),
97 stamp: VersionCheckStamp(
98 lastTimeVersionWasChecked: _stampUpToDate,
99 lastKnownRemoteVersion: getChannelUpToDateVersion(),
100 ),
101 expectSetStamp: true,
102 channel: channel,
103 );
104
105 final FlutterVersion version = FlutterVersion.instance;
106 await version.checkFlutterVersionFreshness();
107 _expectVersionMessage(FlutterVersion.newVersionAvailableMessage());
108 }, overrides: <Type, Generator>{
109 FlutterVersion: () => FlutterVersion(_testClock),
110 ProcessManager: () => mockProcessManager,
111 Cache: () => mockCache,
112 });
113
114 testUsingContext('does not print warning if printed recently', () async {
115 fakeData(
116 mockProcessManager,
117 mockCache,
118 localCommitDate: getChannelOutOfDateVersion(),
119 stamp: VersionCheckStamp(
120 lastTimeVersionWasChecked: _stampUpToDate,
121 lastKnownRemoteVersion: getChannelUpToDateVersion(),
122 ),
123 expectSetStamp: true,
124 channel: channel,
125 );
126
127 final FlutterVersion version = FlutterVersion.instance;
128 await version.checkFlutterVersionFreshness();
129 _expectVersionMessage(FlutterVersion.newVersionAvailableMessage());
130 expect((await VersionCheckStamp.load()).lastTimeWarningWasPrinted, _testClock.now());
131
132 await version.checkFlutterVersionFreshness();
133 _expectVersionMessage('');
134 }, overrides: <Type, Generator>{
135 FlutterVersion: () => FlutterVersion(_testClock),
136 ProcessManager: () => mockProcessManager,
137 Cache: () => mockCache,
138 });
139
140 testUsingContext('pings server when version stamp is missing then does not', () async {
141 fakeData(
142 mockProcessManager,
143 mockCache,
144 localCommitDate: getChannelOutOfDateVersion(),
145 remoteCommitDate: getChannelUpToDateVersion(),
146 expectSetStamp: true,
147 expectServerPing: true,
148 channel: channel,
149 );
150 final FlutterVersion version = FlutterVersion.instance;
151
152 await version.checkFlutterVersionFreshness();
153 _expectVersionMessage(FlutterVersion.newVersionAvailableMessage());
154
155 // Immediate subsequent check is not expected to ping the server.
156 fakeData(
157 mockProcessManager,
158 mockCache,
159 localCommitDate: getChannelOutOfDateVersion(),
160 stamp: await VersionCheckStamp.load(),
161 channel: channel,
162 );
163 await version.checkFlutterVersionFreshness();
164 _expectVersionMessage('');
165 }, overrides: <Type, Generator>{
166 FlutterVersion: () => FlutterVersion(_testClock),
167 ProcessManager: () => mockProcessManager,
168 Cache: () => mockCache,
169 });
170
171 testUsingContext('pings server when version stamp is out-of-date', () async {
172 fakeData(
173 mockProcessManager,
174 mockCache,
175 localCommitDate: getChannelOutOfDateVersion(),
176 stamp: VersionCheckStamp(
177 lastTimeVersionWasChecked: _stampOutOfDate,
178 lastKnownRemoteVersion: _testClock.ago(const Duration(days: 2)),
179 ),
180 remoteCommitDate: getChannelUpToDateVersion(),
181 expectSetStamp: true,
182 expectServerPing: true,
183 channel: channel,
184 );
185 final FlutterVersion version = FlutterVersion.instance;
186
187 await version.checkFlutterVersionFreshness();
188 _expectVersionMessage(FlutterVersion.newVersionAvailableMessage());
189 }, overrides: <Type, Generator>{
190 FlutterVersion: () => FlutterVersion(_testClock),
191 ProcessManager: () => mockProcessManager,
192 Cache: () => mockCache,
193 });
194
195 testUsingContext('does not print warning when unable to connect to server if not out of date', () async {
196 fakeData(
197 mockProcessManager,
198 mockCache,
199 localCommitDate: getChannelUpToDateVersion(),
200 errorOnFetch: true,
201 expectServerPing: true,
202 expectSetStamp: true,
203 channel: channel,
204 );
205 final FlutterVersion version = FlutterVersion.instance;
206
207 await version.checkFlutterVersionFreshness();
208 _expectVersionMessage('');
209 }, overrides: <Type, Generator>{
210 FlutterVersion: () => FlutterVersion(_testClock),
211 ProcessManager: () => mockProcessManager,
212 Cache: () => mockCache,
213 });
214
215 testUsingContext('prints warning when unable to connect to server if really out of date', () async {
216 fakeData(
217 mockProcessManager,
218 mockCache,
219 localCommitDate: getChannelOutOfDateVersion(),
220 errorOnFetch: true,
221 expectServerPing: true,
222 expectSetStamp: true,
223 channel: channel,
224 );
225 final FlutterVersion version = FlutterVersion.instance;
226
227 await version.checkFlutterVersionFreshness();
228 _expectVersionMessage(FlutterVersion.versionOutOfDateMessage(_testClock.now().difference(getChannelOutOfDateVersion())));
229 }, overrides: <Type, Generator>{
230 FlutterVersion: () => FlutterVersion(_testClock),
231 ProcessManager: () => mockProcessManager,
232 Cache: () => mockCache,
233 });
234
235 testUsingContext('versions comparison', () async {
236 fakeData(
237 mockProcessManager,
238 mockCache,
239 localCommitDate: getChannelOutOfDateVersion(),
240 errorOnFetch: true,
241 expectServerPing: true,
242 expectSetStamp: true,
243 channel: channel,
244 );
245 final FlutterVersion version = FlutterVersion.instance;
246
247 when(mockProcessManager.runSync(
248 <String>['git', 'merge-base', '--is-ancestor', 'abcdef', '123456'],
249 workingDirectory: anyNamed('workingDirectory'),
250 )).thenReturn(ProcessResult(1, 0, '', ''));
251
252 expect(
253 version.checkRevisionAncestry(
254 tentativeDescendantRevision: '123456',
255 tentativeAncestorRevision: 'abcdef',
256 ),
257 true);
258
259 verify(mockProcessManager.runSync(
260 <String>['git', 'merge-base', '--is-ancestor', 'abcdef', '123456'],
261 workingDirectory: anyNamed('workingDirectory'),
262 ));
263 }, overrides: <Type, Generator>{
264 FlutterVersion: () => FlutterVersion(_testClock),
265 ProcessManager: () => mockProcessManager,
266 });
Greg Spencera2ed3ec2018-11-13 17:18:06 -0800267 });
268
Greg Spencereb35f892018-11-14 16:51:12 -0800269 group('$VersionCheckStamp for $channel', () {
270 void _expectDefault(VersionCheckStamp stamp) {
271 expect(stamp.lastKnownRemoteVersion, isNull);
272 expect(stamp.lastTimeVersionWasChecked, isNull);
273 expect(stamp.lastTimeWarningWasPrinted, isNull);
274 }
Greg Spencera2ed3ec2018-11-13 17:18:06 -0800275
Greg Spencereb35f892018-11-14 16:51:12 -0800276 testUsingContext('loads blank when stamp file missing', () async {
277 fakeData(mockProcessManager, mockCache, channel: channel);
278 _expectDefault(await VersionCheckStamp.load());
279 }, overrides: <Type, Generator>{
280 FlutterVersion: () => FlutterVersion(_testClock),
281 ProcessManager: () => mockProcessManager,
282 Cache: () => mockCache,
283 });
Greg Spencera2ed3ec2018-11-13 17:18:06 -0800284
Greg Spencereb35f892018-11-14 16:51:12 -0800285 testUsingContext('loads blank when stamp file is malformed JSON', () async {
286 fakeData(mockProcessManager, mockCache, stampJson: '<', channel: channel);
287 _expectDefault(await VersionCheckStamp.load());
288 }, overrides: <Type, Generator>{
289 FlutterVersion: () => FlutterVersion(_testClock),
290 ProcessManager: () => mockProcessManager,
291 Cache: () => mockCache,
292 });
293
294 testUsingContext('loads blank when stamp file is well-formed but invalid JSON', () async {
295 fakeData(
296 mockProcessManager,
297 mockCache,
298 stampJson: '[]',
299 channel: channel,
300 );
301 _expectDefault(await VersionCheckStamp.load());
302 }, overrides: <Type, Generator>{
303 FlutterVersion: () => FlutterVersion(_testClock),
304 ProcessManager: () => mockProcessManager,
305 Cache: () => mockCache,
306 });
307
308 testUsingContext('loads valid JSON', () async {
309 fakeData(
310 mockProcessManager,
311 mockCache,
312 stampJson: '''
Yegor5efbe052017-04-10 13:21:02 -0700313 {
Jonah Williamsa871d592018-11-10 17:02:32 -0800314 "lastKnownRemoteVersion": "${_testClock.ago(const Duration(days: 1))}",
315 "lastTimeVersionWasChecked": "${_testClock.ago(const Duration(days: 2))}",
Yegor5efbe052017-04-10 13:21:02 -0700316 "lastTimeWarningWasPrinted": "${_testClock.now()}"
317 }
Greg Spencereb35f892018-11-14 16:51:12 -0800318 ''',
319 channel: channel,
320 );
Yegor5efbe052017-04-10 13:21:02 -0700321
Greg Spencereb35f892018-11-14 16:51:12 -0800322 final VersionCheckStamp stamp = await VersionCheckStamp.load();
323 expect(stamp.lastKnownRemoteVersion, _testClock.ago(const Duration(days: 1)));
324 expect(stamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
325 expect(stamp.lastTimeWarningWasPrinted, _testClock.now());
326 }, overrides: <Type, Generator>{
327 FlutterVersion: () => FlutterVersion(_testClock),
328 ProcessManager: () => mockProcessManager,
329 Cache: () => mockCache,
330 });
331
332 testUsingContext('stores version stamp', () async {
333 fakeData(
334 mockProcessManager,
335 mockCache,
336 expectSetStamp: true,
337 channel: channel,
338 );
339
340 _expectDefault(await VersionCheckStamp.load());
341
342 final VersionCheckStamp stamp = VersionCheckStamp(
343 lastKnownRemoteVersion: _testClock.ago(const Duration(days: 1)),
344 lastTimeVersionWasChecked: _testClock.ago(const Duration(days: 2)),
345 lastTimeWarningWasPrinted: _testClock.now(),
346 );
347 await stamp.store();
348
349 final VersionCheckStamp storedStamp = await VersionCheckStamp.load();
350 expect(storedStamp.lastKnownRemoteVersion, _testClock.ago(const Duration(days: 1)));
351 expect(storedStamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
352 expect(storedStamp.lastTimeWarningWasPrinted, _testClock.now());
353 }, overrides: <Type, Generator>{
354 FlutterVersion: () => FlutterVersion(_testClock),
355 ProcessManager: () => mockProcessManager,
356 Cache: () => mockCache,
357 });
358
359 testUsingContext('overwrites individual fields', () async {
360 fakeData(
361 mockProcessManager,
362 mockCache,
363 expectSetStamp: true,
364 channel: channel,
365 );
366
367 _expectDefault(await VersionCheckStamp.load());
368
369 final VersionCheckStamp stamp = VersionCheckStamp(
370 lastKnownRemoteVersion: _testClock.ago(const Duration(days: 10)),
371 lastTimeVersionWasChecked: _testClock.ago(const Duration(days: 9)),
372 lastTimeWarningWasPrinted: _testClock.ago(const Duration(days: 8)),
373 );
374 await stamp.store(
375 newKnownRemoteVersion: _testClock.ago(const Duration(days: 1)),
376 newTimeVersionWasChecked: _testClock.ago(const Duration(days: 2)),
377 newTimeWarningWasPrinted: _testClock.now(),
378 );
379
380 final VersionCheckStamp storedStamp = await VersionCheckStamp.load();
381 expect(storedStamp.lastKnownRemoteVersion, _testClock.ago(const Duration(days: 1)));
382 expect(storedStamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
383 expect(storedStamp.lastTimeWarningWasPrinted, _testClock.now());
384 }, overrides: <Type, Generator>{
385 FlutterVersion: () => FlutterVersion(_testClock),
386 ProcessManager: () => mockProcessManager,
387 Cache: () => mockCache,
388 });
Yegor5efbe052017-04-10 13:21:02 -0700389 });
Greg Spencereb35f892018-11-14 16:51:12 -0800390 }
Ian Hicksona07c9a12019-03-08 19:26:34 -0800391
392 testUsingContext('GitTagVersion', () {
393 const String hash = 'abcdef';
394 expect(GitTagVersion.parse('v1.2.3-4-g$hash').frameworkVersionFor(hash), '1.2.4-pre.4');
395 expect(GitTagVersion.parse('v98.76.54-32-g$hash').frameworkVersionFor(hash), '98.76.55-pre.32');
396 expect(GitTagVersion.parse('v10.20.30-0-g$hash').frameworkVersionFor(hash), '10.20.30');
Jonah Williamseb996af2019-05-07 10:11:00 -0700397 expect(GitTagVersion.parse('v1.2.3+hotfix.1-4-g$hash').frameworkVersionFor(hash), '1.2.3+hotfix.2-pre.4');
398 expect(GitTagVersion.parse('v7.2.4+hotfix.8-0-g$hash').frameworkVersionFor(hash), '7.2.4+hotfix.8');
Ian Hicksona07c9a12019-03-08 19:26:34 -0800399 expect(testLogger.traceText, '');
400 expect(GitTagVersion.parse('x1.2.3-4-g$hash').frameworkVersionFor(hash), '0.0.0-unknown');
401 expect(GitTagVersion.parse('v1.0.0-unknown-0-g$hash').frameworkVersionFor(hash), '0.0.0-unknown');
402 expect(GitTagVersion.parse('beta-1-g$hash').frameworkVersionFor(hash), '0.0.0-unknown');
403 expect(GitTagVersion.parse('v1.2.3-4-gx$hash').frameworkVersionFor(hash), '0.0.0-unknown');
404 expect(testLogger.statusText, '');
405 expect(testLogger.errorText, '');
Alexandre Ardhuinbfa1d252019-03-23 00:02:21 +0100406 expect(
407 testLogger.traceText,
Ian Hicksona07c9a12019-03-08 19:26:34 -0800408 'Could not interpret results of "git describe": x1.2.3-4-gabcdef\n'
409 'Could not interpret results of "git describe": v1.0.0-unknown-0-gabcdef\n'
410 'Could not interpret results of "git describe": beta-1-gabcdef\n'
Alexandre Ardhuinbfa1d252019-03-23 00:02:21 +0100411 'Could not interpret results of "git describe": v1.2.3-4-gxabcdef\n',
Ian Hicksona07c9a12019-03-08 19:26:34 -0800412 );
413 });
Yegor93126a82017-04-04 10:45:43 -0700414}
415
416void _expectVersionMessage(String message) {
Jonah Williams0acd3e62019-04-25 15:51:08 -0700417 final BufferLogger logger = context.get<Logger>();
Yegor93126a82017-04-04 10:45:43 -0700418 expect(logger.statusText.trim(), message.trim());
Yegor5efbe052017-04-10 13:21:02 -0700419 logger.clear();
Yegor93126a82017-04-04 10:45:43 -0700420}
421
Todd Volkert8d11f5c2018-03-28 10:58:28 -0700422void fakeData(
423 ProcessManager pm,
424 Cache cache, {
Yegor5efbe052017-04-10 13:21:02 -0700425 DateTime localCommitDate,
Yegor93126a82017-04-04 10:45:43 -0700426 DateTime remoteCommitDate,
Yegor5efbe052017-04-10 13:21:02 -0700427 VersionCheckStamp stamp,
428 String stampJson,
Alexandre Ardhuin09276be2018-06-05 08:50:40 +0200429 bool errorOnFetch = false,
430 bool expectSetStamp = false,
431 bool expectServerPing = false,
Greg Spencereb35f892018-11-14 16:51:12 -0800432 String channel = 'master',
Yegor93126a82017-04-04 10:45:43 -0700433}) {
Yegor93126a82017-04-04 10:45:43 -0700434 ProcessResult success(String standardOutput) {
Alexandre Ardhuind927c932018-09-12 08:29:29 +0200435 return ProcessResult(1, 0, standardOutput, '');
Yegor93126a82017-04-04 10:45:43 -0700436 }
437
438 ProcessResult failure(int exitCode) {
Alexandre Ardhuind927c932018-09-12 08:29:29 +0200439 return ProcessResult(1, exitCode, '', 'error');
Yegor93126a82017-04-04 10:45:43 -0700440 }
441
442 when(cache.getStampFor(any)).thenAnswer((Invocation invocation) {
Greg Spencereb35f892018-11-14 16:51:12 -0800443 expect(invocation.positionalArguments.single, VersionCheckStamp.flutterVersionCheckStampFile);
Yegor93126a82017-04-04 10:45:43 -0700444
Greg Spencereb35f892018-11-14 16:51:12 -0800445 if (stampJson != null) {
Yegor5efbe052017-04-10 13:21:02 -0700446 return stampJson;
Greg Spencereb35f892018-11-14 16:51:12 -0800447 }
Yegor93126a82017-04-04 10:45:43 -0700448
Greg Spencereb35f892018-11-14 16:51:12 -0800449 if (stamp != null) {
Jason Simmons466d1542018-03-12 11:06:32 -0700450 return json.encode(stamp.toJson());
Greg Spencereb35f892018-11-14 16:51:12 -0800451 }
Yegor93126a82017-04-04 10:45:43 -0700452
Yegor5efbe052017-04-10 13:21:02 -0700453 return null;
Yegor93126a82017-04-04 10:45:43 -0700454 });
455
456 when(cache.setStampFor(any, any)).thenAnswer((Invocation invocation) {
Greg Spencereb35f892018-11-14 16:51:12 -0800457 expect(invocation.positionalArguments.first, VersionCheckStamp.flutterVersionCheckStampFile);
Yegor93126a82017-04-04 10:45:43 -0700458
459 if (expectSetStamp) {
Jason Simmons466d1542018-03-12 11:06:32 -0700460 stamp = VersionCheckStamp.fromJson(json.decode(invocation.positionalArguments[1]));
Yegor93126a82017-04-04 10:45:43 -0700461 return null;
462 }
463
Alexandre Ardhuind927c932018-09-12 08:29:29 +0200464 throw StateError('Unexpected call to Cache.setStampFor(${invocation.positionalArguments}, ${invocation.namedArguments})');
Yegor93126a82017-04-04 10:45:43 -0700465 });
466
Sam Rawlins2329cb72018-04-09 12:43:31 -0700467 final Answering<ProcessResult> syncAnswer = (Invocation invocation) {
∂ω∂4277f362019-08-21 23:55:57 +0300468 bool argsAre(String a1, [ String a2, String a3, String a4, String a5, String a6, String a7, String a8, String a9 ]) {
Alexandre Ardhuineda03e22018-08-02 12:02:32 +0200469 const ListEquality<String> equality = ListEquality<String>();
Yegor93126a82017-04-04 10:45:43 -0700470 final List<String> args = invocation.positionalArguments.single;
∂ω∂4277f362019-08-21 23:55:57 +0300471 final List<String> expectedArgs = <String>[a1, a2, a3, a4, a5, a6, a7, a8, a9].where((String arg) => arg != null).toList();
Yegor93126a82017-04-04 10:45:43 -0700472 return equality.equals(args, expectedArgs);
473 }
474
∂ω∂4277f362019-08-21 23:55:57 +0300475 bool listArgsAre(List<String> a) {
476 return Function.apply(argsAre, a);
477 }
478
479 if (listArgsAre(FlutterVersion.gitLog(<String>['-n', '1', '--pretty=format:%ad', '--date=iso']))) {
Yegor93126a82017-04-04 10:45:43 -0700480 return success(localCommitDate.toString());
481 } else if (argsAre('git', 'remote')) {
482 return success('');
483 } else if (argsAre('git', 'remote', 'add', '__flutter_version_check__', 'https://github.com/flutter/flutter.git')) {
484 return success('');
Greg Spencereb35f892018-11-14 16:51:12 -0800485 } else if (argsAre('git', 'fetch', '__flutter_version_check__', channel)) {
486 if (!expectServerPing) {
Yegor5efbe052017-04-10 13:21:02 -0700487 fail('Did not expect server ping');
Greg Spencereb35f892018-11-14 16:51:12 -0800488 }
Yegor93126a82017-04-04 10:45:43 -0700489 return errorOnFetch ? failure(128) : success('');
∂ω∂4277f362019-08-21 23:55:57 +0300490 // Careful here! argsAre accepts 9 arguments and FlutterVersion.gitLog adds 4.
491 } else if (remoteCommitDate != null && listArgsAre(FlutterVersion.gitLog(<String>['__flutter_version_check__/$channel', '-n', '1', '--pretty=format:%ad', '--date=iso']))) {
Yegor93126a82017-04-04 10:45:43 -0700492 return success(remoteCommitDate.toString());
493 }
494
Alexandre Ardhuind927c932018-09-12 08:29:29 +0200495 throw StateError('Unexpected call to ProcessManager.run(${invocation.positionalArguments}, ${invocation.namedArguments})');
Yegor93126a82017-04-04 10:45:43 -0700496 };
497
Sam Rawlinsfba81d02018-05-31 08:24:26 -0700498 when(pm.runSync(any, workingDirectory: anyNamed('workingDirectory'))).thenAnswer(syncAnswer);
499 when(pm.run(any, workingDirectory: anyNamed('workingDirectory'))).thenAnswer((Invocation invocation) async {
Yegor93126a82017-04-04 10:45:43 -0700500 return syncAnswer(invocation);
501 });
Alexander Aprelev7ebf2722018-07-12 14:59:22 -0700502
503 when(pm.runSync(
504 <String>['git', 'rev-parse', '--abbrev-ref', '--symbolic', '@{u}'],
505 workingDirectory: anyNamed('workingDirectory'),
506 environment: anyNamed('environment'),
Greg Spencereb35f892018-11-14 16:51:12 -0800507 )).thenReturn(ProcessResult(101, 0, channel, ''));
Alexander Aprelev7ebf2722018-07-12 14:59:22 -0700508 when(pm.runSync(
509 <String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
510 workingDirectory: anyNamed('workingDirectory'),
511 environment: anyNamed('environment'),
Alexandre Ardhuind927c932018-09-12 08:29:29 +0200512 )).thenReturn(ProcessResult(102, 0, 'branch', ''));
Alexander Aprelev7ebf2722018-07-12 14:59:22 -0700513 when(pm.runSync(
∂ω∂4277f362019-08-21 23:55:57 +0300514 FlutterVersion.gitLog(<String>['-n', '1', '--pretty=format:%H']),
Alexander Aprelev7ebf2722018-07-12 14:59:22 -0700515 workingDirectory: anyNamed('workingDirectory'),
516 environment: anyNamed('environment'),
Alexandre Ardhuind927c932018-09-12 08:29:29 +0200517 )).thenReturn(ProcessResult(103, 0, '1234abcd', ''));
Alexander Aprelev7ebf2722018-07-12 14:59:22 -0700518 when(pm.runSync(
∂ω∂4277f362019-08-21 23:55:57 +0300519 FlutterVersion.gitLog(<String>['-n', '1', '--pretty=format:%ar']),
Alexander Aprelev7ebf2722018-07-12 14:59:22 -0700520 workingDirectory: anyNamed('workingDirectory'),
521 environment: anyNamed('environment'),
Alexandre Ardhuind927c932018-09-12 08:29:29 +0200522 )).thenReturn(ProcessResult(104, 0, '1 second ago', ''));
Alexander Aprelev7ebf2722018-07-12 14:59:22 -0700523 when(pm.runSync(
524 <String>['git', 'describe', '--match', 'v*.*.*', '--first-parent', '--long', '--tags'],
525 workingDirectory: anyNamed('workingDirectory'),
526 environment: anyNamed('environment'),
Alexandre Ardhuind927c932018-09-12 08:29:29 +0200527 )).thenReturn(ProcessResult(105, 0, 'v0.1.2-3-1234abcd', ''));
Yegor93126a82017-04-04 10:45:43 -0700528}
529
530class MockProcessManager extends Mock implements ProcessManager {}
Greg Spencereb35f892018-11-14 16:51:12 -0800531
Yegor93126a82017-04-04 10:45:43 -0700532class MockCache extends Mock implements Cache {}