Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // | |
| 5 // Dart test program for testing FileSystemEntity.resolveSymbolicLinks | |
| 6 | |
| 7 import "package:expect/expect.dart"; | |
| 8 import "package:path/path.dart"; | |
| 9 import "package:async_helper/async_helper.dart"; | |
| 10 import 'dart:async'; | |
| 11 import 'dart:io'; | |
| 12 | |
| 13 main() { | |
| 14 String testsDir = dirname(dirname(dirname(Platform.script))); | |
| 15 asyncTest(() => testFile(join( | |
| 16 testsDir, 'standalone', 'io', 'resolve_symbolic_links_test.dart'))); | |
| 17 asyncTest(() => testFile(join(testsDir, 'standalone', 'io', '..', 'io', | |
| 18 '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?
| |
| 19 | |
| 20 asyncTest(() => testDir(join(testsDir, 'standalone', 'io'))); | |
| 21 asyncTest(() => testDir(join(testsDir, 'lib', '..', 'standalone', 'io'))); | |
| 22 asyncTest(() => testDir('.')); | |
| 23 if (Platform.isWindows) { | |
| 24 asyncTest(() =>testFile(join('\\\\?\\$testsDir', | |
| 25 'standalone', 'io', 'resolve_symbolic_links_test.dart'))); | |
| 26 asyncTest(() => testDir('\\\\?\\$testsDir')); | |
| 27 } | |
| 28 asyncTest(() => new Directory('').createTemp().then((tempDir) { | |
| 29 String temp = tempDir.path; | |
| 30 return makeEntities(temp) | |
| 31 .then((_) => Future.wait( | |
| 32 [testFile(join(temp, 'dir1', 'file1')), | |
| 33 testFile(join(temp, 'link1', 'file2')), | |
| 34 testFile(join(temp, 'link1', '..', 'dir1','dir2', 'file2')), | |
| 35 testDir(join(temp, 'dir1', 'dir2', '..', '.', '..', 'dir1')), | |
| 36 // Non-Windows platforms resolve the link before adding the '..'. | |
| 37 Platform.isWindows ? | |
| 38 testDir(join(temp, 'dir1', '..', 'link1', '..', 'dir1')) : | |
| 39 testDir(join(temp, 'dir1', '..', 'link1', '..', 'dir2')), | |
| 40 testDir(join(temp, 'dir1', 'dir2', '..', '.', '..', 'dir1')), | |
| 41 testLink(join(temp, 'link1')), | |
| 42 Platform.isWindows ? | |
| 43 testLink(join(temp, 'link1', '..', 'link1')) : | |
| 44 testLink(join(temp, 'link1', '..', '..', 'link1'))])) | |
| 45 .whenComplete(() => tempDir.delete(recursive: true)); | |
| 46 })); | |
| 47 } | |
| 48 | |
| 49 Future makeEntities(String temp) { | |
| 50 return new Directory(join(temp, 'dir1', 'dir2')).create(recursive: true) | |
| 51 .then((_) => new File(join(temp, 'dir1', 'dir2', 'file2')).create()) | |
| 52 .then((_) => new File(join(temp, 'dir1', 'file1')).create()) | |
| 53 .then((_) => new Link(join(temp, 'link1')) | |
| 54 .create(join(temp, 'dir1', 'dir2'))); | |
| 55 } | |
| 56 | |
| 57 Future testFile(String name) { | |
| 58 Expect.isTrue(FileSystemEntity.identicalSync(name, | |
| 59 new File(name).resolveSymbolicLinksSync())); | |
| 60 return new File(name).resolveSymbolicLinks().then((String resolved) { | |
| 61 Expect.isTrue(FileSystemEntity.identicalSync(name, resolved)); | |
| 62 Expect.isTrue(isAbsolute(resolved)); | |
| 63 Expect.isFalse(resolved.contains('..')); | |
| 64 Expect.isFalse(resolved.contains('link1')); | |
| 65 }); | |
| 66 } | |
| 67 | |
| 68 Future testDir(String name) { | |
| 69 Expect.isTrue(FileSystemEntity.identicalSync(name, | |
| 70 new Directory(name).resolveSymbolicLinksSync())); | |
| 71 return new Directory(name).resolveSymbolicLinks().then((String resolved) { | |
| 72 Expect.isTrue(FileSystemEntity.identicalSync(name, resolved)); | |
| 73 Expect.isTrue(isAbsolute(resolved)); | |
| 74 Expect.isFalse(resolved.contains('..')); | |
| 75 Expect.isFalse(resolved.contains('link1')); | |
| 76 }); | |
| 77 } | |
| 78 | |
| 79 Future testLink(String name) { | |
| 80 Expect.isFalse(FileSystemEntity.identicalSync(name, | |
| 81 new Link(name).resolveSymbolicLinksSync())); | |
| 82 Expect.isTrue(FileSystemEntity.identicalSync(new Link(name).targetSync(), | |
| 83 new Link(name).resolveSymbolicLinksSync())); | |
| 84 return new Link(name).resolveSymbolicLinks().then((String resolved) { | |
| 85 Expect.isFalse(FileSystemEntity.identicalSync(name, resolved)); | |
| 86 Expect.isTrue(isAbsolute(resolved)); | |
| 87 Expect.isFalse(resolved.contains('..')); | |
| 88 Expect.isFalse(resolved.contains('link1')); | |
| 89 return new Link(name).target() | |
| 90 .then((targetName) => FileSystemEntity.identical(targetName, resolved)) | |
| 91 .then((identical) => Expect.isTrue(identical)); | |
| 92 }); | |
| 93 } | |
| OLD | NEW |