| 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 | 7 |
| 7 | 8 |
| 8 createLink(String dst, String link, bool symbolic, void callback()) { | 9 createLink(String dst, String link, bool symbolic, void callback()) { |
| 9 var args = [ symbolic ? '-s' : '', dst, link ]; | 10 var args = [ symbolic ? '-s' : '', dst, link ]; |
| 10 var script = 'tests/standalone/io/ln.sh'; | 11 var script = 'tests/standalone/io/ln.sh'; |
| 11 if (!new File(script).existsSync()) { | 12 if (!new File(script).existsSync()) { |
| 12 script = '../$script'; | 13 script = '../$script'; |
| 13 } | 14 } |
| 14 Process.run(script, args).then((result) { | 15 Process.run(script, args).then((result) { |
| 15 if (result.exitCode == 0) { | 16 if (result.exitCode == 0) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 60 } |
| 60 | 61 |
| 61 | 62 |
| 62 testFileWriteRead() { | 63 testFileWriteRead() { |
| 63 var temp = new Directory('').createTempSync(); | 64 var temp = new Directory('').createTempSync(); |
| 64 var x = '${temp.path}${Platform.pathSeparator}x'; | 65 var x = '${temp.path}${Platform.pathSeparator}x'; |
| 65 var y = '${temp.path}${Platform.pathSeparator}y'; | 66 var y = '${temp.path}${Platform.pathSeparator}y'; |
| 66 new File(x).createSync(); | 67 new File(x).createSync(); |
| 67 createLink(x, y, true, () { | 68 createLink(x, y, true, () { |
| 68 var data = "asdf".charCodes; | 69 var data = "asdf".charCodes; |
| 69 var output = new File(y).openOutputStream(FileMode.WRITE); | 70 var output = new File(y).openWrite(FileMode.WRITE); |
| 70 output.write(data); | 71 output.add(data); |
| 71 output.onNoPendingWrites = () { | 72 output.close(); |
| 72 output.close(); | 73 output.done.then((_) { |
| 73 var read = new File(y).readAsBytesSync(); | 74 var read = new File(y).readAsBytesSync(); |
| 74 Expect.listEquals(data, read); | 75 Expect.listEquals(data, read); |
| 75 var read2 = new File(x).readAsBytesSync(); | 76 var read2 = new File(x).readAsBytesSync(); |
| 76 Expect.listEquals(data, read2); | 77 Expect.listEquals(data, read2); |
| 77 temp.deleteSync(recursive: true); | 78 temp.deleteSync(recursive: true); |
| 78 }; | 79 }); |
| 79 }); | 80 }); |
| 80 } | 81 } |
| 81 | 82 |
| 82 | 83 |
| 83 testDirectoryExistsCreate() { | 84 testDirectoryExistsCreate() { |
| 84 var temp = new Directory('').createTempSync(); | 85 var temp = new Directory('').createTempSync(); |
| 85 var x = '${temp.path}${Platform.pathSeparator}x'; | 86 var x = '${temp.path}${Platform.pathSeparator}x'; |
| 86 var y = '${temp.path}${Platform.pathSeparator}y'; | 87 var y = '${temp.path}${Platform.pathSeparator}y'; |
| 87 createLink(x, y, true, () { | 88 createLink(x, y, true, () { |
| 88 Expect.isFalse(new Directory(x).existsSync()); | 89 Expect.isFalse(new Directory(x).existsSync()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 112 Expect.isFalse(link.existsSync()); | 113 Expect.isFalse(link.existsSync()); |
| 113 Expect.isTrue(temp2.existsSync()); | 114 Expect.isTrue(temp2.existsSync()); |
| 114 Expect.isTrue(new File(x).existsSync()); | 115 Expect.isTrue(new File(x).existsSync()); |
| 115 temp2.deleteSync(recursive: true); | 116 temp2.deleteSync(recursive: true); |
| 116 }); | 117 }); |
| 117 }); | 118 }); |
| 118 } | 119 } |
| 119 | 120 |
| 120 | 121 |
| 121 testDirectoryListing() { | 122 testDirectoryListing() { |
| 123 var keepAlive = new ReceivePort(); |
| 122 var temp = new Directory('').createTempSync(); | 124 var temp = new Directory('').createTempSync(); |
| 123 var temp2 = new Directory('').createTempSync(); | 125 var temp2 = new Directory('').createTempSync(); |
| 124 var y = '${temp.path}${Platform.pathSeparator}y'; | 126 var y = '${temp.path}${Platform.pathSeparator}y'; |
| 125 var x = '${temp2.path}${Platform.pathSeparator}x'; | 127 var x = '${temp2.path}${Platform.pathSeparator}x'; |
| 126 new File(x).createSync(); | 128 new File(x).createSync(); |
| 127 createLink(temp2.path, y, true, () { | 129 createLink(temp2.path, y, true, () { |
| 128 var files = []; | 130 var files = []; |
| 129 var dirs = []; | 131 var dirs = []; |
| 130 for (var entry in temp.listSync(recursive:true)) { | 132 for (var entry in temp.listSync(recursive:true)) { |
| 131 if (entry is File) { | 133 if (entry is File) { |
| 132 files.add(entry.name); | 134 files.add(entry.name); |
| 133 } else { | 135 } else { |
| 134 Expect.isTrue(entry is Directory); | 136 Expect.isTrue(entry is Directory); |
| 135 dirs.add(entry.path); | 137 dirs.add(entry.path); |
| 136 } | 138 } |
| 137 } | 139 } |
| 138 Expect.equals(1, files.length); | 140 Expect.equals(1, files.length); |
| 139 Expect.isTrue(files[0].endsWith('$y${Platform.pathSeparator}x')); | 141 Expect.isTrue(files[0].endsWith('$y${Platform.pathSeparator}x')); |
| 140 Expect.equals(1, dirs.length); | 142 Expect.equals(1, dirs.length); |
| 141 Expect.isTrue(dirs[0].endsWith(y)); | 143 Expect.isTrue(dirs[0].endsWith(y)); |
| 142 | 144 |
| 143 files = []; | 145 files = []; |
| 144 dirs = []; | 146 dirs = []; |
| 145 var lister = temp.list(recursive: true); | 147 var lister = temp.list(recursive: true).listen( |
| 146 lister.onFile = (f) => files.add(f); | 148 (entity) { |
| 147 lister.onDir = (d) => dirs.add(d); | 149 if (entity is File) { |
| 148 lister.onDone = (success) { | 150 files.add(entity.name); |
| 149 Expect.isTrue(success); | 151 } else { |
| 150 Expect.equals(1, files.length); | 152 Expect.isTrue(entity is Directory); |
| 151 Expect.isTrue(files[0].endsWith('$y${Platform.pathSeparator}x')); | 153 dirs.add(entity.path); |
| 152 Expect.equals(1, dirs.length); | 154 } |
| 153 Expect.isTrue(dirs[0].endsWith(y)); | 155 }, |
| 154 temp.deleteSync(recursive: true); | 156 onDone: () { |
| 155 temp2.deleteSync(recursive: true); | 157 Expect.equals(1, files.length); |
| 156 }; | 158 Expect.isTrue(files[0].endsWith('$y${Platform.pathSeparator}x')); |
| 159 Expect.equals(1, dirs.length); |
| 160 Expect.isTrue(dirs[0].endsWith(y)); |
| 161 temp.deleteSync(recursive: true); |
| 162 temp2.deleteSync(recursive: true); |
| 163 keepAlive.close(); |
| 164 }); |
| 157 }); | 165 }); |
| 158 } | 166 } |
| 159 | 167 |
| 160 | 168 |
| 161 testDirectoryListingBrokenLink() { | 169 testDirectoryListingBrokenLink() { |
| 170 var keepAlive = new ReceivePort(); |
| 162 var temp = new Directory('').createTempSync(); | 171 var temp = new Directory('').createTempSync(); |
| 163 var x = '${temp.path}${Platform.pathSeparator}x'; | 172 var x = '${temp.path}${Platform.pathSeparator}x'; |
| 164 var link = '${temp.path}${Platform.pathSeparator}link'; | 173 var link = '${temp.path}${Platform.pathSeparator}link'; |
| 165 var doesNotExist = 'this_thing_does_not_exist'; | 174 var doesNotExist = 'this_thing_does_not_exist'; |
| 166 new File(x).createSync(); | 175 new File(x).createSync(); |
| 167 createLink(doesNotExist, link, true, () { | 176 createLink(doesNotExist, link, true, () { |
| 168 Expect.throws(() => temp.listSync(recursive: true), | 177 Expect.throws(() => temp.listSync(recursive: true), |
| 169 (e) => e is DirectoryIOException); | 178 (e) => e is DirectoryIOException); |
| 170 var files = []; | 179 var files = []; |
| 171 var dirs = []; | 180 var dirs = []; |
| 172 var errors = []; | 181 var errors = []; |
| 173 var lister = temp.list(recursive: true); | 182 temp.list(recursive: true).listen( |
| 174 lister.onFile = (f) => files.add(f); | 183 (entity) { |
| 175 lister.onDir = (d) => dirs.add(d); | 184 if (entity is File) { |
| 176 lister.onError = (d) => errors.add(d); | 185 files.add(entity.name); |
| 177 lister.onDone = (success) { | 186 } else { |
| 178 Expect.isFalse(success); | 187 Expect.isTrue(entity is Directory); |
| 179 Expect.equals(1, files.length); | 188 dirs.add(entity.path); |
| 180 Expect.isTrue(files[0].endsWith(x)); | 189 } |
| 181 Expect.equals(0, dirs.length); | 190 }, |
| 182 Expect.equals(1, errors.length); | 191 onError: (e) => errors.add(e), |
| 183 Expect.isTrue(errors[0].toString().contains(link)); | 192 onDone: () { |
| 184 temp.deleteSync(recursive: true); | 193 Expect.equals(1, files.length); |
| 185 }; | 194 Expect.isTrue(files[0].endsWith(x)); |
| 195 Expect.equals(0, dirs.length); |
| 196 Expect.equals(1, errors.length); |
| 197 Expect.isTrue(errors[0].toString().contains(link)); |
| 198 temp.deleteSync(recursive: true); |
| 199 keepAlive.close(); |
| 200 }); |
| 186 }); | 201 }); |
| 187 } | 202 } |
| 188 | 203 |
| 189 | 204 |
| 190 main() { | 205 main() { |
| 191 testFileExistsCreate(); | 206 testFileExistsCreate(); |
| 192 testFileDelete(); | 207 testFileDelete(); |
| 193 testFileWriteRead(); | 208 testFileWriteRead(); |
| 194 testDirectoryExistsCreate(); | 209 testDirectoryExistsCreate(); |
| 195 testDirectoryDelete(); | 210 testDirectoryDelete(); |
| 196 testDirectoryListing(); | 211 testDirectoryListing(); |
| 197 testDirectoryListingBrokenLink(); | 212 testDirectoryListingBrokenLink(); |
| 198 } | 213 } |
| OLD | NEW |