| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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:async"; | 5 import "dart:async"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 | 7 |
| 8 import "package:async_helper/async_helper.dart"; | 8 import "package:async_helper/async_helper.dart"; |
| 9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 | 10 |
| 11 class FutureExpect { | 11 class FutureExpect { |
| 12 static Future isTrue(Future<bool> result) => | 12 static Future isTrue(Future<bool> result) => |
| 13 result.then((value) => Expect.isTrue(value)); | 13 result.then((value) => Expect.isTrue(value)); |
| 14 static Future isFalse(Future<bool> result) => | 14 static Future isFalse(Future<bool> result) => |
| 15 result.then((value) => Expect.isFalse(value)); | 15 result.then((value) => Expect.isFalse(value)); |
| 16 static Future equals(expected, Future result) => | 16 static Future equals(expected, Future result) => |
| 17 result.then((value) => Expect.equals(expected, value)); | 17 result.then((value) => Expect.equals(expected, value)); |
| 18 static Future listEquals(expected, Future result) => | 18 static Future listEquals(expected, Future result) => |
| 19 result.then((value) => Expect.listEquals(expected, value)); | 19 result.then((value) => Expect.listEquals(expected, value)); |
| 20 static Future throws(Future result) => | 20 static Future throws(Future result) => |
| 21 result.then((value) { | 21 result.then((value) { |
| 22 throw new ExpectException( | 22 throw new ExpectException( |
| 23 "FutureExpect.throws received $value instead of an exception"); | 23 "FutureExpect.throws received $value instead of an exception"); |
| 24 }, onError: (_) => null); | 24 }, onError: (_) => null); |
| 25 } | 25 } |
| 26 | 26 |
| 27 | 27 |
| 28 Future testFileExistsCreate() { | 28 Future testFileExistsCreate() { |
| 29 return new Directory('').createTemp().then((temp) { | 29 return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) { |
| 30 var x = '${temp.path}${Platform.pathSeparator}x'; | 30 var x = '${temp.path}${Platform.pathSeparator}x'; |
| 31 var y = '${temp.path}${Platform.pathSeparator}y'; | 31 var y = '${temp.path}${Platform.pathSeparator}y'; |
| 32 return new Link(y).create(x) | 32 return new Link(y).create(x) |
| 33 .then((link) => Expect.equals(y, link.path)) | 33 .then((link) => Expect.equals(y, link.path)) |
| 34 .then((_) => FutureExpect.isFalse(new File(y).exists())) | 34 .then((_) => FutureExpect.isFalse(new File(y).exists())) |
| 35 .then((_) => FutureExpect.isFalse(new File(x).exists())) | 35 .then((_) => FutureExpect.isFalse(new File(x).exists())) |
| 36 .then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(y))) | 36 .then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(y))) |
| 37 .then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(x))) | 37 .then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(x))) |
| 38 .then((_) => FutureExpect.equals(FileSystemEntityType.NOT_FOUND, | 38 .then((_) => FutureExpect.equals(FileSystemEntityType.NOT_FOUND, |
| 39 FileSystemEntity.type(y))) | 39 FileSystemEntity.type(y))) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 FileSystemEntity.type(y))) | 91 FileSystemEntity.type(y))) |
| 92 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, | 92 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, |
| 93 FileSystemEntity.type(x))) | 93 FileSystemEntity.type(x))) |
| 94 .then((_) => FutureExpect.throws(new Link(y).target())) | 94 .then((_) => FutureExpect.throws(new Link(y).target())) |
| 95 .then((_) => temp.delete(recursive: true)); | 95 .then((_) => temp.delete(recursive: true)); |
| 96 }); | 96 }); |
| 97 } | 97 } |
| 98 | 98 |
| 99 | 99 |
| 100 Future testFileDelete() { | 100 Future testFileDelete() { |
| 101 return new Directory('').createTemp().then((temp) { | 101 return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) { |
| 102 var x = '${temp.path}${Platform.pathSeparator}x'; | 102 var x = '${temp.path}${Platform.pathSeparator}x'; |
| 103 var y = '${temp.path}${Platform.pathSeparator}y'; | 103 var y = '${temp.path}${Platform.pathSeparator}y'; |
| 104 return new File(x).create() | 104 return new File(x).create() |
| 105 .then((_) => new Link(y).create(x)) | 105 .then((_) => new Link(y).create(x)) |
| 106 .then((_) => FutureExpect.isTrue(new File(x).exists())) | 106 .then((_) => FutureExpect.isTrue(new File(x).exists())) |
| 107 .then((_) => FutureExpect.isTrue(new File(y).exists())) | 107 .then((_) => FutureExpect.isTrue(new File(y).exists())) |
| 108 .then((_) => new File(y).delete()) | 108 .then((_) => new File(y).delete()) |
| 109 .then((_) => FutureExpect.isTrue(new File(x).exists())) | 109 .then((_) => FutureExpect.isTrue(new File(x).exists())) |
| 110 .then((_) => FutureExpect.isFalse(new File(y).exists())) | 110 .then((_) => FutureExpect.isFalse(new File(y).exists())) |
| 111 .then((_) => new Link(y).create(x)) | 111 .then((_) => new Link(y).create(x)) |
| 112 .then((_) => FutureExpect.isTrue(new File(x).exists())) | 112 .then((_) => FutureExpect.isTrue(new File(x).exists())) |
| 113 .then((_) => FutureExpect.isTrue(new File(y).exists())) | 113 .then((_) => FutureExpect.isTrue(new File(y).exists())) |
| 114 .then((_) => new File(y).delete()) | 114 .then((_) => new File(y).delete()) |
| 115 .then((_) => FutureExpect.isTrue(new File(x).exists())) | 115 .then((_) => FutureExpect.isTrue(new File(x).exists())) |
| 116 .then((_) => FutureExpect.isFalse(new File(y).exists())) | 116 .then((_) => FutureExpect.isFalse(new File(y).exists())) |
| 117 .then((_) => temp.delete(recursive: true)); | 117 .then((_) => temp.delete(recursive: true)); |
| 118 }); | 118 }); |
| 119 } | 119 } |
| 120 | 120 |
| 121 | 121 |
| 122 Future testFileWriteRead() { | 122 Future testFileWriteRead() { |
| 123 return new Directory('').createTemp().then((temp) { | 123 return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) { |
| 124 var x = '${temp.path}${Platform.pathSeparator}x'; | 124 var x = '${temp.path}${Platform.pathSeparator}x'; |
| 125 var y = '${temp.path}${Platform.pathSeparator}y'; | 125 var y = '${temp.path}${Platform.pathSeparator}y'; |
| 126 var data = "asdf".codeUnits; | 126 var data = "asdf".codeUnits; |
| 127 return new File(x).create() | 127 return new File(x).create() |
| 128 .then((_) => new Link(y).create(x)) | 128 .then((_) => new Link(y).create(x)) |
| 129 .then((_) => | 129 .then((_) => |
| 130 (new File(y).openWrite(mode: FileMode.WRITE)..add(data)).close()) | 130 (new File(y).openWrite(mode: FileMode.WRITE)..add(data)).close()) |
| 131 .then((_) => FutureExpect.listEquals(data, new File(y).readAsBytes())) | 131 .then((_) => FutureExpect.listEquals(data, new File(y).readAsBytes())) |
| 132 .then((_) => FutureExpect.listEquals(data, new File(x).readAsBytes())) | 132 .then((_) => FutureExpect.listEquals(data, new File(x).readAsBytes())) |
| 133 .then((_) => temp.delete(recursive: true)); | 133 .then((_) => temp.delete(recursive: true)); |
| 134 }); | 134 }); |
| 135 } | 135 } |
| 136 | 136 |
| 137 | 137 |
| 138 Future testDirectoryExistsCreate() { | 138 Future testDirectoryExistsCreate() { |
| 139 return new Directory('').createTemp().then((temp) { | 139 return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) { |
| 140 var x = '${temp.path}${Platform.pathSeparator}x'; | 140 var x = '${temp.path}${Platform.pathSeparator}x'; |
| 141 var y = '${temp.path}${Platform.pathSeparator}y'; | 141 var y = '${temp.path}${Platform.pathSeparator}y'; |
| 142 return new Link(y).create(x) | 142 return new Link(y).create(x) |
| 143 .then((_) => FutureExpect.isFalse(new Directory(x).exists())) | 143 .then((_) => FutureExpect.isFalse(new Directory(x).exists())) |
| 144 .then((_) => FutureExpect.isFalse(new Directory(y).exists())) | 144 .then((_) => FutureExpect.isFalse(new Directory(y).exists())) |
| 145 .then((_) => FutureExpect.throws(new Directory(y).create())) | 145 .then((_) => FutureExpect.throws(new Directory(y).create())) |
| 146 .then((_) => temp.delete(recursive: true)); | 146 .then((_) => temp.delete(recursive: true)); |
| 147 }); | 147 }); |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 Future testDirectoryDelete() { | 151 Future testDirectoryDelete() { |
| 152 return new Directory('').createTemp().then((temp) => | 152 return Directory.systemTemp |
| 153 new Directory('').createTemp().then((temp2) { | 153 .createTemp('dart_file_system_async') |
| 154 var y = '${temp.path}${Platform.pathSeparator}y'; | 154 .then((temp) { |
| 155 var x = '${temp2.path}${Platform.pathSeparator}x'; | 155 return Directory.systemTemp |
| 156 var link = new Directory(y); | 156 .createTemp('dart_file_system_async') |
| 157 return new File(x).create() | 157 .then((temp2) { |
| 158 .then((_) => new Link(y).create(temp2.path)) | 158 var y = '${temp.path}${Platform.pathSeparator}y'; |
| 159 .then((_) => FutureExpect.isTrue(link.exists())) | 159 var x = '${temp2.path}${Platform.pathSeparator}x'; |
| 160 .then((_) => FutureExpect.isTrue(temp2.exists())) | 160 var link = new Directory(y); |
| 161 .then((_) => link.delete()) | 161 return new File(x).create() |
| 162 .then((_) => FutureExpect.isFalse(link.exists())) | 162 .then((_) => new Link(y).create(temp2.path)) |
| 163 .then((_) => FutureExpect.isTrue(temp2.exists())) | 163 .then((_) => FutureExpect.isTrue(link.exists())) |
| 164 .then((_) => new Link(y).create(temp2.path)) | 164 .then((_) => FutureExpect.isTrue(temp2.exists())) |
| 165 .then((_) => FutureExpect.isTrue(link.exists())) | 165 .then((_) => link.delete()) |
| 166 .then((_) => temp.delete(recursive: true)) | 166 .then((_) => FutureExpect.isFalse(link.exists())) |
| 167 .then((_) => FutureExpect.isFalse(link.exists())) | 167 .then((_) => FutureExpect.isTrue(temp2.exists())) |
| 168 .then((_) => FutureExpect.isFalse(temp.exists())) | 168 .then((_) => new Link(y).create(temp2.path)) |
| 169 .then((_) => FutureExpect.isTrue(temp2.exists())) | 169 .then((_) => FutureExpect.isTrue(link.exists())) |
| 170 .then((_) => FutureExpect.isTrue(new File(x).exists())) | 170 .then((_) => temp.delete(recursive: true)) |
| 171 .then((_) => temp2.delete(recursive: true)); | 171 .then((_) => FutureExpect.isFalse(link.exists())) |
| 172 })); | 172 .then((_) => FutureExpect.isFalse(temp.exists())) |
| 173 .then((_) => FutureExpect.isTrue(temp2.exists())) |
| 174 .then((_) => FutureExpect.isTrue(new File(x).exists())) |
| 175 .then((_) => temp2.delete(recursive: true)); |
| 176 }); |
| 177 }); |
| 173 } | 178 } |
| 174 | 179 |
| 175 | 180 |
| 176 Future testDirectoryListing() { | 181 Future testDirectoryListing() { |
| 177 return new Directory('').createTemp().then((temp) => | 182 return Directory.systemTemp |
| 178 new Directory('').createTemp().then((temp2) { | 183 .createTemp('dart_file_system_async') |
| 179 var sep = Platform.pathSeparator; | 184 .then((temp) { |
| 180 var y = '${temp.path}${sep}y'; | 185 return Directory.systemTemp |
| 181 var x = '${temp2.path}${sep}x'; | 186 .createTemp('dart_file_system_async_links') |
| 182 return new File(x).create() | 187 .then((temp2) { |
| 183 .then((_) => new Link(y).create(temp2.path)) | 188 var sep = Platform.pathSeparator; |
| 184 .then((_) => temp.list(recursive: true).singleWhere( | 189 var y = '${temp.path}${sep}y'; |
| 185 (entry) => entry is File)) | 190 var x = '${temp2.path}${sep}x'; |
| 186 .then((file) => Expect.isTrue(file.path.endsWith('$y${sep}x'))) | 191 return new File(x).create() |
| 187 .then((_) => temp.list(recursive: true).singleWhere( | 192 .then((_) => new Link(y).create(temp2.path)) |
| 188 (entry) => entry is Directory)) | 193 .then((_) => temp.list(recursive: true).singleWhere( |
| 189 .then((dir) => Expect.isTrue(dir.path.endsWith('y'))) | 194 (entry) => entry is File)) |
| 190 .then((_) => temp.delete(recursive: true)) | 195 .then((file) => Expect.isTrue(file.path.endsWith('$y${sep}x'))) |
| 191 .then((_) => temp2.delete(recursive: true)); | 196 .then((_) => temp.list(recursive: true).singleWhere( |
| 192 })); | 197 (entry) => entry is Directory)) |
| 198 .then((dir) => Expect.isTrue(dir.path.endsWith('y'))) |
| 199 .then((_) => temp.delete(recursive: true)) |
| 200 .then((_) => temp2.delete(recursive: true)); |
| 201 }); |
| 202 }); |
| 193 } | 203 } |
| 194 | 204 |
| 195 | 205 |
| 196 Future testDirectoryListingBrokenLink() { | 206 Future testDirectoryListingBrokenLink() { |
| 197 return new Directory('').createTemp().then((temp) { | 207 return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) { |
| 198 var x = '${temp.path}${Platform.pathSeparator}x'; | 208 var x = '${temp.path}${Platform.pathSeparator}x'; |
| 199 var link = '${temp.path}${Platform.pathSeparator}link'; | 209 var link = '${temp.path}${Platform.pathSeparator}link'; |
| 200 var doesNotExist = 'this_thing_does_not_exist'; | 210 var doesNotExist = 'this_thing_does_not_exist'; |
| 201 bool sawFile = false; | 211 bool sawFile = false; |
| 202 bool sawLink = false; | 212 bool sawLink = false; |
| 203 return new File(x).create() | 213 return new File(x).create() |
| 204 .then((_) => new Link(link).create(doesNotExist)) | 214 .then((_) => new Link(link).create(doesNotExist)) |
| 205 .then((_) => temp.list(recursive: true).forEach( | 215 .then((_) => temp.list(recursive: true).forEach( |
| 206 (entity) { | 216 (entity) { |
| 207 if (entity is File) { | 217 if (entity is File) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 228 testFileExistsCreate() | 238 testFileExistsCreate() |
| 229 .then((_) => testFileDelete()) | 239 .then((_) => testFileDelete()) |
| 230 .then((_) => testFileWriteRead()) | 240 .then((_) => testFileWriteRead()) |
| 231 .then((_) => testDirectoryExistsCreate()) | 241 .then((_) => testDirectoryExistsCreate()) |
| 232 .then((_) => testDirectoryDelete()) | 242 .then((_) => testDirectoryDelete()) |
| 233 .then((_) => testDirectoryListing()) | 243 .then((_) => testDirectoryListing()) |
| 234 .then((_) => testDirectoryListingBrokenLink()) | 244 .then((_) => testDirectoryListingBrokenLink()) |
| 235 .then((_) => asyncEnd()); | 245 .then((_) => asyncEnd()); |
| 236 } | 246 } |
| 237 } | 247 } |
| OLD | NEW |