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