Index: tests/standalone/io/resolve_symbolic_links_test.dart |
diff --git a/tests/standalone/io/resolve_symbolic_links_test.dart b/tests/standalone/io/resolve_symbolic_links_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4b0631a50720639df68c87a0dad9e07846b06fb2 |
--- /dev/null |
+++ b/tests/standalone/io/resolve_symbolic_links_test.dart |
@@ -0,0 +1,93 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+// |
+// Dart test program for testing FileSystemEntity.resolveSymbolicLinks |
+ |
+import "package:expect/expect.dart"; |
+import "package:path/path.dart"; |
+import "package:async_helper/async_helper.dart"; |
+import 'dart:async'; |
+import 'dart:io'; |
+ |
+main() { |
+ String testsDir = dirname(dirname(dirname(Platform.script))); |
+ asyncTest(() => testFile(join( |
+ testsDir, 'standalone', 'io', 'resolve_symbolic_links_test.dart'))); |
+ asyncTest(() => testFile(join(testsDir, 'standalone', 'io', '..', 'io', |
+ 'resolve_symbolic_links_test.dart'))); |
Bill Hesse
2013/09/09 11:55:39
Violates style guide about putting arguments on on
Bob Nystrom
2013/09/13 15:29:10
What style guide is this?
|
+ |
+ asyncTest(() => testDir(join(testsDir, 'standalone', 'io'))); |
+ asyncTest(() => testDir(join(testsDir, 'lib', '..', 'standalone', 'io'))); |
+ asyncTest(() => testDir('.')); |
+ if (Platform.isWindows) { |
+ asyncTest(() =>testFile(join('\\\\?\\$testsDir', |
+ 'standalone', 'io', 'resolve_symbolic_links_test.dart'))); |
+ asyncTest(() => testDir('\\\\?\\$testsDir')); |
+ } |
+ asyncTest(() => new Directory('').createTemp().then((tempDir) { |
+ String temp = tempDir.path; |
+ return makeEntities(temp) |
+ .then((_) => Future.wait( |
+ [testFile(join(temp, 'dir1', 'file1')), |
+ testFile(join(temp, 'link1', 'file2')), |
+ testFile(join(temp, 'link1', '..', 'dir1','dir2', 'file2')), |
+ testDir(join(temp, 'dir1', 'dir2', '..', '.', '..', 'dir1')), |
+ // Non-Windows platforms resolve the link before adding the '..'. |
+ Platform.isWindows ? |
+ testDir(join(temp, 'dir1', '..', 'link1', '..', 'dir1')) : |
+ testDir(join(temp, 'dir1', '..', 'link1', '..', 'dir2')), |
+ testDir(join(temp, 'dir1', 'dir2', '..', '.', '..', 'dir1')), |
+ testLink(join(temp, 'link1')), |
+ Platform.isWindows ? |
+ testLink(join(temp, 'link1', '..', 'link1')) : |
+ testLink(join(temp, 'link1', '..', '..', 'link1'))])) |
+ .whenComplete(() => tempDir.delete(recursive: true)); |
+ })); |
+} |
+ |
+Future makeEntities(String temp) { |
+ return new Directory(join(temp, 'dir1', 'dir2')).create(recursive: true) |
+ .then((_) => new File(join(temp, 'dir1', 'dir2', 'file2')).create()) |
+ .then((_) => new File(join(temp, 'dir1', 'file1')).create()) |
+ .then((_) => new Link(join(temp, 'link1')) |
+ .create(join(temp, 'dir1', 'dir2'))); |
+} |
+ |
+Future testFile(String name) { |
+ Expect.isTrue(FileSystemEntity.identicalSync(name, |
+ new File(name).resolveSymbolicLinksSync())); |
+ return new File(name).resolveSymbolicLinks().then((String resolved) { |
+ Expect.isTrue(FileSystemEntity.identicalSync(name, resolved)); |
+ Expect.isTrue(isAbsolute(resolved)); |
+ Expect.isFalse(resolved.contains('..')); |
+ Expect.isFalse(resolved.contains('link1')); |
+ }); |
+} |
+ |
+Future testDir(String name) { |
+ Expect.isTrue(FileSystemEntity.identicalSync(name, |
+ new Directory(name).resolveSymbolicLinksSync())); |
+ return new Directory(name).resolveSymbolicLinks().then((String resolved) { |
+ Expect.isTrue(FileSystemEntity.identicalSync(name, resolved)); |
+ Expect.isTrue(isAbsolute(resolved)); |
+ Expect.isFalse(resolved.contains('..')); |
+ Expect.isFalse(resolved.contains('link1')); |
+ }); |
+} |
+ |
+Future testLink(String name) { |
+ Expect.isFalse(FileSystemEntity.identicalSync(name, |
+ new Link(name).resolveSymbolicLinksSync())); |
+ Expect.isTrue(FileSystemEntity.identicalSync(new Link(name).targetSync(), |
+ new Link(name).resolveSymbolicLinksSync())); |
+ return new Link(name).resolveSymbolicLinks().then((String resolved) { |
+ Expect.isFalse(FileSystemEntity.identicalSync(name, resolved)); |
+ Expect.isTrue(isAbsolute(resolved)); |
+ Expect.isFalse(resolved.contains('..')); |
+ Expect.isFalse(resolved.contains('link1')); |
+ return new Link(name).target() |
+ .then((targetName) => FileSystemEntity.identical(targetName, resolved)) |
+ .then((identical) => Expect.isTrue(identical)); |
+ }); |
+} |