Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: tests/standalone/io/resolve_symbolic_links_test.dart

Issue 23444037: dart:io | Change File.fullPath to FileSystemEntity.resolveSymbolicLinks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Documentation edits. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« runtime/bin/directory.cc ('K') | « tests/standalone/io/file_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // All of these tests test that resolveSymbolicLinks gives a path
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.
18 asyncTest(() => testFile(join(
19 testsDir, 'standalone', 'io', 'resolve_symbolic_links_test.dart')));
20 asyncTest(() => testFile(join(testsDir, 'standalone', 'io', '..', 'io',
21 'resolve_symbolic_links_test.dart')));
22
23 asyncTest(() => testDir(join(testsDir, 'standalone', 'io')));
24 asyncTest(() => testDir(join(testsDir, 'lib', '..', 'standalone', 'io')));
25 // Test a relative path.
26 asyncTest(() => testDir('.'));
27 if (Platform.isWindows) {
28 asyncTest(() =>testFile(join('\\\\?\\$testsDir', 'standalone', 'io',
29 'resolve_symbolic_links_test.dart')));
30 asyncTest(() => testDir('\\\\?\\$testsDir'));
31 }
32 asyncTest(() => new Directory('').createTemp().then((tempDir) {
33 String temp = tempDir.path;
34 return makeEntities(temp).then((_) => Future.wait(
35 [testFile(join(temp, 'dir1', 'file1')),
36 testFile(join(temp, 'link1', 'file2')),
37 testDir(join(temp, 'dir1', 'dir2', '..', '.', '..', 'dir1')),
38 testDir(join(temp, 'dir1', 'dir2', '..', '.', '..', 'dir1')),
39 testLink(join(temp, 'link1'))]))
40 .then((_) {
41 if (Platform.isWindows) {
42 // Windows applies '..' to a link without resolving the link first.
43 return Future.wait([
44 testFile(join(
45 temp, 'dir1', '..', 'link1', '..', 'dir1', 'dir2', 'file2')),
46 testDir(join(temp, 'dir1', '..', 'link1', '..', 'dir1')),
47 testLink(join(temp, 'link1', '..', 'link1'))]);
48 } else {
49 // Non-Windows platforms resolve the link before adding the '..'.
50 return Future.wait([
51 testFile(join(
52 temp, 'dir1', '..', 'link1', '..', 'dir2', 'file2')),
53 testDir(join(temp, 'dir1', '..', 'link1', '..', 'dir2')),
54 testLink(join(temp, 'link1', '..', '..', 'link1'))]);
55 }
56 })
57 .then((_) {
58 Directory.current = temp;
59 return Future.wait([
60 testFile('dir1/dir2/file2'), // Test forward slashes on Windows too.
61 testFile('link1/file2'),
62 testFile(join('dir1', '..', 'dir1', '.', 'file1')),
63 testDir('.'),
64 testDir('link1/.'),
65 testLink('link1')]);
66 })
67 .then((_) {
68 Directory.current = 'link1';
69 if (Platform.isWindows) {
70 return Future.wait([
71 testFile('file2'),
72 // Windows applies '..' to a link without resolving the link first.
73 testFile('..\\dir1\\file1'),
74 testDir('.'),
75 testDir('..'),
76 testLink('..\\link1')]);
77 } else {
78 return Future.wait([
79 testFile('file2'),
80 // On non-Windows the link is changed to dir1/dir2 before .. happens.
81 testFile('../dir2/file2'),
82 testDir('.'),
83 testDir('..'),
84 testLink('../../link1')]);
85 }
86 })
87 .whenComplete(() => tempDir.delete(recursive: true));
88 }));
89 }
90
91 Future makeEntities(String temp) {
92 return new Directory(join(temp, 'dir1', 'dir2')).create(recursive: true)
93 .then((_) => new File(join(temp, 'dir1', 'dir2', 'file2')).create())
94 .then((_) => new File(join(temp, 'dir1', 'file1')).create())
95 .then((_) => new Link(join(temp, 'link1'))
96 .create(join(temp, 'dir1', 'dir2')));
97 }
98
99 Future testFile(String name) {
100 // We test that f.resolveSymbolicLinks points to the same place
101 // as f, because the actual resolved path is not easily predictable.
102 // The location of the temp directory varies from system to system,
103 // and its path includes symbolic links on some systems.
104 //Expect.isTrue(FileSystemEntity.identicalSync(name,
105 // new File(name).resolveSymbolicLinksSync()));
106 return new File(name).resolveSymbolicLinks().then((String resolved) {
107 //Expect.isTrue(FileSystemEntity.identicalSync(name, resolved));
108 Expect.isTrue(isAbsolute(resolved));
109 // Test that resolveSymbolicLinks removes all links, .., and . segments.
110 Expect.isFalse(resolved.contains('..'));
111 Expect.isFalse(resolved.contains('./'));
112 Expect.isFalse(resolved.contains('link1'));
113 });
114 }
115
116 Future testDir(String name) {
117 Expect.isTrue(FileSystemEntity.identicalSync(name,
118 new Directory(name).resolveSymbolicLinksSync()));
119 return new Directory(name).resolveSymbolicLinks().then((String resolved) {
120 Expect.isTrue(FileSystemEntity.identicalSync(name, resolved));
121 Expect.isTrue(isAbsolute(resolved));
122 // Test that resolveSymbolicLinks removes all links, .., and . segments.
123 Expect.isFalse(resolved.contains('..'));
124 Expect.isFalse(resolved.contains('./'));
125 Expect.isFalse(resolved.contains('link1'));
126 });
127 }
128
129 Future testLink(String name) {
130 Expect.isFalse(FileSystemEntity.identicalSync(name,
131 new Link(name).resolveSymbolicLinksSync()));
132 Expect.isTrue(FileSystemEntity.identicalSync(new Link(name).targetSync(),
133 new Link(name).resolveSymbolicLinksSync()));
134 return new Link(name).resolveSymbolicLinks().then((String resolved) {
135 Expect.isFalse(FileSystemEntity.identicalSync(name, resolved));
136 Expect.isTrue(isAbsolute(resolved));
137 // Test that resolveSymbolicLinks removes all links, .., and . segments.
138 Expect.isFalse(resolved.contains('..'));
139 Expect.isFalse(resolved.contains('./'));
140 Expect.isFalse(resolved.contains('link1'));
141 return new Link(name).target()
142 .then((targetName) => FileSystemEntity.identical(targetName, resolved))
143 .then((identical) => Expect.isTrue(identical));
144 });
145 }
OLDNEW
« runtime/bin/directory.cc ('K') | « tests/standalone/io/file_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698