| 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 import '../../pub/utils.dart'; | 9 import '../../pub/utils.dart'; |
| 10 import 'test_pub.dart'; |
| 10 | 11 |
| 11 main() { | 12 main() { |
| 13 initConfig(); |
| 14 |
| 12 group('listDir', () { | 15 group('listDir', () { |
| 13 test('lists a simple directory non-recursively', () { | 16 test('lists a simple directory non-recursively', () { |
| 14 expect(withTempDir((path) { | 17 expect(withTempDir((path) { |
| 15 var future = defer(() { | 18 var future = defer(() { |
| 16 writeTextFile(join(path, 'file1.txt'), ''); | 19 writeTextFile(join(path, 'file1.txt'), ''); |
| 17 writeTextFile(join(path, 'file2.txt'), ''); | 20 writeTextFile(join(path, 'file2.txt'), ''); |
| 18 createDir(join(path, 'subdir')); | 21 createDir(join(path, 'subdir')); |
| 19 writeTextFile(join(path, 'subdir', 'file3.txt'), ''); | 22 writeTextFile(join(path, 'subdir', 'file3.txt'), ''); |
| 20 return listDir(path); | 23 return listDir(path); |
| 21 }); | 24 }); |
| 22 expect(future, completion(unorderedEquals([ | 25 expect(future, completion(unorderedEquals([ |
| 23 join(path, 'file1.txt'), | 26 join(path, 'file1.txt'), |
| 24 join(path, 'file2.txt'), | 27 join(path, 'file2.txt'), |
| 25 join(path, 'subdir') | 28 join(path, 'subdir') |
| 26 ]))); | 29 ]))); |
| 27 return future; | 30 return future; |
| 28 }), completes); | 31 }), completes); |
| 29 }); | 32 }); |
| 30 | 33 |
| 31 test('lists a simple directory recursively', () { | 34 test('lists a simple directory recursively', () { |
| 32 expect(withTempDir((path) { | 35 expect(withTempDir((path) { |
| 33 var future = defer(() { | 36 var future = defer(() { |
| 34 writeTextFile(join(path, 'file1.txt'), ''); | 37 writeTextFile(join(path, 'file1.txt'), ''); |
| 35 writeTextFile(join(path, 'file2.txt'), ''); | 38 writeTextFile(join(path, 'file2.txt'), ''); |
| 36 createDir(join(path, 'subdir')); | 39 createDir(join(path, 'subdir')); |
| 37 writeTextFile(join(path, 'subdir', 'file3.txt'), ''); | 40 writeTextFile(join(path, 'subdir', 'file3.txt'), ''); |
| 38 return listDir(path, recursive: true); | 41 return listDir(path, recursive: true); |
| 39 }); | 42 }); |
| 43 |
| 40 expect(future, completion(unorderedEquals([ | 44 expect(future, completion(unorderedEquals([ |
| 41 join(path, 'file1.txt'), | 45 join(path, 'file1.txt'), |
| 42 join(path, 'file2.txt'), | 46 join(path, 'file2.txt'), |
| 43 join(path, 'subdir'), | 47 join(path, 'subdir'), |
| 44 join(path, 'subdir/file3.txt'), | 48 join(path, 'subdir', 'file3.txt'), |
| 45 ]))); | 49 ]))); |
| 46 return future; | 50 return future; |
| 47 }), completes); | 51 }), completes); |
| 48 }); | 52 }); |
| 49 | 53 |
| 50 test('ignores hidden files by default', () { | 54 test('ignores hidden files by default', () { |
| 51 expect(withTempDir((path) { | 55 expect(withTempDir((path) { |
| 52 var future = defer(() { | 56 var future = defer(() { |
| 53 writeTextFile(join(path, 'file1.txt'), ''); | 57 writeTextFile(join(path, 'file1.txt'), ''); |
| 54 writeTextFile(join(path, 'file2.txt'), ''); | 58 writeTextFile(join(path, 'file2.txt'), ''); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 73 writeTextFile(join(path, '.file3.txt'), ''); | 77 writeTextFile(join(path, '.file3.txt'), ''); |
| 74 createDir(join(path, '.subdir')); | 78 createDir(join(path, '.subdir')); |
| 75 writeTextFile(join(path, '.subdir', 'file3.txt'), ''); | 79 writeTextFile(join(path, '.subdir', 'file3.txt'), ''); |
| 76 return listDir(path, recursive: true, includeHiddenFiles: true); | 80 return listDir(path, recursive: true, includeHiddenFiles: true); |
| 77 }); | 81 }); |
| 78 expect(future, completion(unorderedEquals([ | 82 expect(future, completion(unorderedEquals([ |
| 79 join(path, 'file1.txt'), | 83 join(path, 'file1.txt'), |
| 80 join(path, 'file2.txt'), | 84 join(path, 'file2.txt'), |
| 81 join(path, '.file3.txt'), | 85 join(path, '.file3.txt'), |
| 82 join(path, '.subdir'), | 86 join(path, '.subdir'), |
| 83 join(path, '.subdir/file3.txt') | 87 join(path, '.subdir', 'file3.txt') |
| 84 ]))); | 88 ]))); |
| 85 return future; | 89 return future; |
| 86 }), completes); | 90 }), completes); |
| 87 }); | 91 }); |
| 88 | 92 |
| 89 test('returns the unresolved paths for symlinks', () { | 93 test('returns the unresolved paths for symlinks', () { |
| 90 expect(withTempDir((path) { | 94 expect(withTempDir((path) { |
| 91 var dirToList = join(path, 'dir-to-list'); | 95 var dirToList = join(path, 'dir-to-list'); |
| 92 var future = defer(() { | 96 var future = defer(() { |
| 93 writeTextFile(join(path, 'file1.txt'), ''); | 97 createDir(join(path, 'dir1')); |
| 94 writeTextFile(join(path, 'file2.txt'), ''); | 98 writeTextFile(join(path, 'dir1', 'file1.txt'), ''); |
| 99 createDir(join(path, 'dir2')); |
| 100 writeTextFile(join(path, 'dir2', 'file2.txt'), ''); |
| 95 createDir(dirToList); | 101 createDir(dirToList); |
| 96 return createSymlink(join(path, 'file1.txt'), | 102 return createSymlink(join(path, 'dir1'), |
| 97 join(dirToList, 'link1')); | 103 join(dirToList, 'linked-dir1')); |
| 98 }).then((_) { | 104 }).then((_) { |
| 99 createDir(join(dirToList, 'subdir')); | 105 createDir(join(dirToList, 'subdir')); |
| 100 return createSymlink( | 106 return createSymlink( |
| 101 join(path, 'file2.txt'), | 107 join(path, 'dir2'), |
| 102 join(dirToList, 'subdir', 'link2')); | 108 join(dirToList, 'subdir', 'linked-dir2')); |
| 103 }).then((_) => listDir(dirToList, recursive: true)); | 109 }).then((_) => listDir(dirToList, recursive: true)); |
| 104 expect(future, completion(unorderedEquals([ | 110 expect(future, completion(unorderedEquals([ |
| 105 join(dirToList, 'link1'), | 111 join(dirToList, 'linked-dir1'), |
| 112 join(dirToList, 'linked-dir1', 'file1.txt'), |
| 106 join(dirToList, 'subdir'), | 113 join(dirToList, 'subdir'), |
| 107 join(dirToList, 'subdir/link2'), | 114 join(dirToList, 'subdir', 'linked-dir2'), |
| 115 join(dirToList, 'subdir', 'linked-dir2', 'file2.txt'), |
| 108 ]))); | 116 ]))); |
| 109 return future; | 117 return future; |
| 110 }), completes); | 118 }), completes); |
| 111 }); | 119 }); |
| 112 | 120 |
| 113 test('works with recursive symlinks', () { | 121 test('works with recursive symlinks', () { |
| 114 expect(withTempDir((path) { | 122 expect(withTempDir((path) { |
| 115 var future = defer(() { | 123 var future = defer(() { |
| 116 writeTextFile(join(path, 'file1.txt'), ''); | 124 writeTextFile(join(path, 'file1.txt'), ''); |
| 117 return createSymlink(path, join(path, 'linkdir')); | 125 return createSymlink(path, join(path, 'linkdir')); |
| 118 }).then((_) => listDir(path, recursive: true)); | 126 }).then((_) => listDir(path, recursive: true)); |
| 119 expect(future, completion(unorderedEquals([ | 127 expect(future, completion(unorderedEquals([ |
| 120 join(path, 'file1.txt'), | 128 join(path, 'file1.txt'), |
| 121 join(path, 'linkdir') | 129 join(path, 'linkdir') |
| 122 ]))); | 130 ]))); |
| 123 return future; | 131 return future; |
| 124 }), completes); | 132 }), completes); |
| 125 }); | 133 }); |
| 126 }); | 134 }); |
| 127 } | 135 } |
| OLD | NEW |