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 '../../../pkg/unittest/lib/unittest.dart'; | 7 import '../../../pkg/unittest/lib/unittest.dart'; |
8 import '../../pub/io.dart'; | 8 import '../../pub/io.dart'; |
9 | 9 |
10 main() { | 10 main() { |
11 group('listDir', () { | 11 group('listDir', () { |
12 test('lists a simple directory non-recursively', () { | 12 test('lists a simple directory non-recursively', () { |
13 expect(withTempDir((path) { | 13 expect(withTempDir((path) { |
14 var future = writeTextFile(join(path, 'file1.txt'), '') | 14 var future = writeTextFile(join(path, 'file1.txt'), '') |
15 .chain((_) => writeTextFile(join(path, 'file2.txt'), '')) | 15 .then((_) => writeTextFile(join(path, 'file2.txt'), '')) |
16 .chain((_) => createDir(join(path, 'subdir'))) | 16 .then((_) => createDir(join(path, 'subdir'))) |
17 .chain((_) => writeTextFile(join(path, 'subdir', 'file3.txt'), '')) | 17 .then((_) => writeTextFile(join(path, 'subdir', 'file3.txt'), '')) |
18 .chain((_) => listDir(path)); | 18 .then((_) => listDir(path)); |
19 expect(future, completion(unorderedEquals([ | 19 expect(future, completion(unorderedEquals([ |
20 join(path, 'file1.txt'), | 20 join(path, 'file1.txt'), |
21 join(path, 'file2.txt'), | 21 join(path, 'file2.txt'), |
22 join(path, 'subdir') | 22 join(path, 'subdir') |
23 ]))); | 23 ]))); |
24 return future; | 24 return future; |
25 }), completes); | 25 }), completes); |
26 }); | 26 }); |
27 | 27 |
28 test('lists a simple directory recursively', () { | 28 test('lists a simple directory recursively', () { |
29 expect(withTempDir((path) { | 29 expect(withTempDir((path) { |
30 var future = writeTextFile(join(path, 'file1.txt'), '') | 30 var future = writeTextFile(join(path, 'file1.txt'), '') |
31 .chain((_) => writeTextFile(join(path, 'file2.txt'), '')) | 31 .then((_) => writeTextFile(join(path, 'file2.txt'), '')) |
32 .chain((_) => createDir(join(path, 'subdir'))) | 32 .then((_) => createDir(join(path, 'subdir'))) |
33 .chain((_) => writeTextFile(join(path, 'subdir', 'file3.txt'), '')) | 33 .then((_) => writeTextFile(join(path, 'subdir', 'file3.txt'), '')) |
34 .chain((_) => listDir(path, recursive: true)); | 34 .then((_) => listDir(path, recursive: true)); |
35 expect(future, completion(unorderedEquals([ | 35 expect(future, completion(unorderedEquals([ |
36 join(path, 'file1.txt'), | 36 join(path, 'file1.txt'), |
37 join(path, 'file2.txt'), | 37 join(path, 'file2.txt'), |
38 join(path, 'subdir'), | 38 join(path, 'subdir'), |
39 join(path, 'subdir/file3.txt'), | 39 join(path, 'subdir/file3.txt'), |
40 ]))); | 40 ]))); |
41 return future; | 41 return future; |
42 }), completes); | 42 }), completes); |
43 }); | 43 }); |
44 | 44 |
45 test('ignores hidden files by default', () { | 45 test('ignores hidden files by default', () { |
46 expect(withTempDir((path) { | 46 expect(withTempDir((path) { |
47 var future = writeTextFile(join(path, 'file1.txt'), '') | 47 var future = writeTextFile(join(path, 'file1.txt'), '') |
48 .chain((_) => writeTextFile(join(path, 'file2.txt'), '')) | 48 .then((_) => writeTextFile(join(path, 'file2.txt'), '')) |
49 .chain((_) => writeTextFile(join(path, '.file3.txt'), '')) | 49 .then((_) => writeTextFile(join(path, '.file3.txt'), '')) |
50 .chain((_) => createDir(join(path, '.subdir'))) | 50 .then((_) => createDir(join(path, '.subdir'))) |
51 .chain((_) => writeTextFile(join(path, '.subdir', 'file3.txt'), '')) | 51 .then((_) => writeTextFile(join(path, '.subdir', 'file3.txt'), '')) |
52 .chain((_) => listDir(path, recursive: true)); | 52 .then((_) => listDir(path, recursive: true)); |
53 expect(future, completion(unorderedEquals([ | 53 expect(future, completion(unorderedEquals([ |
54 join(path, 'file1.txt'), | 54 join(path, 'file1.txt'), |
55 join(path, 'file2.txt') | 55 join(path, 'file2.txt') |
56 ]))); | 56 ]))); |
57 return future; | 57 return future; |
58 }), completes); | 58 }), completes); |
59 }); | 59 }); |
60 | 60 |
61 test('includes hidden files when told to', () { | 61 test('includes hidden files when told to', () { |
62 expect(withTempDir((path) { | 62 expect(withTempDir((path) { |
63 var future = writeTextFile(join(path, 'file1.txt'), '') | 63 var future = writeTextFile(join(path, 'file1.txt'), '') |
64 .chain((_) => writeTextFile(join(path, 'file2.txt'), '')) | 64 .then((_) => writeTextFile(join(path, 'file2.txt'), '')) |
65 .chain((_) => writeTextFile(join(path, '.file3.txt'), '')) | 65 .then((_) => writeTextFile(join(path, '.file3.txt'), '')) |
66 .chain((_) => createDir(join(path, '.subdir'))) | 66 .then((_) => createDir(join(path, '.subdir'))) |
67 .chain((_) => writeTextFile(join(path, '.subdir', 'file3.txt'), '')) | 67 .then((_) => writeTextFile(join(path, '.subdir', 'file3.txt'), '')) |
68 .chain((_) { | 68 .then((_) { |
69 return listDir(path, recursive: true, includeHiddenFiles: true); | 69 return listDir(path, recursive: true, includeHiddenFiles: true); |
70 }); | 70 }); |
71 expect(future, completion(unorderedEquals([ | 71 expect(future, completion(unorderedEquals([ |
72 join(path, 'file1.txt'), | 72 join(path, 'file1.txt'), |
73 join(path, 'file2.txt'), | 73 join(path, 'file2.txt'), |
74 join(path, '.file3.txt'), | 74 join(path, '.file3.txt'), |
75 join(path, '.subdir'), | 75 join(path, '.subdir'), |
76 join(path, '.subdir/file3.txt') | 76 join(path, '.subdir/file3.txt') |
77 ]))); | 77 ]))); |
78 return future; | 78 return future; |
79 }), completes); | 79 }), completes); |
80 }); | 80 }); |
81 | 81 |
82 test('returns the unresolved paths for symlinks', () { | 82 test('returns the unresolved paths for symlinks', () { |
83 expect(withTempDir((path) { | 83 expect(withTempDir((path) { |
84 var dirToList = join(path, 'dir-to-list'); | 84 var dirToList = join(path, 'dir-to-list'); |
85 var future = writeTextFile(join(path, 'file1.txt'), '') | 85 var future = writeTextFile(join(path, 'file1.txt'), '') |
86 .chain((_) => writeTextFile(join(path, 'file2.txt'), '')) | 86 .then((_) => writeTextFile(join(path, 'file2.txt'), '')) |
87 .chain((_) => createDir(dirToList)) | 87 .then((_) => createDir(dirToList)) |
88 .chain((_) { | 88 .then((_) { |
89 return createSymlink( | 89 return createSymlink( |
90 join(path, 'file1.txt'), | 90 join(path, 'file1.txt'), |
91 join(dirToList, 'link1')); | 91 join(dirToList, 'link1')); |
92 }).chain((_) => createDir(join(dirToList, 'subdir'))) | 92 }).then((_) => createDir(join(dirToList, 'subdir'))) |
93 .chain((_) { | 93 .then((_) { |
94 return createSymlink( | 94 return createSymlink( |
95 join(path, 'file2.txt'), | 95 join(path, 'file2.txt'), |
96 join(dirToList, 'subdir', 'link2')); | 96 join(dirToList, 'subdir', 'link2')); |
97 }).chain((_) => listDir(dirToList, recursive: true)); | 97 }).then((_) => listDir(dirToList, recursive: true)); |
98 expect(future, completion(unorderedEquals([ | 98 expect(future, completion(unorderedEquals([ |
99 join(dirToList, 'link1'), | 99 join(dirToList, 'link1'), |
100 join(dirToList, 'subdir'), | 100 join(dirToList, 'subdir'), |
101 join(dirToList, 'subdir/link2'), | 101 join(dirToList, 'subdir/link2'), |
102 ]))); | 102 ]))); |
103 return future; | 103 return future; |
104 }), completes); | 104 }), completes); |
105 }); | 105 }); |
106 | 106 |
107 test('works with recursive symlinks', () { | 107 test('works with recursive symlinks', () { |
108 expect(withTempDir((path) { | 108 expect(withTempDir((path) { |
109 var future = writeTextFile(join(path, 'file1.txt'), '') | 109 var future = writeTextFile(join(path, 'file1.txt'), '') |
110 .chain((_) => createSymlink(path, join(path, 'linkdir'))) | 110 .then((_) => createSymlink(path, join(path, 'linkdir'))) |
111 .chain((_) => listDir(path, recursive: true)); | 111 .then((_) => listDir(path, recursive: true)); |
112 expect(future, completion(unorderedEquals([ | 112 expect(future, completion(unorderedEquals([ |
113 join(path, 'file1.txt'), | 113 join(path, 'file1.txt'), |
114 join(path, 'linkdir') | 114 join(path, 'linkdir') |
115 ]))); | 115 ]))); |
116 return future; | 116 return future; |
117 }), completes); | 117 }), completes); |
118 }); | 118 }); |
119 }); | 119 }); |
120 } | 120 } |
OLD | NEW |