| 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 import "dart:io"; | 5 import "dart:io"; |
| 6 import "dart:isolate"; | 6 import "dart:isolate"; |
| 7 | 7 |
| 8 | 8 |
| 9 createLink(String dst, String link, bool symbolic, void callback()) { | 9 createLink(String dst, String link, bool symbolic, void callback()) { |
| 10 var args = [ symbolic ? '-s' : '', dst, link ]; | 10 var args = [ symbolic ? '-s' : '', dst, link ]; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 var temp = new Directory('').createTempSync(); | 124 var temp = new Directory('').createTempSync(); |
| 125 var temp2 = new Directory('').createTempSync(); | 125 var temp2 = new Directory('').createTempSync(); |
| 126 var y = '${temp.path}${Platform.pathSeparator}y'; | 126 var y = '${temp.path}${Platform.pathSeparator}y'; |
| 127 var x = '${temp2.path}${Platform.pathSeparator}x'; | 127 var x = '${temp2.path}${Platform.pathSeparator}x'; |
| 128 new File(x).createSync(); | 128 new File(x).createSync(); |
| 129 createLink(temp2.path, y, true, () { | 129 createLink(temp2.path, y, true, () { |
| 130 var files = []; | 130 var files = []; |
| 131 var dirs = []; | 131 var dirs = []; |
| 132 for (var entry in temp.listSync(recursive:true)) { | 132 for (var entry in temp.listSync(recursive:true)) { |
| 133 if (entry is File) { | 133 if (entry is File) { |
| 134 files.add(entry.name); | 134 files.add(entry.path); |
| 135 } else { | 135 } else { |
| 136 Expect.isTrue(entry is Directory); | 136 Expect.isTrue(entry is Directory); |
| 137 dirs.add(entry.path); | 137 dirs.add(entry.path); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 Expect.equals(1, files.length); | 140 Expect.equals(1, files.length); |
| 141 Expect.isTrue(files[0].endsWith('$y${Platform.pathSeparator}x')); | 141 Expect.isTrue(files[0].endsWith('$y${Platform.pathSeparator}x')); |
| 142 Expect.equals(1, dirs.length); | 142 Expect.equals(1, dirs.length); |
| 143 Expect.isTrue(dirs[0].endsWith(y)); | 143 Expect.isTrue(dirs[0].endsWith(y)); |
| 144 | 144 |
| 145 files = []; | 145 files = []; |
| 146 dirs = []; | 146 dirs = []; |
| 147 var lister = temp.list(recursive: true).listen( | 147 var lister = temp.list(recursive: true).listen( |
| 148 (entity) { | 148 (entity) { |
| 149 if (entity is File) { | 149 if (entity is File) { |
| 150 files.add(entity.name); | 150 files.add(entity.path); |
| 151 } else { | 151 } else { |
| 152 Expect.isTrue(entity is Directory); | 152 Expect.isTrue(entity is Directory); |
| 153 dirs.add(entity.path); | 153 dirs.add(entity.path); |
| 154 } | 154 } |
| 155 }, | 155 }, |
| 156 onDone: () { | 156 onDone: () { |
| 157 Expect.equals(1, files.length); | 157 Expect.equals(1, files.length); |
| 158 Expect.isTrue(files[0].endsWith('$y${Platform.pathSeparator}x')); | 158 Expect.isTrue(files[0].endsWith('$y${Platform.pathSeparator}x')); |
| 159 Expect.equals(1, dirs.length); | 159 Expect.equals(1, dirs.length); |
| 160 Expect.isTrue(dirs[0].endsWith(y)); | 160 Expect.isTrue(dirs[0].endsWith(y)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 175 new File(x).createSync(); | 175 new File(x).createSync(); |
| 176 createLink(doesNotExist, link, true, () { | 176 createLink(doesNotExist, link, true, () { |
| 177 Expect.throws(() => temp.listSync(recursive: true), | 177 Expect.throws(() => temp.listSync(recursive: true), |
| 178 (e) => e is DirectoryIOException); | 178 (e) => e is DirectoryIOException); |
| 179 var files = []; | 179 var files = []; |
| 180 var dirs = []; | 180 var dirs = []; |
| 181 var errors = []; | 181 var errors = []; |
| 182 temp.list(recursive: true).listen( | 182 temp.list(recursive: true).listen( |
| 183 (entity) { | 183 (entity) { |
| 184 if (entity is File) { | 184 if (entity is File) { |
| 185 files.add(entity.name); | 185 files.add(entity.path); |
| 186 } else { | 186 } else { |
| 187 Expect.isTrue(entity is Directory); | 187 Expect.isTrue(entity is Directory); |
| 188 dirs.add(entity.path); | 188 dirs.add(entity.path); |
| 189 } | 189 } |
| 190 }, | 190 }, |
| 191 onError: (e) => errors.add(e), | 191 onError: (e) => errors.add(e), |
| 192 onDone: () { | 192 onDone: () { |
| 193 Expect.equals(1, files.length); | 193 Expect.equals(1, files.length); |
| 194 Expect.isTrue(files[0].endsWith(x)); | 194 Expect.isTrue(files[0].endsWith(x)); |
| 195 Expect.equals(0, dirs.length); | 195 Expect.equals(0, dirs.length); |
| 196 Expect.equals(1, errors.length); | 196 Expect.equals(1, errors.length); |
| 197 Expect.isTrue(errors[0].toString().contains(link)); | 197 Expect.isTrue(errors[0].toString().contains(link)); |
| 198 temp.deleteSync(recursive: true); | 198 temp.deleteSync(recursive: true); |
| 199 keepAlive.close(); | 199 keepAlive.close(); |
| 200 }); | 200 }); |
| 201 }); | 201 }); |
| 202 } | 202 } |
| 203 | 203 |
| 204 | 204 |
| 205 main() { | 205 main() { |
| 206 testFileExistsCreate(); | 206 testFileExistsCreate(); |
| 207 testFileDelete(); | 207 testFileDelete(); |
| 208 testFileWriteRead(); | 208 testFileWriteRead(); |
| 209 testDirectoryExistsCreate(); | 209 testDirectoryExistsCreate(); |
| 210 testDirectoryDelete(); | 210 testDirectoryDelete(); |
| 211 testDirectoryListing(); | 211 testDirectoryListing(); |
| 212 testDirectoryListingBrokenLink(); | 212 testDirectoryListingBrokenLink(); |
| 213 } | 213 } |
| OLD | NEW |