From ac7954c11aa3ac7e1801ad720bd213862663af0e Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Tue, 21 Feb 2017 15:11:37 -0800 Subject: [PATCH] Migrate from touch cmd to dart's built-in API (#8313) This enables us to run more tests on Windows. --- .../flutter_tools/lib/src/base/file_system.dart | 2 +- .../test/dependency_checker_test.dart | 15 ++++++++------- packages/flutter_tools/test/devfs_test.dart | 3 +-- packages/flutter_tools/test/src/common.dart | 13 ++----------- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/file_system.dart b/packages/flutter_tools/lib/src/base/file_system.dart index 4d295f0ff1..86f9884793 100644 --- a/packages/flutter_tools/lib/src/base/file_system.dart +++ b/packages/flutter_tools/lib/src/base/file_system.dart @@ -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()); diff --git a/packages/flutter_tools/test/dependency_checker_test.dart b/packages/flutter_tools/test/dependency_checker_test.dart index ec386312b4..8fb4ee4afd 100644 --- a/packages/flutter_tools/test/dependency_checker_test.dart +++ b/packages/flutter_tools/test/dependency_checker_test.dart @@ -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: { FileSystem: () => testFileSystem, }); - }, skip: io.Platform.isWindows); // TODO(goderbauer): Migrate test away from 'touch' bash command. + }); } diff --git a/packages/flutter_tools/test/devfs_test.dart b/packages/flutter_tools/test/devfs_test.dart index f45ebc3c7e..73d5bd7864 100644 --- a/packages/flutter_tools/test/devfs_test.dart +++ b/packages/flutter_tools/test/devfs_test.dart @@ -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(); diff --git a/packages/flutter_tools/test/src/common.dart b/packages/flutter_tools/test/src/common.dart index 4a4976af81..f09ff55f99 100644 --- a/packages/flutter_tools/test/src/common.dart +++ b/packages/flutter_tools/test/src/common.dart @@ -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(['touch', '-t', argument, path]); + fs.file(path).setLastModifiedSync(modificationTime); } /// Matcher for functions that throw ToolExit.