From 059853964844386bcdf7cbf601a37db1ae478bed Mon Sep 17 00:00:00 2001 From: "rnystrom@google.com" <rnystrom@google.com> Date: Tue, 5 Feb 2013 04:18:34 +0000 Subject: [PATCH] Get most pub IO tests passing on Windows. The remaining issue now is a hang in dart:io. BUG= Review URL: https://codereview.chromium.org//12211004 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@18112 260f80e4-7a28-3924-810f-c04153c831b5 --- lib/src/io.dart | 5 ++++- test/command_line_config.dart | 40 +++++++++++++++++++++-------------- test/io_test.dart | 28 +++++++++++++++--------- test/pub.status | 2 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/lib/src/io.dart b/lib/src/io.dart index c81da000..04f39ade 100644 --- a/lib/src/io.dart +++ b/lib/src/io.dart @@ -190,6 +190,7 @@ Future<List<String>> listDir(dir, if (listedDirectories.contains(resolvedPath)) { return new Future.immediate([]); } + listedDirectories = new Set<String>.from(listedDirectories); listedDirectories.add(resolvedPath); @@ -220,7 +221,6 @@ Future<List<String>> listDir(dir, if (!includeHiddenFiles && basename(file).startsWith('.')) return; file = join(dir, basename(file)); contents.add(file); - // TODO(nweiz): don't manually recurse once issue 7358 is fixed. Note that // once we remove the manual recursion, we'll need to explicitly filter // out files in hidden directories. @@ -228,6 +228,7 @@ Future<List<String>> listDir(dir, children.add(doList(new Directory(file), listedDirectories)); } }; + lister.onFile = (file) { if (!includeHiddenFiles && basename(file).startsWith('.')) return; contents.add(join(dir, basename(file))); @@ -308,6 +309,8 @@ Future _attemptRetryable(Future callback()) { /// Creates a new symlink that creates an alias from [from] to [to], both of /// which can be a [String], [File], or [Directory]. Returns a [Future] which /// completes to the symlink file (i.e. [to]). +/// +/// Note that on Windows, only directories may be symlinked to. Future<File> createSymlink(from, to) { from = _getPath(from); to = _getPath(to); diff --git a/test/command_line_config.dart b/test/command_line_config.dart index 71df35e0..d15126bc 100644 --- a/test/command_line_config.dart +++ b/test/command_line_config.dart @@ -10,15 +10,23 @@ import '../../../pkg/path/lib/path.dart' as path; import '../../../pkg/unittest/lib/unittest.dart'; import '../../pub/utils.dart'; -const _GREEN = '\u001b[32m'; -const _RED = '\u001b[31m'; -const _MAGENTA = '\u001b[35m'; -const _NONE = '\u001b[0m'; +/// Gets a "special" string (ANSI escape or Unicode). On Windows, returns +/// something else since those aren't supported. +String _getSpecial(String color, [String onWindows = '']) { + // No ANSI escapes on windows. + if (Platform.operatingSystem == 'windows') return onWindows; + return color; +} /// Pretty Unicode characters! -const _CHECKBOX = '\u2713'; -const _BALLOT_X = '\u2717'; -const _LAMBDA = '\u03bb'; +final _checkbox = _getSpecial('\u2713', 'PASS'); +final _ballotX = _getSpecial('\u2717', 'FAIL'); +final _lambda = _getSpecial('\u03bb', '<fn>'); + +final _green = _getSpecial('\u001b[32m'); +final _red = _getSpecial('\u001b[31m'); +final _magenta = _getSpecial('\u001b[35m'); +final _none = _getSpecial('\u001b[0m'); /// A custom unittest configuration for running the pub tests from the /// command-line and generating human-friendly output. @@ -30,9 +38,9 @@ class CommandLineConfiguration extends Configuration { void onTestResult(TestCase testCase) { var result; switch (testCase.result) { - case PASS: result = '$_GREEN$_CHECKBOX$_NONE'; break; - case FAIL: result = '$_RED$_BALLOT_X$_NONE'; break; - case ERROR: result = '$_MAGENTA?$_NONE'; break; + case PASS: result = '$_green$_checkbox$_none'; break; + case FAIL: result = '$_red$_ballotX$_none'; break; + case ERROR: result = '$_magenta?$_none'; break; } print('$result ${testCase.description}'); @@ -51,15 +59,15 @@ class CommandLineConfiguration extends Configuration { if (uncaughtError != null) { print('Top-level uncaught error: $uncaughtError'); } else if (errors != 0) { - print('${_GREEN}$passed${_NONE} passed, ${_RED}$failed${_NONE} failed, ' - '${_MAGENTA}$errors${_NONE} errors.'); + print('${_green}$passed${_none} passed, ${_red}$failed${_none} failed, ' + '${_magenta}$errors${_none} errors.'); } else if (failed != 0) { - print('${_GREEN}$passed${_NONE} passed, ${_RED}$failed${_NONE} ' + print('${_green}$passed${_none} passed, ${_red}$failed${_none} ' 'failed.'); } else if (passed == 0) { print('No tests found.'); } else { - print('All ${_GREEN}$passed${_NONE} tests passed!'); + print('All ${_green}$passed${_none} tests passed!'); success = true; } } @@ -154,7 +162,7 @@ class _StackFrame { library = path.relative(library); } - var member = match[1].replaceAll("<anonymous closure>", _LAMBDA); + var member = match[1].replaceAll("<anonymous closure>", _lambda); return new _StackFrame._(isCore, library, match[3], match[4], member); } -} \ No newline at end of file +} diff --git a/test/io_test.dart b/test/io_test.dart index 29e97098..6c6922c3 100644 --- a/test/io_test.dart +++ b/test/io_test.dart @@ -7,8 +7,11 @@ library io_test; import '../../../pkg/unittest/lib/unittest.dart'; import '../../pub/io.dart'; import '../../pub/utils.dart'; +import 'test_pub.dart'; main() { + initConfig(); + group('listDir', () { test('lists a simple directory non-recursively', () { expect(withTempDir((path) { @@ -37,11 +40,12 @@ main() { writeTextFile(join(path, 'subdir', 'file3.txt'), ''); return listDir(path, recursive: true); }); + expect(future, completion(unorderedEquals([ join(path, 'file1.txt'), join(path, 'file2.txt'), join(path, 'subdir'), - join(path, 'subdir/file3.txt'), + join(path, 'subdir', 'file3.txt'), ]))); return future; }), completes); @@ -80,7 +84,7 @@ main() { join(path, 'file2.txt'), join(path, '.file3.txt'), join(path, '.subdir'), - join(path, '.subdir/file3.txt') + join(path, '.subdir', 'file3.txt') ]))); return future; }), completes); @@ -90,21 +94,25 @@ main() { expect(withTempDir((path) { var dirToList = join(path, 'dir-to-list'); var future = defer(() { - writeTextFile(join(path, 'file1.txt'), ''); - writeTextFile(join(path, 'file2.txt'), ''); + createDir(join(path, 'dir1')); + writeTextFile(join(path, 'dir1', 'file1.txt'), ''); + createDir(join(path, 'dir2')); + writeTextFile(join(path, 'dir2', 'file2.txt'), ''); createDir(dirToList); - return createSymlink(join(path, 'file1.txt'), - join(dirToList, 'link1')); + return createSymlink(join(path, 'dir1'), + join(dirToList, 'linked-dir1')); }).then((_) { createDir(join(dirToList, 'subdir')); return createSymlink( - join(path, 'file2.txt'), - join(dirToList, 'subdir', 'link2')); + join(path, 'dir2'), + join(dirToList, 'subdir', 'linked-dir2')); }).then((_) => listDir(dirToList, recursive: true)); expect(future, completion(unorderedEquals([ - join(dirToList, 'link1'), + join(dirToList, 'linked-dir1'), + join(dirToList, 'linked-dir1', 'file1.txt'), join(dirToList, 'subdir'), - join(dirToList, 'subdir/link2'), + join(dirToList, 'subdir', 'linked-dir2'), + join(dirToList, 'subdir', 'linked-dir2', 'file2.txt'), ]))); return future; }), completes); diff --git a/test/pub.status b/test/pub.status index 3a948d5f..ea69d15f 100644 --- a/test/pub.status +++ b/test/pub.status @@ -11,7 +11,7 @@ *: Skip [ $system == windows ] -io_test: Fail, Pass, Timeout # Issue 7505 +io_test: Timeout # Issue 7505 # Issue 8264 install/hosted/install_test: Fail, Pass -- GitLab