DependencyChecker with tests (#7268)

- [x] Introduce DependencyChecker which can determine if any dependencies have been modified.
- [x] Move the DartDependencyBuilder into a separate file.
- [x] Add unit tests for DartDependencyBuilder.
- [x] Add unit tets for DependencyChecker

Part of #7014
This commit is contained in:
John McCutchan
2016-12-15 15:05:15 -08:00
committed by GitHub
parent 977a25f29c
commit 2546259a64
25 changed files with 325 additions and 49 deletions

View File

@@ -3,6 +3,9 @@
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/process_manager.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
@@ -12,3 +15,19 @@ CommandRunner<Null> createTestCommandRunner([FlutterCommand command]) {
runner.addCommand(command);
return runner;
}
/// Updates [path] to have a modification time [seconds] from now.
void updateFileModificationTime(String path,
DateTime baseTime,
int seconds) {
DateTime modificationTime = baseTime.add(new Duration(seconds: seconds));
String argument =
'${modificationTime.year}'
'${modificationTime.month.toString().padLeft(2, "0")}'
'${modificationTime.day.toString().padLeft(2, "0")}'
'${modificationTime.hour.toString().padLeft(2, "0")}'
'${modificationTime.minute.toString().padLeft(2, "0")}'
'.${modificationTime.second.toString().padLeft(2, "0")}';
ProcessManager processManager = context[ProcessManager];
processManager.runSync('touch', <String>['-t', argument, path]);
}

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/context.dart';
@@ -20,6 +21,7 @@ import 'package:flutter_tools/src/toolchain.dart';
import 'package:flutter_tools/src/usage.dart';
import 'package:mockito/mockito.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
/// Return the test logger. This assumes that the current Logger is a BufferLogger.
@@ -64,6 +66,9 @@ void testUsingContext(String description, dynamic testMethod(), {
testContext.putIfAbsent(SimControl, () => new MockSimControl());
testContext.putIfAbsent(Usage, () => new MockUsage());
final String basePath = path.dirname(Platform.script.path);
final String flutterRoot =
path.normalize(path.join(basePath, '..', '..', '..'));
try {
return await testContext.runInZone(() {
// Apply the overrides to the test context in the zone since their
@@ -71,7 +76,9 @@ void testUsingContext(String description, dynamic testMethod(), {
overrides.forEach((Type type, dynamic value()) {
context.setVariable(type, value());
});
// Provide a sane default for the flutterRoot directory. Individual
// tests can override this.
Cache.flutterRoot = flutterRoot;
return testMethod();
});
} catch (error) {