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

Side by Side Diff: sdk/lib/_internal/pub/test/io_test.dart

Issue 14924006: Add a function to pub for finding the canonical path of a file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 years, 7 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library io_test; 5 library io_test;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:pathos/path.dart' as path; 9 import 'package:pathos/path.dart' as path;
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 deleteEntry(path.join(temp, 'dir')); 128 deleteEntry(path.join(temp, 'dir'));
129 129
130 expect(listDir(temp, recursive: true), unorderedEquals([ 130 expect(listDir(temp, recursive: true), unorderedEquals([
131 path.join(temp, 'file1.txt'), 131 path.join(temp, 'file1.txt'),
132 path.join(temp, 'linkdir') 132 path.join(temp, 'linkdir')
133 ])); 133 ]));
134 }), completes); 134 }), completes);
135 }); 135 });
136 }); 136 });
137 137
138 group('canonicalize', () {
139 test('resolves a non-link', () {
140 expect(withTempDir((temp) {
141 var filePath = path.join(temp, 'file');
142 writeTextFile(filePath, '');
143 expect(canonicalize(filePath), equals(filePath));
144 }), completes);
145 });
146
147 test('resolves a non-existent file', () {
148 expect(withTempDir((temp) {
149 expect(canonicalize(path.join(temp, 'nothing')),
150 equals(path.join(temp, 'nothing')));
151 }), completes);
152 });
153
154 test('resolves a symlink', () {
155 expect(withTempDir((temp) {
156 createDir(path.join(temp, 'linked-dir'));
157 createSymlink(
158 path.join(temp, 'linked-dir'),
159 path.join(temp, 'dir'));
160 expect(
161 canonicalize(path.join(temp, 'dir')),
162 equals(path.join(temp, 'linked-dir')));
163 }), completes);
164 });
165
166 test('resolves a relative symlink', () {
167 expect(withTempDir((temp) {
168 createDir(path.join(temp, 'linked-dir'));
169 createSymlink(
170 path.join(temp, 'linked-dir'),
171 path.join(temp, 'dir'),
172 relative: true);
173 expect(
174 canonicalize(path.join(temp, 'dir')),
175 equals(path.join(temp, 'linked-dir')));
176 }), completes);
177 });
178
179 test('resolves a single-level horizontally recursive symlink', () {
180 expect(withTempDir((temp) {
181 var linkPath = path.join(temp, 'foo');
182 createSymlink(linkPath, linkPath);
183 expect(canonicalize(linkPath), equals(linkPath));
184 }), completes);
185 });
186
187 test('resolves a multi-level horizontally recursive symlink', () {
188 expect(withTempDir((temp) {
189 var fooPath = path.join(temp, 'foo');
190 var barPath = path.join(temp, 'bar');
191 var bazPath = path.join(temp, 'baz');
192 createSymlink(barPath, fooPath);
193 createSymlink(bazPath, barPath);
194 createSymlink(fooPath, bazPath);
195 expect(canonicalize(fooPath), equals(fooPath));
196 expect(canonicalize(barPath), equals(barPath));
197 expect(canonicalize(bazPath), equals(bazPath));
198
199 createSymlink(fooPath, path.join(temp, 'outer'));
200 expect(canonicalize(path.join(temp, 'outer')), equals(fooPath));
201 }), completes);
202 });
203
204 test('resolves a broken symlink', () {
205 expect(withTempDir((temp) {
206 createSymlink(path.join(temp, 'nonexistent'), path.join(temp, 'foo'));
207 expect(
208 canonicalize(path.join(temp, 'foo')),
209 equals(path.join(temp, 'nonexistent')));
210 }), completes);
211 });
212
213 test('resolves multiple nested symlinks', () {
214 expect(withTempDir((temp) {
215 var dir1 = path.join(temp, 'dir1');
216 var dir2 = path.join(temp, 'dir2');
217 var subdir1 = path.join(dir1, 'subdir1');
218 var subdir2 = path.join(dir2, 'subdir2');
219 createDir(dir2);
220 createDir(subdir2);
221 createSymlink(dir2, dir1);
222 createSymlink(subdir2, subdir1);
223 expect(
224 canonicalize(path.join(subdir1, 'file')),
225 equals(path.join(subdir2, 'file')));
226 }), completes);
227 });
228
229 test('resolves a nested vertical symlink', () {
230 expect(withTempDir((temp) {
231 var dir1 = path.join(temp, 'dir1');
232 var dir2 = path.join(temp, 'dir2');
233 var subdir = path.join(dir1, 'subdir');
234 createDir(dir1);
235 createDir(dir2);
236 createSymlink(dir2, subdir);
237 expect(
238 canonicalize(path.join(subdir, 'file')),
239 equals(path.join(dir2, 'file')));
240 }), completes);
241 });
242
243 test('resolves a vertically recursive symlink', () {
244 expect(withTempDir((temp) {
245 var dir = path.join(temp, 'dir');
246 var subdir = path.join(dir, 'subdir');
247 createDir(dir);
248 createSymlink(dir, subdir);
249 expect(
250 canonicalize(path.join(temp, 'dir', 'subdir', 'subdir', 'subdir',
251 'subdir', 'file')),
252 equals(path.join(dir, 'file')));
253 }), completes);
254 });
255 });
256
138 testExistencePredicate("entryExists", entryExists, 257 testExistencePredicate("entryExists", entryExists,
139 forFile: true, 258 forFile: true,
140 forFileSymlink: true, 259 forFileSymlink: true,
141 forMultiLevelFileSymlink: true, 260 forMultiLevelFileSymlink: true,
142 forDirectory: true, 261 forDirectory: true,
143 forDirectorySymlink: true, 262 forDirectorySymlink: true,
144 forMultiLevelDirectorySymlink: true, 263 forMultiLevelDirectorySymlink: true,
145 forBrokenSymlink: true, 264 forBrokenSymlink: true,
146 forMultiLevelBrokenSymlink: true); 265 forMultiLevelBrokenSymlink: true);
147 266
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 var symlink2Path = path.join(temp, "link2.txt"); 390 var symlink2Path = path.join(temp, "link2.txt");
272 writeTextFile(targetPath, "contents"); 391 writeTextFile(targetPath, "contents");
273 createSymlink(targetPath, symlink1Path); 392 createSymlink(targetPath, symlink1Path);
274 createSymlink(symlink1Path, symlink2Path); 393 createSymlink(symlink1Path, symlink2Path);
275 expect(predicate(symlink2Path), equals(forMultiLevelFileSymlink)); 394 expect(predicate(symlink2Path), equals(forMultiLevelFileSymlink));
276 }), completes); 395 }), completes);
277 }); 396 });
278 } 397 }
279 }); 398 });
280 } 399 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/test/install/path/shared_dependency_symlink_test.dart ('k') | sdk/lib/_internal/pub/test/test_pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698