2016-12-15 23:05:15 +00:00
|
|
|
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-01-26 23:43:28 +00:00
|
|
|
import 'package:file/memory.dart';
|
|
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
|
|
|
import 'package:flutter_tools/src/cache.dart';
|
|
|
|
import 'package:flutter_tools/src/commands/devices.dart';
|
2016-12-15 23:05:15 +00:00
|
|
|
import 'package:flutter_tools/src/dart/dependencies.dart';
|
|
|
|
import 'package:flutter_tools/src/dependency_checker.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'src/common.dart';
|
|
|
|
import 'src/context.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
group('DependencyChecker', () {
|
2017-03-10 17:39:01 +00:00
|
|
|
final String dataPath = fs.path.join(
|
|
|
|
getFlutterRoot(),
|
|
|
|
'packages',
|
|
|
|
'flutter_tools',
|
|
|
|
'test',
|
|
|
|
'data',
|
|
|
|
'dart_dependencies_test',
|
|
|
|
);
|
|
|
|
|
2017-02-21 23:11:37 +00:00
|
|
|
FileSystem testFileSystem;
|
2017-01-26 23:43:28 +00:00
|
|
|
|
2017-03-10 17:39:01 +00:00
|
|
|
setUpAll(() {
|
2017-01-26 23:43:28 +00:00
|
|
|
Cache.disableLocking();
|
2017-03-10 17:39:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setUp(() {
|
2017-01-26 23:43:28 +00:00
|
|
|
testFileSystem = new MemoryFileSystem();
|
|
|
|
});
|
|
|
|
|
2016-12-15 23:05:15 +00:00
|
|
|
testUsingContext('good', () {
|
2017-02-14 01:45:50 +00:00
|
|
|
final String testPath = fs.path.join(dataPath, 'good');
|
|
|
|
final String mainPath = fs.path.join(testPath, 'main.dart');
|
|
|
|
final String fooPath = fs.path.join(testPath, 'foo.dart');
|
|
|
|
final String barPath = fs.path.join(testPath, 'lib', 'bar.dart');
|
|
|
|
final String packagesPath = fs.path.join(testPath, '.packages');
|
2017-03-04 01:50:46 +00:00
|
|
|
final DartDependencySetBuilder builder =
|
2017-03-07 21:09:48 +00:00
|
|
|
new DartDependencySetBuilder(mainPath, packagesPath);
|
2017-03-04 01:50:46 +00:00
|
|
|
final DependencyChecker dependencyChecker =
|
2016-12-15 23:05:15 +00:00
|
|
|
new DependencyChecker(builder, null);
|
|
|
|
|
|
|
|
// Set file modification time on all dependencies to be in the past.
|
2017-03-04 01:50:46 +00:00
|
|
|
final DateTime baseTime = new DateTime.now();
|
2016-12-15 23:05:15 +00:00
|
|
|
updateFileModificationTime(packagesPath, baseTime, -10);
|
|
|
|
updateFileModificationTime(mainPath, baseTime, -10);
|
|
|
|
updateFileModificationTime(fooPath, baseTime, -10);
|
|
|
|
updateFileModificationTime(barPath, baseTime, -10);
|
|
|
|
expect(dependencyChecker.check(baseTime), isFalse);
|
|
|
|
|
|
|
|
// Set .packages file modification time to be in the future.
|
|
|
|
updateFileModificationTime(packagesPath, baseTime, 20);
|
|
|
|
expect(dependencyChecker.check(baseTime), isTrue);
|
|
|
|
|
|
|
|
// Reset .packages file modification time.
|
|
|
|
updateFileModificationTime(packagesPath, baseTime, 0);
|
|
|
|
expect(dependencyChecker.check(baseTime), isFalse);
|
|
|
|
|
|
|
|
// Set 'package:self/bar.dart' file modification time to be in the future.
|
|
|
|
updateFileModificationTime(barPath, baseTime, 10);
|
|
|
|
expect(dependencyChecker.check(baseTime), isTrue);
|
2017-03-02 18:57:27 +00:00
|
|
|
});
|
2017-02-21 23:11:37 +00:00
|
|
|
|
2016-12-15 23:05:15 +00:00
|
|
|
testUsingContext('syntax error', () {
|
2017-02-14 01:45:50 +00:00
|
|
|
final String testPath = fs.path.join(dataPath, 'syntax_error');
|
|
|
|
final String mainPath = fs.path.join(testPath, 'main.dart');
|
|
|
|
final String fooPath = fs.path.join(testPath, 'foo.dart');
|
|
|
|
final String packagesPath = fs.path.join(testPath, '.packages');
|
2016-12-15 23:05:15 +00:00
|
|
|
|
2017-03-04 01:50:46 +00:00
|
|
|
final DartDependencySetBuilder builder =
|
2017-03-07 21:09:48 +00:00
|
|
|
new DartDependencySetBuilder(mainPath, packagesPath);
|
2017-03-04 01:50:46 +00:00
|
|
|
final DependencyChecker dependencyChecker =
|
2016-12-15 23:05:15 +00:00
|
|
|
new DependencyChecker(builder, null);
|
|
|
|
|
2017-03-04 01:50:46 +00:00
|
|
|
final DateTime baseTime = new DateTime.now();
|
2016-12-15 23:05:15 +00:00
|
|
|
|
|
|
|
// Set file modification time on all dependencies to be in the past.
|
|
|
|
updateFileModificationTime(packagesPath, baseTime, -10);
|
|
|
|
updateFileModificationTime(mainPath, baseTime, -10);
|
|
|
|
updateFileModificationTime(fooPath, baseTime, -10);
|
|
|
|
|
|
|
|
// Dependencies are considered dirty because there is a syntax error in
|
|
|
|
// the .dart file.
|
|
|
|
expect(dependencyChecker.check(baseTime), isTrue);
|
|
|
|
});
|
2017-01-26 23:43:28 +00:00
|
|
|
|
|
|
|
/// Test a flutter tool move.
|
|
|
|
///
|
|
|
|
/// Tests that the flutter tool doesn't crash and displays a warning when its own location
|
|
|
|
/// changed since it was last referenced to in a package's .packages file.
|
|
|
|
testUsingContext('moved flutter sdk', () async {
|
2017-03-04 01:50:46 +00:00
|
|
|
final Directory destinationPath = fs.systemTempDirectory.createTempSync('dependency_checker_test_');
|
2017-01-26 23:43:28 +00:00
|
|
|
// Copy the golden input and let the test run in an isolated temporary in-memory file system.
|
2018-02-01 06:51:26 +00:00
|
|
|
const LocalFileSystem localFileSystem = const LocalFileSystem();
|
2017-03-04 01:50:46 +00:00
|
|
|
final Directory sourcePath = localFileSystem.directory(localFileSystem.path.join(dataPath, 'changed_sdk_location'));
|
2017-02-21 23:11:37 +00:00
|
|
|
copyDirectorySync(sourcePath, destinationPath);
|
2017-01-26 23:43:28 +00:00
|
|
|
fs.currentDirectory = destinationPath;
|
|
|
|
|
|
|
|
// Doesn't matter what commands we run. Arbitrarily list devices here.
|
|
|
|
await createTestCommandRunner(new DevicesCommand()).run(<String>['devices']);
|
|
|
|
expect(testLogger.errorText, contains('.packages'));
|
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
FileSystem: () => testFileSystem,
|
|
|
|
});
|
2017-02-21 23:11:37 +00:00
|
|
|
});
|
2016-12-15 23:05:15 +00:00
|
|
|
}
|