OLD | NEW |
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:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
12 | 12 |
13 import '../lib/src/io.dart'; | 13 import '../lib/src/io.dart'; |
14 import 'test_pub.dart'; | 14 import 'test_pub.dart'; |
15 | 15 |
16 main() { | 16 main() { |
17 initConfig(); | 17 initConfig(); |
18 | 18 |
19 group('listDir', () { | 19 group('listDir', () { |
20 test('lists a simple directory non-recursively', () { | |
21 expect(withTempDir((temp) { | |
22 writeTextFile(path.join(temp, 'file1.txt'), ''); | |
23 writeTextFile(path.join(temp, 'file2.txt'), ''); | |
24 createDir(path.join(temp, 'subdir')); | |
25 writeTextFile(path.join(temp, 'subdir', 'file3.txt'), ''); | |
26 | |
27 expect(listDir(temp), unorderedEquals([ | |
28 path.join(temp, 'file1.txt'), | |
29 path.join(temp, 'file2.txt'), | |
30 path.join(temp, 'subdir') | |
31 ])); | |
32 }), completes); | |
33 }); | |
34 | |
35 test('lists a simple directory recursively', () { | |
36 expect(withTempDir((temp) { | |
37 writeTextFile(path.join(temp, 'file1.txt'), ''); | |
38 writeTextFile(path.join(temp, 'file2.txt'), ''); | |
39 createDir(path.join(temp, 'subdir')); | |
40 writeTextFile(path.join(temp, 'subdir', 'file3.txt'), ''); | |
41 | |
42 expect(listDir(temp, recursive: true), unorderedEquals([ | |
43 path.join(temp, 'file1.txt'), | |
44 path.join(temp, 'file2.txt'), | |
45 path.join(temp, 'subdir'), | |
46 path.join(temp, 'subdir', 'file3.txt'), | |
47 ])); | |
48 }), completes); | |
49 }); | |
50 | |
51 test('ignores hidden files by default', () { | 20 test('ignores hidden files by default', () { |
52 expect(withTempDir((temp) { | 21 expect(withTempDir((temp) { |
53 writeTextFile(path.join(temp, 'file1.txt'), ''); | 22 writeTextFile(path.join(temp, 'file1.txt'), ''); |
54 writeTextFile(path.join(temp, 'file2.txt'), ''); | 23 writeTextFile(path.join(temp, 'file2.txt'), ''); |
55 writeTextFile(path.join(temp, '.file3.txt'), ''); | 24 writeTextFile(path.join(temp, '.file3.txt'), ''); |
56 createDir(path.join(temp, '.subdir')); | 25 createDir(path.join(temp, '.subdir')); |
57 writeTextFile(path.join(temp, '.subdir', 'file3.txt'), ''); | 26 writeTextFile(path.join(temp, '.subdir', 'file3.txt'), ''); |
58 | 27 |
59 expect(listDir(temp, recursive: true), unorderedEquals([ | 28 expect(listDir(temp, recursive: true), unorderedEquals([ |
60 path.join(temp, 'file1.txt'), | 29 path.join(temp, 'file1.txt'), |
(...skipping 13 matching lines...) Expand all Loading... |
74 expect(listDir(temp, recursive: true, includeHidden: true), | 43 expect(listDir(temp, recursive: true, includeHidden: true), |
75 unorderedEquals([ | 44 unorderedEquals([ |
76 path.join(temp, 'file1.txt'), | 45 path.join(temp, 'file1.txt'), |
77 path.join(temp, 'file2.txt'), | 46 path.join(temp, 'file2.txt'), |
78 path.join(temp, '.file3.txt'), | 47 path.join(temp, '.file3.txt'), |
79 path.join(temp, '.subdir'), | 48 path.join(temp, '.subdir'), |
80 path.join(temp, '.subdir', 'file3.txt') | 49 path.join(temp, '.subdir', 'file3.txt') |
81 ])); | 50 ])); |
82 }), completes); | 51 }), completes); |
83 }); | 52 }); |
84 | |
85 test('returns the unresolved paths for symlinks', () { | |
86 expect(withTempDir((temp) { | |
87 var dirToList = path.join(temp, 'dir-to-list'); | |
88 createDir(path.join(temp, 'dir1')); | |
89 writeTextFile(path.join(temp, 'dir1', 'file1.txt'), ''); | |
90 createDir(path.join(temp, 'dir2')); | |
91 writeTextFile(path.join(temp, 'dir2', 'file2.txt'), ''); | |
92 createDir(dirToList); | |
93 createSymlink( | |
94 path.join(temp, 'dir1'), | |
95 path.join(dirToList, 'linked-dir1')); | |
96 createDir(path.join(dirToList, 'subdir')); | |
97 createSymlink( | |
98 path.join(temp, 'dir2'), | |
99 path.join(dirToList, 'subdir', 'linked-dir2')); | |
100 | |
101 expect(listDir(dirToList, recursive: true), unorderedEquals([ | |
102 path.join(dirToList, 'linked-dir1'), | |
103 path.join(dirToList, 'linked-dir1', 'file1.txt'), | |
104 path.join(dirToList, 'subdir'), | |
105 path.join(dirToList, 'subdir', 'linked-dir2'), | |
106 path.join(dirToList, 'subdir', 'linked-dir2', 'file2.txt'), | |
107 ])); | |
108 }), completes); | |
109 }); | |
110 | |
111 test('works with recursive symlinks', () { | |
112 expect(withTempDir((temp) { | |
113 writeTextFile(path.join(temp, 'file1.txt'), ''); | |
114 createSymlink(temp, path.join(temp, 'linkdir')); | |
115 | |
116 expect(listDir(temp, recursive: true), unorderedEquals([ | |
117 path.join(temp, 'file1.txt'), | |
118 path.join(temp, 'linkdir') | |
119 ])); | |
120 }), completes); | |
121 }); | |
122 | |
123 test('treats a broken symlink as a file', () { | |
124 expect(withTempDir((temp) { | |
125 writeTextFile(path.join(temp, 'file1.txt'), ''); | |
126 createDir(path.join(temp, 'dir')); | |
127 createSymlink(path.join(temp, 'dir'), path.join(temp, 'linkdir')); | |
128 deleteEntry(path.join(temp, 'dir')); | |
129 | |
130 expect(listDir(temp, recursive: true), unorderedEquals([ | |
131 path.join(temp, 'file1.txt'), | |
132 path.join(temp, 'linkdir') | |
133 ])); | |
134 }), completes); | |
135 }); | |
136 }); | 53 }); |
137 | 54 |
138 group('canonicalize', () { | 55 group('canonicalize', () { |
139 test('resolves a non-link', () { | 56 test('resolves a non-link', () { |
140 expect(withCanonicalTempDir((temp) { | 57 expect(withCanonicalTempDir((temp) { |
141 var filePath = path.join(temp, 'file'); | 58 var filePath = path.join(temp, 'file'); |
142 writeTextFile(filePath, ''); | 59 writeTextFile(filePath, ''); |
143 expect(canonicalize(filePath), equals(filePath)); | 60 expect(canonicalize(filePath), equals(filePath)); |
144 }), completes); | 61 }), completes); |
145 }); | 62 }); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 expect(predicate(symlink2Path), equals(forMultiLevelFileSymlink)); | 340 expect(predicate(symlink2Path), equals(forMultiLevelFileSymlink)); |
424 }), completes); | 341 }), completes); |
425 }); | 342 }); |
426 } | 343 } |
427 }); | 344 }); |
428 } | 345 } |
429 | 346 |
430 /// Like [withTempDir], but canonicalizes the path before passing it to [fn]. | 347 /// Like [withTempDir], but canonicalizes the path before passing it to [fn]. |
431 Future withCanonicalTempDir(Future fn(String path)) => | 348 Future withCanonicalTempDir(Future fn(String path)) => |
432 withTempDir((temp) => fn(canonicalize(temp))); | 349 withTempDir((temp) => fn(canonicalize(temp))); |
OLD | NEW |