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) { ...@@ -77,7 +77,7 @@ void copyDirectorySync(Directory srcDir, Directory destDir) {
destDir.createSync(recursive: true); destDir.createSync(recursive: true);
srcDir.listSync().forEach((FileSystemEntity entity) { 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) { if (entity is File) {
File newFile = destDir.fileSystem.file(newPath); File newFile = destDir.fileSystem.file(newPath);
newFile.writeAsBytesSync(entity.readAsBytesSync()); newFile.writeAsBytesSync(entity.readAsBytesSync());
......
...@@ -19,7 +19,7 @@ void main() { ...@@ -19,7 +19,7 @@ void main() {
group('DependencyChecker', () { group('DependencyChecker', () {
final String basePath = fs.path.dirname(fs.path.fromUri(platform.script)); final String basePath = fs.path.dirname(fs.path.fromUri(platform.script));
final String dataPath = fs.path.join(basePath, 'data', 'dart_dependencies_test'); final String dataPath = fs.path.join(basePath, 'data', 'dart_dependencies_test');
MemoryFileSystem testFileSystem; FileSystem testFileSystem;
setUp(() { setUp(() {
Cache.disableLocking(); Cache.disableLocking();
...@@ -56,7 +56,8 @@ void main() { ...@@ -56,7 +56,8 @@ void main() {
// Set 'package:self/bar.dart' file modification time to be in the future. // Set 'package:self/bar.dart' file modification time to be in the future.
updateFileModificationTime(barPath, baseTime, 10); updateFileModificationTime(barPath, baseTime, 10);
expect(dependencyChecker.check(baseTime), isTrue); expect(dependencyChecker.check(baseTime), isTrue);
}); }, skip: io.Platform.isWindows); // TODO(goderbauer): enable when sky_snapshot is ready on Windows
testUsingContext('syntax error', () { testUsingContext('syntax error', () {
final String testPath = fs.path.join(dataPath, 'syntax_error'); final String testPath = fs.path.join(dataPath, 'syntax_error');
final String mainPath = fs.path.join(testPath, 'main.dart'); final String mainPath = fs.path.join(testPath, 'main.dart');
...@@ -85,11 +86,11 @@ void main() { ...@@ -85,11 +86,11 @@ void main() {
/// Tests that the flutter tool doesn't crash and displays a warning when its own location /// 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. /// changed since it was last referenced to in a package's .packages file.
testUsingContext('moved flutter sdk', () async { 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. // Copy the golden input and let the test run in an isolated temporary in-memory file system.
copyDirectorySync( LocalFileSystem localFileSystem = const LocalFileSystem();
const LocalFileSystem().directory(fs.path.join(dataPath, 'changed_sdk_location')), Directory sourcePath = localFileSystem.directory(localFileSystem.path.join(dataPath, 'changed_sdk_location'));
fs.directory(destinationPath)); copyDirectorySync(sourcePath, destinationPath);
fs.currentDirectory = destinationPath; fs.currentDirectory = destinationPath;
// Doesn't matter what commands we run. Arbitrarily list devices here. // Doesn't matter what commands we run. Arbitrarily list devices here.
...@@ -98,5 +99,5 @@ void main() { ...@@ -98,5 +99,5 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => testFileSystem, FileSystem: () => testFileSystem,
}); });
}, skip: io.Platform.isWindows); // TODO(goderbauer): Migrate test away from 'touch' bash command. });
} }
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:io' as io;
import 'package:flutter_tools/src/asset.dart'; import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
...@@ -115,7 +114,7 @@ void main() { ...@@ -115,7 +114,7 @@ void main() {
]); ]);
expect(devFS.assetPathsToEvict, isEmpty); expect(devFS.assetPathsToEvict, isEmpty);
expect(bytes, 6); 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 { testUsingContext('delete a file from the local file system', () async {
File file = fs.file(fs.path.join(basePath, filePath)); File file = fs.file(fs.path.join(basePath, filePath));
await file.delete(); await file.delete();
......
...@@ -3,11 +3,10 @@ ...@@ -3,11 +3,10 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:process/process.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'package:flutter_tools/src/base/common.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.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart'; import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
...@@ -23,15 +22,7 @@ void updateFileModificationTime(String path, ...@@ -23,15 +22,7 @@ void updateFileModificationTime(String path,
DateTime baseTime, DateTime baseTime,
int seconds) { int seconds) {
DateTime modificationTime = baseTime.add(new Duration(seconds: seconds)); DateTime modificationTime = baseTime.add(new Duration(seconds: seconds));
String argument = fs.file(path).setLastModifiedSync(modificationTime);
'${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]);
} }
/// Matcher for functions that throw ToolExit. /// 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