Commit ac7954c1 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Migrate from touch cmd to dart's built-in API (#8313)

This enables us to run more tests on Windows.
parent e9a775bf
......@@ -77,7 +77,7 @@ void copyDirectorySync(Directory srcDir, Directory destDir) {
destDir.createSync(recursive: true);
srcDir.listSync().forEach((FileSystemEntity entity) {
String newPath = fs.path.join(destDir.path, fs.path.basename(entity.path));
String newPath = destDir.fileSystem.path.join(destDir.path, entity.basename);
if (entity is File) {
File newFile = destDir.fileSystem.file(newPath);
newFile.writeAsBytesSync(entity.readAsBytesSync());
......
......@@ -19,7 +19,7 @@ void main() {
group('DependencyChecker', () {
final String basePath = fs.path.dirname(fs.path.fromUri(platform.script));
final String dataPath = fs.path.join(basePath, 'data', 'dart_dependencies_test');
MemoryFileSystem testFileSystem;
FileSystem testFileSystem;
setUp(() {
Cache.disableLocking();
......@@ -56,7 +56,8 @@ void main() {
// Set 'package:self/bar.dart' file modification time to be in the future.
updateFileModificationTime(barPath, baseTime, 10);
expect(dependencyChecker.check(baseTime), isTrue);
});
}, skip: io.Platform.isWindows); // TODO(goderbauer): enable when sky_snapshot is ready on Windows
testUsingContext('syntax error', () {
final String testPath = fs.path.join(dataPath, 'syntax_error');
final String mainPath = fs.path.join(testPath, 'main.dart');
......@@ -85,11 +86,11 @@ void main() {
/// 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 {
String destinationPath = '/some/test/location';
Directory destinationPath = fs.systemTempDirectory.createTempSync('dependency_checker_test_');
// Copy the golden input and let the test run in an isolated temporary in-memory file system.
copyDirectorySync(
const LocalFileSystem().directory(fs.path.join(dataPath, 'changed_sdk_location')),
fs.directory(destinationPath));
LocalFileSystem localFileSystem = const LocalFileSystem();
Directory sourcePath = localFileSystem.directory(localFileSystem.path.join(dataPath, 'changed_sdk_location'));
copyDirectorySync(sourcePath, destinationPath);
fs.currentDirectory = destinationPath;
// Doesn't matter what commands we run. Arbitrarily list devices here.
......@@ -98,5 +99,5 @@ void main() {
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
});
}, skip: io.Platform.isWindows); // TODO(goderbauer): Migrate test away from 'touch' bash command.
});
}
......@@ -4,7 +4,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io' as io;
import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/io.dart';
......@@ -115,7 +114,7 @@ void main() {
]);
expect(devFS.assetPathsToEvict, isEmpty);
expect(bytes, 6);
}, skip: io.Platform.isWindows); // TODO(goderbauer): enable when updateFileModificationTime is ported to Windows
});
testUsingContext('delete a file from the local file system', () async {
File file = fs.file(fs.path.join(basePath, filePath));
await file.delete();
......
......@@ -3,11 +3,10 @@
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:process/process.dart';
import 'package:test/test.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
......@@ -23,15 +22,7 @@ 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(<String>['touch', '-t', argument, path]);
fs.file(path).setLastModifiedSync(modificationTime);
}
/// Matcher for functions that throw ToolExit.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment