2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2017-09-01 02:35:05 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:file/file.dart';
|
|
|
|
import 'package:file/memory.dart';
|
2020-04-22 23:34:12 +00:00
|
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
import 'package:process/process.dart';
|
|
|
|
import 'package:quiver/testing/async.dart';
|
|
|
|
import 'package:platform/platform.dart';
|
|
|
|
|
2020-01-13 18:12:06 +00:00
|
|
|
import 'package:flutter_tools/src/base/bot_detector.dart';
|
2019-10-03 18:08:42 +00:00
|
|
|
import 'package:flutter_tools/src/base/common.dart';
|
2019-10-23 05:05:00 +00:00
|
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
2017-09-01 02:35:05 +00:00
|
|
|
import 'package:flutter_tools/src/base/io.dart';
|
2020-04-22 23:34:12 +00:00
|
|
|
import 'package:flutter_tools/src/base/logger.dart';
|
2019-10-23 05:05:00 +00:00
|
|
|
import 'package:flutter_tools/src/cache.dart';
|
2017-09-01 02:35:05 +00:00
|
|
|
import 'package:flutter_tools/src/dart/pub.dart';
|
2019-10-03 18:08:42 +00:00
|
|
|
import 'package:flutter_tools/src/reporting/reporting.dart';
|
2017-09-01 02:35:05 +00:00
|
|
|
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../../src/common.dart';
|
|
|
|
import '../../src/context.dart';
|
2019-10-03 18:08:42 +00:00
|
|
|
import '../../src/mocks.dart' as mocks;
|
2017-09-01 02:35:05 +00:00
|
|
|
|
|
|
|
void main() {
|
2019-10-05 03:01:04 +00:00
|
|
|
setUpAll(() {
|
2020-04-22 23:34:12 +00:00
|
|
|
Cache.flutterRoot = '';
|
2019-10-05 03:01:04 +00:00
|
|
|
});
|
2017-12-06 21:27:29 +00:00
|
|
|
|
2020-01-03 16:13:03 +00:00
|
|
|
tearDown(() {
|
|
|
|
MockDirectory.findCache = false;
|
|
|
|
});
|
|
|
|
|
2020-04-22 23:34:12 +00:00
|
|
|
testWithoutContext('pub get 69', () async {
|
2017-09-01 02:35:05 +00:00
|
|
|
String error;
|
2017-12-02 00:20:06 +00:00
|
|
|
|
2020-04-22 23:34:12 +00:00
|
|
|
final MockProcessManager processMock = MockProcessManager(69);
|
|
|
|
final BufferLogger logger = BufferLogger.test();
|
|
|
|
final Pub pub = Pub(
|
|
|
|
fileSystem: MockFileSystem(),
|
|
|
|
logger: logger,
|
|
|
|
processManager: processMock,
|
|
|
|
usage: MockUsage(),
|
|
|
|
platform: FakePlatform(
|
|
|
|
environment: const <String, String>{},
|
|
|
|
),
|
|
|
|
botDetector: const BotDetectorAlwaysNo(),
|
|
|
|
);
|
2017-12-02 00:20:06 +00:00
|
|
|
|
2018-09-12 06:29:29 +00:00
|
|
|
FakeAsync().run((FakeAsync time) {
|
2018-03-07 05:36:03 +00:00
|
|
|
expect(processMock.lastPubEnvironment, isNull);
|
2020-04-22 23:34:12 +00:00
|
|
|
expect(logger.statusText, '');
|
2019-10-08 21:53:28 +00:00
|
|
|
pub.get(context: PubContext.flutterTests, checkLastModified: false).then((void value) {
|
2017-09-01 02:35:05 +00:00
|
|
|
error = 'test completed unexpectedly';
|
2017-12-05 22:46:39 +00:00
|
|
|
}, onError: (dynamic thrownError) {
|
|
|
|
error = 'test failed unexpectedly: $thrownError';
|
2017-09-01 02:35:05 +00:00
|
|
|
});
|
|
|
|
time.elapse(const Duration(milliseconds: 500));
|
2020-04-22 23:34:12 +00:00
|
|
|
expect(logger.statusText,
|
2019-05-21 14:38:58 +00:00
|
|
|
'Running "flutter pub get" in /...\n'
|
2019-10-11 02:37:01 +00:00
|
|
|
'pub get failed (server unavailable) -- attempting retry 1 in 1 second...\n',
|
2017-09-01 02:35:05 +00:00
|
|
|
);
|
2018-03-07 05:36:03 +00:00
|
|
|
expect(processMock.lastPubEnvironment, contains('flutter_cli:flutter_tests'));
|
2017-12-05 22:46:39 +00:00
|
|
|
expect(processMock.lastPubCache, isNull);
|
2017-09-01 02:35:05 +00:00
|
|
|
time.elapse(const Duration(milliseconds: 500));
|
2020-04-22 23:34:12 +00:00
|
|
|
expect(logger.statusText,
|
2019-05-21 14:38:58 +00:00
|
|
|
'Running "flutter pub get" in /...\n'
|
2019-10-11 02:37:01 +00:00
|
|
|
'pub get failed (server unavailable) -- attempting retry 1 in 1 second...\n'
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 2 in 2 seconds...\n',
|
2017-09-01 02:35:05 +00:00
|
|
|
);
|
|
|
|
time.elapse(const Duration(seconds: 1));
|
2020-04-22 23:34:12 +00:00
|
|
|
expect(logger.statusText,
|
2019-05-21 14:38:58 +00:00
|
|
|
'Running "flutter pub get" in /...\n'
|
2019-10-11 02:37:01 +00:00
|
|
|
'pub get failed (server unavailable) -- attempting retry 1 in 1 second...\n'
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 2 in 2 seconds...\n',
|
2017-09-01 02:35:05 +00:00
|
|
|
);
|
|
|
|
time.elapse(const Duration(seconds: 100)); // from t=0 to t=100
|
2020-04-22 23:34:12 +00:00
|
|
|
expect(logger.statusText,
|
2019-05-21 14:38:58 +00:00
|
|
|
'Running "flutter pub get" in /...\n'
|
2019-10-11 02:37:01 +00:00
|
|
|
'pub get failed (server unavailable) -- attempting retry 1 in 1 second...\n'
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 2 in 2 seconds...\n'
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 3 in 4 seconds...\n' // at t=1
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 4 in 8 seconds...\n' // at t=5
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 5 in 16 seconds...\n' // at t=13
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 6 in 32 seconds...\n' // at t=29
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 7 in 64 seconds...\n', // at t=61
|
2017-09-01 02:35:05 +00:00
|
|
|
);
|
|
|
|
time.elapse(const Duration(seconds: 200)); // from t=0 to t=200
|
2020-04-22 23:34:12 +00:00
|
|
|
expect(logger.statusText,
|
2019-05-21 14:38:58 +00:00
|
|
|
'Running "flutter pub get" in /...\n'
|
2019-10-11 02:37:01 +00:00
|
|
|
'pub get failed (server unavailable) -- attempting retry 1 in 1 second...\n'
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 2 in 2 seconds...\n'
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 3 in 4 seconds...\n'
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 4 in 8 seconds...\n'
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 5 in 16 seconds...\n'
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 6 in 32 seconds...\n'
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 7 in 64 seconds...\n'
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 8 in 64 seconds...\n' // at t=39
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 9 in 64 seconds...\n' // at t=103
|
|
|
|
'pub get failed (server unavailable) -- attempting retry 10 in 64 seconds...\n', // at t=167
|
2017-09-01 02:35:05 +00:00
|
|
|
);
|
|
|
|
});
|
2020-04-22 23:34:12 +00:00
|
|
|
expect(logger.errorText, isEmpty);
|
2017-09-01 02:35:05 +00:00
|
|
|
expect(error, isNull);
|
2017-12-05 22:46:39 +00:00
|
|
|
});
|
|
|
|
|
2020-04-22 23:34:12 +00:00
|
|
|
testWithoutContext('pub get 66 shows message from pub', () async {
|
|
|
|
final BufferLogger logger = BufferLogger.test();
|
|
|
|
final Pub pub = Pub(
|
|
|
|
platform: FakePlatform(environment: const <String, String>{}),
|
|
|
|
fileSystem: MockFileSystem(),
|
|
|
|
logger: logger,
|
|
|
|
usage: MockUsage(),
|
|
|
|
botDetector: const BotDetectorAlwaysNo(),
|
|
|
|
processManager: MockProcessManager(66, stderr: 'err1\nerr2\nerr3\n', stdout: 'out1\nout2\nout3\n'),
|
|
|
|
);
|
2019-10-11 02:37:01 +00:00
|
|
|
try {
|
|
|
|
await pub.get(context: PubContext.flutterTests, checkLastModified: false);
|
|
|
|
throw AssertionError('pubGet did not fail');
|
|
|
|
} on ToolExit catch (error) {
|
|
|
|
expect(error.message, 'pub get failed (66; err3)');
|
|
|
|
}
|
2020-04-22 23:34:12 +00:00
|
|
|
expect(logger.statusText,
|
2019-10-11 02:37:01 +00:00
|
|
|
'Running "flutter pub get" in /...\n'
|
|
|
|
'out1\n'
|
|
|
|
'out2\n'
|
|
|
|
'out3\n'
|
|
|
|
);
|
2020-04-22 23:34:12 +00:00
|
|
|
expect(logger.errorText,
|
2019-10-11 02:37:01 +00:00
|
|
|
'err1\n'
|
|
|
|
'err2\n'
|
|
|
|
'err3\n'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-22 23:34:12 +00:00
|
|
|
testWithoutContext('pub cache in root is used', () async {
|
2017-12-05 22:46:39 +00:00
|
|
|
String error;
|
2020-04-22 23:34:12 +00:00
|
|
|
final MockProcessManager processMock = MockProcessManager(69);
|
|
|
|
final MockFileSystem fsMock = MockFileSystem();
|
|
|
|
final Pub pub = Pub(
|
|
|
|
platform: FakePlatform(environment: const <String, String>{}),
|
|
|
|
usage: MockUsage(),
|
|
|
|
fileSystem: fsMock,
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: processMock,
|
|
|
|
botDetector: const BotDetectorAlwaysNo(),
|
|
|
|
);
|
2017-12-05 22:46:39 +00:00
|
|
|
|
2018-09-12 06:29:29 +00:00
|
|
|
FakeAsync().run((FakeAsync time) {
|
2017-12-05 22:46:39 +00:00
|
|
|
MockDirectory.findCache = true;
|
2018-03-07 05:36:03 +00:00
|
|
|
expect(processMock.lastPubEnvironment, isNull);
|
2017-12-05 22:46:39 +00:00
|
|
|
expect(processMock.lastPubCache, isNull);
|
2019-10-08 21:53:28 +00:00
|
|
|
pub.get(context: PubContext.flutterTests, checkLastModified: false).then((void value) {
|
2017-12-05 22:46:39 +00:00
|
|
|
error = 'test completed unexpectedly';
|
|
|
|
}, onError: (dynamic thrownError) {
|
|
|
|
error = 'test failed unexpectedly: $thrownError';
|
|
|
|
});
|
|
|
|
time.elapse(const Duration(milliseconds: 500));
|
2020-04-22 23:34:12 +00:00
|
|
|
|
2017-12-06 21:27:29 +00:00
|
|
|
expect(processMock.lastPubCache, equals(fsMock.path.join(Cache.flutterRoot, '.pub-cache')));
|
2017-12-05 22:46:39 +00:00
|
|
|
expect(error, isNull);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-22 23:34:12 +00:00
|
|
|
testWithoutContext('pub cache in environment is used', () async {
|
|
|
|
final MockProcessManager processMock = MockProcessManager(69);
|
|
|
|
final Pub pub = Pub(
|
|
|
|
fileSystem: MockFileSystem(),
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: processMock,
|
|
|
|
usage: MockUsage(),
|
|
|
|
botDetector: const BotDetectorAlwaysNo(),
|
|
|
|
platform: FakePlatform(
|
|
|
|
environment: const <String, String>{
|
|
|
|
'PUB_CACHE': 'custom/pub-cache/path',
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2017-12-05 22:46:39 +00:00
|
|
|
|
2018-09-12 06:29:29 +00:00
|
|
|
FakeAsync().run((FakeAsync time) {
|
2017-12-06 21:27:29 +00:00
|
|
|
MockDirectory.findCache = true;
|
2018-03-07 05:36:03 +00:00
|
|
|
expect(processMock.lastPubEnvironment, isNull);
|
2017-12-05 22:46:39 +00:00
|
|
|
expect(processMock.lastPubCache, isNull);
|
2020-04-22 23:34:12 +00:00
|
|
|
|
|
|
|
String error;
|
2019-10-08 21:53:28 +00:00
|
|
|
pub.get(context: PubContext.flutterTests, checkLastModified: false).then((void value) {
|
2017-12-05 22:46:39 +00:00
|
|
|
error = 'test completed unexpectedly';
|
|
|
|
}, onError: (dynamic thrownError) {
|
|
|
|
error = 'test failed unexpectedly: $thrownError';
|
|
|
|
});
|
|
|
|
time.elapse(const Duration(milliseconds: 500));
|
2020-04-22 23:34:12 +00:00
|
|
|
|
2017-12-06 21:27:29 +00:00
|
|
|
expect(processMock.lastPubCache, equals('custom/pub-cache/path'));
|
2017-12-05 22:46:39 +00:00
|
|
|
expect(error, isNull);
|
|
|
|
});
|
2017-09-01 02:35:05 +00:00
|
|
|
});
|
2019-10-03 18:08:42 +00:00
|
|
|
|
2020-04-22 23:34:12 +00:00
|
|
|
testWithoutContext('analytics sent on success', () async {
|
2019-10-03 18:08:42 +00:00
|
|
|
MockDirectory.findCache = true;
|
2020-04-22 23:34:12 +00:00
|
|
|
final MockUsage usage = MockUsage();
|
|
|
|
final Pub pub = Pub(
|
|
|
|
fileSystem: MockFileSystem(),
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: MockProcessManager(0),
|
|
|
|
botDetector: const BotDetectorAlwaysNo(),
|
|
|
|
usage: usage,
|
|
|
|
platform: FakePlatform(
|
|
|
|
environment: const <String, String>{
|
|
|
|
'PUB_CACHE': 'custom/pub-cache/path',
|
|
|
|
}
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2019-10-08 21:53:28 +00:00
|
|
|
await pub.get(context: PubContext.flutterTests, checkLastModified: false);
|
2020-04-22 23:34:12 +00:00
|
|
|
|
|
|
|
verify(usage.sendEvent('pub-result', 'flutter-tests', label: 'success')).called(1);
|
2019-10-03 18:08:42 +00:00
|
|
|
});
|
|
|
|
|
2020-04-22 23:34:12 +00:00
|
|
|
testWithoutContext('analytics sent on failure', () async {
|
2019-10-03 18:08:42 +00:00
|
|
|
MockDirectory.findCache = true;
|
2020-04-22 23:34:12 +00:00
|
|
|
final MockUsage usage = MockUsage();
|
|
|
|
final Pub pub = Pub(
|
|
|
|
usage: usage,
|
|
|
|
fileSystem: MockFileSystem(),
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: MockProcessManager(1),
|
|
|
|
botDetector: const BotDetectorAlwaysNo(),
|
|
|
|
platform: FakePlatform(
|
|
|
|
environment: const <String, String>{
|
|
|
|
'PUB_CACHE': 'custom/pub-cache/path',
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2019-10-03 18:08:42 +00:00
|
|
|
try {
|
2019-10-08 21:53:28 +00:00
|
|
|
await pub.get(context: PubContext.flutterTests, checkLastModified: false);
|
2019-10-03 18:08:42 +00:00
|
|
|
} on ToolExit {
|
|
|
|
// Ignore.
|
|
|
|
}
|
2020-04-22 23:34:12 +00:00
|
|
|
|
|
|
|
verify(usage.sendEvent('pub-result', 'flutter-tests', label: 'failure')).called(1);
|
2019-10-03 18:08:42 +00:00
|
|
|
});
|
|
|
|
|
2020-04-22 23:34:12 +00:00
|
|
|
testWithoutContext('analytics sent on failed version solve', () async {
|
2019-10-03 18:08:42 +00:00
|
|
|
MockDirectory.findCache = true;
|
2020-04-22 23:34:12 +00:00
|
|
|
final MockUsage usage = MockUsage();
|
|
|
|
final Pub pub = Pub(
|
|
|
|
fileSystem: MockFileSystem(),
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: MockProcessManager(
|
|
|
|
1,
|
|
|
|
stderr: 'version solving failed',
|
|
|
|
),
|
|
|
|
platform: FakePlatform(
|
|
|
|
environment: <String, String>{
|
|
|
|
'PUB_CACHE': 'custom/pub-cache/path',
|
|
|
|
},
|
|
|
|
),
|
|
|
|
usage: usage,
|
|
|
|
botDetector: const BotDetectorAlwaysNo(),
|
|
|
|
);
|
|
|
|
|
2019-10-03 18:08:42 +00:00
|
|
|
try {
|
2019-10-08 21:53:28 +00:00
|
|
|
await pub.get(context: PubContext.flutterTests, checkLastModified: false);
|
2019-10-03 18:08:42 +00:00
|
|
|
} on ToolExit {
|
|
|
|
// Ignore.
|
|
|
|
}
|
2020-04-22 23:34:12 +00:00
|
|
|
|
|
|
|
verify(usage.sendEvent('pub-result', 'flutter-tests', label: 'version-solving-failed')).called(1);
|
2019-10-03 18:08:42 +00:00
|
|
|
});
|
2019-10-23 05:05:00 +00:00
|
|
|
|
2020-04-22 23:34:12 +00:00
|
|
|
testWithoutContext('Pub error handling', () async {
|
|
|
|
final BufferLogger logger = BufferLogger.test();
|
|
|
|
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
2019-10-23 05:05:00 +00:00
|
|
|
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
|
|
|
FakeCommand(
|
|
|
|
command: const <String>[
|
2020-04-22 23:34:12 +00:00
|
|
|
'bin/cache/dart-sdk/bin/pub',
|
2019-10-23 05:05:00 +00:00
|
|
|
'--verbosity=warning',
|
|
|
|
'get',
|
|
|
|
'--no-precompile',
|
|
|
|
],
|
|
|
|
onRun: () {
|
2020-04-22 23:34:12 +00:00
|
|
|
fileSystem.file('.dart_tool/package_config.json')
|
2020-03-05 07:03:26 +00:00
|
|
|
.setLastModifiedSync(DateTime(2002));
|
2019-10-23 05:05:00 +00:00
|
|
|
}
|
|
|
|
),
|
|
|
|
const FakeCommand(
|
|
|
|
command: <String>[
|
2020-04-22 23:34:12 +00:00
|
|
|
'bin/cache/dart-sdk/bin/pub',
|
2019-10-23 05:05:00 +00:00
|
|
|
'--verbosity=warning',
|
|
|
|
'get',
|
|
|
|
'--no-precompile',
|
|
|
|
],
|
|
|
|
),
|
|
|
|
FakeCommand(
|
|
|
|
command: const <String>[
|
2020-04-22 23:34:12 +00:00
|
|
|
'bin/cache/dart-sdk/bin/pub',
|
2019-10-23 05:05:00 +00:00
|
|
|
'--verbosity=warning',
|
|
|
|
'get',
|
|
|
|
'--no-precompile',
|
|
|
|
],
|
|
|
|
onRun: () {
|
2020-04-22 23:34:12 +00:00
|
|
|
fileSystem.file('pubspec.yaml')
|
2020-03-05 07:03:26 +00:00
|
|
|
.setLastModifiedSync(DateTime(2002));
|
2019-10-23 05:05:00 +00:00
|
|
|
}
|
|
|
|
),
|
2019-11-01 02:31:42 +00:00
|
|
|
const FakeCommand(
|
|
|
|
command: <String>[
|
2020-04-22 23:34:12 +00:00
|
|
|
'bin/cache/dart-sdk/bin/pub',
|
2019-11-01 02:31:42 +00:00
|
|
|
'--verbosity=warning',
|
|
|
|
'get',
|
|
|
|
'--no-precompile',
|
|
|
|
],
|
|
|
|
),
|
2019-10-23 05:05:00 +00:00
|
|
|
]);
|
2020-04-22 23:34:12 +00:00
|
|
|
final Pub pub = Pub(
|
|
|
|
usage: MockUsage(),
|
|
|
|
fileSystem: fileSystem,
|
|
|
|
logger: logger,
|
|
|
|
processManager: processManager,
|
|
|
|
platform: FakePlatform(
|
2019-10-23 05:05:00 +00:00
|
|
|
operatingSystem: 'linux', // so that the command executed is consistent
|
|
|
|
environment: <String, String>{},
|
|
|
|
),
|
2020-04-22 23:34:12 +00:00
|
|
|
botDetector: const BotDetectorAlwaysNo()
|
|
|
|
);
|
|
|
|
|
|
|
|
// the good scenario: .packages is old, pub updates the file.
|
|
|
|
fileSystem.file('.dart_tool/package_config.json')
|
|
|
|
..createSync(recursive: true)
|
|
|
|
..setLastModifiedSync(DateTime(2000));
|
|
|
|
fileSystem.file('pubspec.yaml')
|
|
|
|
..createSync()
|
|
|
|
..setLastModifiedSync(DateTime(2001));
|
|
|
|
await pub.get(context: PubContext.flutterTests, checkLastModified: true); // pub sets date of .packages to 2002
|
|
|
|
|
|
|
|
expect(logger.statusText, 'Running "flutter pub get" in /...\n');
|
|
|
|
expect(logger.errorText, isEmpty);
|
|
|
|
expect(fileSystem.file('pubspec.yaml').lastModifiedSync(), DateTime(2001)); // because nothing should touch it
|
|
|
|
expect(fileSystem.file('.dart_tool/package_config.json').lastModifiedSync(), isNot(DateTime(2000))); // because pub changes it to 2002
|
|
|
|
expect(fileSystem.file('.dart_tool/package_config.json').lastModifiedSync(), isNot(DateTime(2002))); // because we set the timestamp again after pub
|
|
|
|
logger.clear();
|
|
|
|
|
|
|
|
// bad scenario 1: pub doesn't update file; doesn't matter, because we do instead
|
|
|
|
fileSystem.file('.dart_tool/package_config.json')
|
|
|
|
.setLastModifiedSync(DateTime(2000));
|
|
|
|
fileSystem.file('pubspec.yaml')
|
|
|
|
.setLastModifiedSync(DateTime(2001));
|
|
|
|
await pub.get(context: PubContext.flutterTests, checkLastModified: true); // pub does nothing
|
|
|
|
|
|
|
|
expect(logger.statusText, 'Running "flutter pub get" in /...\n');
|
|
|
|
expect(logger.errorText, isEmpty);
|
|
|
|
expect(fileSystem.file('pubspec.yaml').lastModifiedSync(), DateTime(2001)); // because nothing should touch it
|
|
|
|
expect(fileSystem.file('.dart_tool/package_config.json').lastModifiedSync(), isNot(DateTime(2000))); // because we set the timestamp
|
|
|
|
expect(fileSystem.file('.dart_tool/package_config.json').lastModifiedSync(), isNot(DateTime(2002))); // just in case FakeProcessManager is buggy
|
|
|
|
logger.clear();
|
|
|
|
|
|
|
|
// bad scenario 2: pub changes pubspec.yaml instead
|
|
|
|
fileSystem.file('.dart_tool/package_config.json')
|
|
|
|
.setLastModifiedSync(DateTime(2000));
|
|
|
|
fileSystem.file('pubspec.yaml')
|
|
|
|
.setLastModifiedSync(DateTime(2001));
|
|
|
|
try {
|
|
|
|
await pub.get(context: PubContext.flutterTests, checkLastModified: true);
|
|
|
|
expect(true, isFalse, reason: 'pub.get did not throw');
|
|
|
|
} on ToolExit catch (error) {
|
|
|
|
expect(error.message, '/: unexpected concurrent modification of pubspec.yaml while running pub.');
|
|
|
|
}
|
|
|
|
expect(logger.statusText, 'Running "flutter pub get" in /...\n');
|
|
|
|
expect(logger.errorText, isEmpty);
|
|
|
|
expect(fileSystem.file('pubspec.yaml').lastModifiedSync(), DateTime(2002)); // because fake pub above touched it
|
|
|
|
expect(fileSystem.file('.dart_tool/package_config.json').lastModifiedSync(), DateTime(2000)); // because nothing touched it
|
|
|
|
|
|
|
|
// bad scenario 3: pubspec.yaml was created in the future
|
|
|
|
fileSystem.file('.dart_tool/package_config.json')
|
|
|
|
.setLastModifiedSync(DateTime(2000));
|
|
|
|
fileSystem.file('pubspec.yaml')
|
|
|
|
.setLastModifiedSync(DateTime(9999));
|
|
|
|
assert(DateTime(9999).isAfter(DateTime.now()));
|
|
|
|
|
|
|
|
await pub.get(context: PubContext.flutterTests, checkLastModified: true); // pub does nothing
|
|
|
|
|
|
|
|
expect(logger.statusText, contains('Running "flutter pub get" in /...\n'));
|
|
|
|
expect(logger.errorText, startsWith(
|
|
|
|
'Warning: File "/pubspec.yaml" was created in the future. Optimizations that rely on '
|
|
|
|
'comparing time stamps will be unreliable. Check your system clock for accuracy.\n'
|
|
|
|
'The timestamp was:'
|
|
|
|
));
|
|
|
|
logger.clear();
|
2019-10-23 05:05:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class BotDetectorAlwaysNo implements BotDetector {
|
|
|
|
const BotDetectorAlwaysNo();
|
2020-04-22 23:34:12 +00:00
|
|
|
|
2019-10-23 05:05:00 +00:00
|
|
|
@override
|
2020-02-12 18:58:02 +00:00
|
|
|
Future<bool> get isRunningOnBot async => false;
|
2017-09-01 02:35:05 +00:00
|
|
|
}
|
|
|
|
|
2018-09-14 19:06:19 +00:00
|
|
|
typedef StartCallback = void Function(List<dynamic> command);
|
2017-09-01 02:35:05 +00:00
|
|
|
|
|
|
|
class MockProcessManager implements ProcessManager {
|
2019-10-03 18:08:42 +00:00
|
|
|
MockProcessManager(this.fakeExitCode, {
|
2019-10-11 02:37:01 +00:00
|
|
|
this.stdout = '',
|
2019-10-03 18:08:42 +00:00
|
|
|
this.stderr = '',
|
|
|
|
});
|
2017-09-01 02:35:05 +00:00
|
|
|
|
|
|
|
final int fakeExitCode;
|
2019-10-11 02:37:01 +00:00
|
|
|
final String stdout;
|
2019-10-03 18:08:42 +00:00
|
|
|
final String stderr;
|
2017-09-01 02:35:05 +00:00
|
|
|
|
2018-03-07 05:36:03 +00:00
|
|
|
String lastPubEnvironment;
|
2017-12-05 22:46:39 +00:00
|
|
|
String lastPubCache;
|
2017-12-02 00:20:06 +00:00
|
|
|
|
2017-09-01 02:35:05 +00:00
|
|
|
@override
|
|
|
|
Future<Process> start(
|
|
|
|
List<dynamic> command, {
|
|
|
|
String workingDirectory,
|
|
|
|
Map<String, String> environment,
|
2018-06-05 06:50:40 +00:00
|
|
|
bool includeParentEnvironment = true,
|
|
|
|
bool runInShell = false,
|
2018-07-20 22:07:24 +00:00
|
|
|
ProcessStartMode mode = ProcessStartMode.normal,
|
2017-09-01 02:35:05 +00:00
|
|
|
}) {
|
2018-03-07 05:36:03 +00:00
|
|
|
lastPubEnvironment = environment['PUB_ENVIRONMENT'];
|
2017-12-05 22:46:39 +00:00
|
|
|
lastPubCache = environment['PUB_CACHE'];
|
2019-10-03 18:08:42 +00:00
|
|
|
return Future<Process>.value(mocks.createMockProcess(
|
|
|
|
exitCode: fakeExitCode,
|
2019-10-11 02:37:01 +00:00
|
|
|
stdout: stdout,
|
2019-10-03 18:08:42 +00:00
|
|
|
stderr: stderr,
|
|
|
|
));
|
2017-09-01 02:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
dynamic noSuchMethod(Invocation invocation) => null;
|
|
|
|
}
|
|
|
|
|
2018-04-10 21:27:53 +00:00
|
|
|
class MockFileSystem extends ForwardingFileSystem {
|
2020-04-22 23:34:12 +00:00
|
|
|
MockFileSystem() : super(MemoryFileSystem.test());
|
2018-04-10 21:27:53 +00:00
|
|
|
|
2017-09-01 02:35:05 +00:00
|
|
|
@override
|
|
|
|
File file(dynamic path) {
|
2018-09-12 06:29:29 +00:00
|
|
|
return MockFile();
|
2017-09-01 02:35:05 +00:00
|
|
|
}
|
2017-12-05 22:46:39 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Directory directory(dynamic path) {
|
2019-11-24 05:54:43 +00:00
|
|
|
return MockDirectory(path as String);
|
2017-12-05 22:46:39 +00:00
|
|
|
}
|
2017-09-01 02:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MockFile implements File {
|
|
|
|
@override
|
2019-02-21 08:27:07 +00:00
|
|
|
Future<RandomAccessFile> open({ FileMode mode = FileMode.read }) async {
|
2018-09-12 06:29:29 +00:00
|
|
|
return MockRandomAccessFile();
|
2017-09-01 02:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool existsSync() => true;
|
|
|
|
|
|
|
|
@override
|
2018-09-12 06:29:29 +00:00
|
|
|
DateTime lastModifiedSync() => DateTime(0);
|
2017-09-01 02:35:05 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
dynamic noSuchMethod(Invocation invocation) => null;
|
|
|
|
}
|
|
|
|
|
2017-12-05 22:46:39 +00:00
|
|
|
class MockDirectory implements Directory {
|
|
|
|
MockDirectory(this.path);
|
|
|
|
|
|
|
|
@override
|
|
|
|
final String path;
|
|
|
|
|
2018-10-04 05:28:07 +00:00
|
|
|
static bool findCache = false;
|
|
|
|
|
2017-12-05 22:46:39 +00:00
|
|
|
@override
|
|
|
|
bool existsSync() => findCache && path.endsWith('.pub-cache');
|
|
|
|
|
|
|
|
@override
|
|
|
|
dynamic noSuchMethod(Invocation invocation) => null;
|
|
|
|
}
|
|
|
|
|
2017-09-01 02:35:05 +00:00
|
|
|
class MockRandomAccessFile extends Mock implements RandomAccessFile {}
|
2019-10-03 18:08:42 +00:00
|
|
|
|
|
|
|
class MockUsage extends Mock implements Usage {}
|