| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Dart test program for testing FileSystemEntity.resolveSymbolicLinks | 5 // Dart test program for testing FileSystemEntity.resolveSymbolicLinks |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import "package:path/path.dart"; | 8 import "package:path/path.dart"; |
| 9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:io'; | 11 import 'dart:io'; |
| 12 | 12 |
| 13 main() { | 13 main() { |
| 14 String testsDir = Platform.script.resolve('../..').toFilePath(); | 14 String testsDir = Platform.script.resolve('../..').toFilePath(); |
| 15 // All of these tests test that resolveSymbolicLinks gives a path | 15 // All of these tests test that resolveSymbolicLinks gives a path |
| 16 // that points to the same place as the original, and that it removes | 16 // that points to the same place as the original, and that it removes |
| 17 // all links, .., and . segments, and that it produces an absolute path. | 17 // all links, .., and . segments, and that it produces an absolute path. |
| 18 asyncTest(() => testFile(join( | 18 asyncTest(() => testFile(join( |
| 19 testsDir, 'standalone', 'io', 'resolve_symbolic_links_test.dart'))); | 19 testsDir, 'standalone', 'io', 'resolve_symbolic_links_test.dart'))); |
| 20 asyncTest(() => testFile(join(testsDir, 'standalone', 'io', '..', 'io', | 20 asyncTest(() => testFile(join(testsDir, 'standalone', 'io', '..', 'io', |
| 21 'resolve_symbolic_links_test.dart'))); | 21 'resolve_symbolic_links_test.dart'))); |
| 22 | 22 |
| 23 asyncTest(() => testDir(join(testsDir, 'standalone', 'io'))); | 23 asyncTest(() => testDir(join(testsDir, 'standalone', 'io'))); |
| 24 asyncTest(() => testDir(join(testsDir, 'lib', '..', 'standalone', 'io'))); | 24 asyncTest(() => testDir(join(testsDir, 'lib', '..', 'standalone', 'io'))); |
| 25 // Test a relative path. | 25 // Test a relative path. |
| 26 asyncTest(() => testDir('.')); | |
| 27 if (Platform.isWindows) { | 26 if (Platform.isWindows) { |
| 28 asyncTest(() =>testFile(join('\\\\?\\$testsDir', 'standalone', 'io', | 27 asyncTest(() =>testFile(join('\\\\?\\$testsDir', 'standalone', 'io', |
| 29 'resolve_symbolic_links_test.dart'))); | 28 'resolve_symbolic_links_test.dart'))); |
| 30 asyncTest(() => testDir('\\\\?\\$testsDir')); | 29 asyncTest(() => testDir('\\\\?\\$testsDir')); |
| 31 } | 30 } |
| 32 asyncTest(() => Directory.systemTemp.createTemp('dart_resolve_symbolic_links') | 31 asyncTest(() => Directory.systemTemp.createTemp('dart_resolve_symbolic_links') |
| 33 .then((tempDir) { | 32 .then((tempDir) { |
| 34 String temp = tempDir.path; | 33 String temp = tempDir.path; |
| 35 return makeEntities(temp).then((_) => Future.wait( | 34 return makeEntities(temp).then((_) => Future.wait( |
| 36 [testFile(join(temp, 'dir1', 'file1')), | 35 [testFile(join(temp, 'dir1', 'file1')), |
| 37 testFile(join(temp, 'link1', 'file2')), | 36 testFile(join(temp, 'link1', 'file2')), |
| 38 testDir(join(temp, 'dir1', 'dir2', '..', '.', '..', 'dir1')), | 37 testDir(join(temp, 'dir1', 'dir2', '..', '.', '..', 'dir1')), |
| 39 testDir(join(temp, 'dir1', 'dir2', '..', '.', '..', 'dir1')), | 38 testDir(join(temp, 'dir1', 'dir2', '..', '.', '..', 'dir1')), |
| 40 testLink(join(temp, 'link1'))])) | 39 testLink(join(temp, 'link1')), |
| 40 testDir('.')])) |
| 41 .then((_) { | 41 .then((_) { |
| 42 if (Platform.isWindows) { | 42 if (Platform.isWindows) { |
| 43 // Windows applies '..' to a link without resolving the link first. | 43 // Windows applies '..' to a link without resolving the link first. |
| 44 return Future.wait([ | 44 return Future.wait([ |
| 45 testFile(join( | 45 testFile(join( |
| 46 temp, 'dir1', '..', 'link1', '..', 'dir1', 'dir2', 'file2')), | 46 temp, 'dir1', '..', 'link1', '..', 'dir1', 'dir2', 'file2')), |
| 47 testDir(join(temp, 'dir1', '..', 'link1', '..', 'dir1')), | 47 testDir(join(temp, 'dir1', '..', 'link1', '..', 'dir1')), |
| 48 testLink(join(temp, 'link1', '..', 'link1'))]); | 48 testLink(join(temp, 'link1', '..', 'link1'))]); |
| 49 } else { | 49 } else { |
| 50 // Non-Windows platforms resolve the link before adding the '..'. | 50 // Non-Windows platforms resolve the link before adding the '..'. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 Expect.isTrue(isAbsolute(resolved)); | 139 Expect.isTrue(isAbsolute(resolved)); |
| 140 // Test that resolveSymbolicLinks removes all links, .., and . segments. | 140 // Test that resolveSymbolicLinks removes all links, .., and . segments. |
| 141 Expect.isFalse(resolved.contains('..')); | 141 Expect.isFalse(resolved.contains('..')); |
| 142 Expect.isFalse(resolved.contains('./')); | 142 Expect.isFalse(resolved.contains('./')); |
| 143 Expect.isFalse(resolved.contains('link1')); | 143 Expect.isFalse(resolved.contains('link1')); |
| 144 return new Link(name).target() | 144 return new Link(name).target() |
| 145 .then((targetName) => FileSystemEntity.identical(targetName, resolved)) | 145 .then((targetName) => FileSystemEntity.identical(targetName, resolved)) |
| 146 .then((identical) => Expect.isTrue(identical)); | 146 .then((identical) => Expect.isTrue(identical)); |
| 147 }); | 147 }); |
| 148 } | 148 } |
| OLD | NEW |