| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 test.physical_file_system; | 5 library analyzer.test.file_system.physical_resource_provider_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:core' hide Resource; | 8 import 'dart:core'; |
| 9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
| 10 | 10 |
| 11 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
| 12 import 'package:analyzer/file_system/physical_file_system.dart'; | 12 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 13 import 'package:analyzer/src/generated/source_io.dart'; | 13 import 'package:analyzer/src/generated/source_io.dart'; |
| 14 import 'package:path/path.dart'; | 14 import 'package:path/path.dart' hide equals; |
| 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 15 import 'package:unittest/unittest.dart'; | 16 import 'package:unittest/unittest.dart'; |
| 16 import 'package:watcher/watcher.dart'; | 17 import 'package:watcher/watcher.dart'; |
| 17 | 18 |
| 18 import '../reflective_tests.dart'; | |
| 19 import '../utils.dart'; | 19 import '../utils.dart'; |
| 20 | 20 |
| 21 main() { | 21 main() { |
| 22 initializeTestEnvironment(); | 22 initializeTestEnvironment(); |
| 23 runReflectiveTests(PhysicalResourceProviderTest); | 23 if (!new bool.fromEnvironment('skipPhysicalResourceProviderTests')) { |
| 24 runReflectiveTests(FileTest); | 24 defineReflectiveTests(PhysicalResourceProviderTest); |
| 25 runReflectiveTests(FolderTest); | 25 defineReflectiveTests(FileTest); |
| 26 defineReflectiveTests(FolderTest); |
| 27 } |
| 26 } | 28 } |
| 27 | 29 |
| 28 var _isFile = new isInstanceOf<File>(); | 30 var _isFile = new isInstanceOf<File>(); |
| 29 var _isFileSystemException = new isInstanceOf<FileSystemException>(); | 31 var _isFileSystemException = new isInstanceOf<FileSystemException>(); |
| 30 var _isFolder = new isInstanceOf<Folder>(); | 32 var _isFolder = new isInstanceOf<Folder>(); |
| 31 | 33 |
| 32 @reflectiveTest | 34 @reflectiveTest |
| 33 class FileTest extends _BaseTest { | 35 class FileTest extends _BaseTest { |
| 34 String path; | 36 String path; |
| 35 File file; | 37 File file; |
| 36 | 38 |
| 37 setUp() { | 39 setUp() { |
| 38 super.setUp(); | 40 super.setUp(); |
| 39 path = join(tempPath, 'file.txt'); | 41 path = join(tempPath, 'file.txt'); |
| 40 file = PhysicalResourceProvider.INSTANCE.getResource(path); | 42 file = PhysicalResourceProvider.INSTANCE.getResource(path); |
| 41 } | 43 } |
| 42 | 44 |
| 43 void test_createSource() { | 45 void test_createSource() { |
| 44 new io.File(path).writeAsStringSync('contents'); | 46 new io.File(path).writeAsStringSync('contents'); |
| 45 Source source = file.createSource(); | 47 Source source = file.createSource(); |
| 46 expect(source.uriKind, UriKind.FILE_URI); | 48 expect(source.uriKind, UriKind.FILE_URI); |
| 47 expect(source.exists(), isTrue); | 49 expect(source.exists(), isTrue); |
| 48 expect(source.contents.data, 'contents'); | 50 expect(source.contents.data, 'contents'); |
| 49 } | 51 } |
| 50 | 52 |
| 53 void test_delete() { |
| 54 new io.File(path).writeAsStringSync('contents'); |
| 55 expect(file.exists, isTrue); |
| 56 // delete |
| 57 file.delete(); |
| 58 expect(file.exists, isFalse); |
| 59 } |
| 60 |
| 51 void test_equals_differentPaths() { | 61 void test_equals_differentPaths() { |
| 52 String path2 = join(tempPath, 'file2.txt'); | 62 String path2 = join(tempPath, 'file2.txt'); |
| 53 File file2 = PhysicalResourceProvider.INSTANCE.getResource(path2); | 63 File file2 = PhysicalResourceProvider.INSTANCE.getResource(path2); |
| 54 expect(file == file2, isFalse); | 64 expect(file == file2, isFalse); |
| 55 } | 65 } |
| 56 | 66 |
| 57 void test_equals_samePath() { | 67 void test_equals_samePath() { |
| 58 new io.File(path).writeAsStringSync('contents'); | 68 new io.File(path).writeAsStringSync('contents'); |
| 59 File file2 = PhysicalResourceProvider.INSTANCE.getResource(path); | 69 File file2 = PhysicalResourceProvider.INSTANCE.getResource(path); |
| 60 expect(file == file2, isTrue); | 70 expect(file == file2, isTrue); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 File file = PhysicalResourceProvider.INSTANCE.getResource(path); | 107 File file = PhysicalResourceProvider.INSTANCE.getResource(path); |
| 98 expect(file.modificationStamp, isNonNegative); | 108 expect(file.modificationStamp, isNonNegative); |
| 99 } | 109 } |
| 100 | 110 |
| 101 void test_parent() { | 111 void test_parent() { |
| 102 Resource parent = file.parent; | 112 Resource parent = file.parent; |
| 103 expect(parent, new isInstanceOf<Folder>()); | 113 expect(parent, new isInstanceOf<Folder>()); |
| 104 expect(parent.path, equals(tempPath)); | 114 expect(parent.path, equals(tempPath)); |
| 105 } | 115 } |
| 106 | 116 |
| 117 void test_readAsBytesSync_doesNotExist() { |
| 118 File file = PhysicalResourceProvider.INSTANCE.getResource('/test.bin'); |
| 119 expect(() { |
| 120 file.readAsBytesSync(); |
| 121 }, throwsA(_isFileSystemException)); |
| 122 } |
| 123 |
| 124 void test_readAsBytesSync_exists() { |
| 125 List<int> bytes = <int>[1, 2, 3, 4, 5]; |
| 126 new io.File(path).writeAsBytesSync(bytes); |
| 127 expect(file.readAsBytesSync(), bytes); |
| 128 } |
| 129 |
| 107 void test_readAsStringSync_doesNotExist() { | 130 void test_readAsStringSync_doesNotExist() { |
| 108 File file = PhysicalResourceProvider.INSTANCE.getResource(path); | 131 File file = PhysicalResourceProvider.INSTANCE.getResource(path); |
| 109 expect(() { | 132 expect(() { |
| 110 file.readAsStringSync(); | 133 file.readAsStringSync(); |
| 111 }, throwsA(_isFileSystemException)); | 134 }, throwsA(_isFileSystemException)); |
| 112 } | 135 } |
| 113 | 136 |
| 114 void test_readAsStringSync_exists() { | 137 void test_readAsStringSync_exists() { |
| 115 new io.File(path).writeAsStringSync('abc'); | 138 new io.File(path).writeAsStringSync('abc'); |
| 116 File file = PhysicalResourceProvider.INSTANCE.getResource(path); | 139 File file = PhysicalResourceProvider.INSTANCE.getResource(path); |
| 117 expect(file.readAsStringSync(), 'abc'); | 140 expect(file.readAsStringSync(), 'abc'); |
| 118 } | 141 } |
| 119 | 142 |
| 143 void test_renameSync_newDoesNotExist() { |
| 144 String oldPath = '$tempPath/file.txt'; |
| 145 String newPath = '$tempPath/new-file.txt'; |
| 146 new io.File(oldPath).writeAsStringSync('text'); |
| 147 File file = PhysicalResourceProvider.INSTANCE.getResource(oldPath); |
| 148 File newFile = file.renameSync(newPath); |
| 149 expect(file.path, oldPath); |
| 150 expect(file.exists, isFalse); |
| 151 expect(newFile.path, newPath); |
| 152 expect(newFile.exists, isTrue); |
| 153 expect(newFile.readAsStringSync(), 'text'); |
| 154 } |
| 155 |
| 156 test_renameSync_newExists_file() async { |
| 157 String oldPath = '$tempPath/file.txt'; |
| 158 String newPath = '$tempPath/new-file.txt'; |
| 159 new io.File(oldPath).writeAsStringSync('text'); |
| 160 new io.File(newPath).writeAsStringSync('new text'); |
| 161 File file = PhysicalResourceProvider.INSTANCE.getResource(oldPath); |
| 162 File newFile = file.renameSync(newPath); |
| 163 expect(file.path, oldPath); |
| 164 expect(file.exists, isFalse); |
| 165 expect(newFile.path, newPath); |
| 166 expect(newFile.exists, isTrue); |
| 167 expect(newFile.readAsStringSync(), 'text'); |
| 168 } |
| 169 |
| 170 void test_renameSync_newExists_folder() { |
| 171 String oldPath = '$tempPath/file.txt'; |
| 172 String newPath = '$tempPath/foo'; |
| 173 new io.File(oldPath).writeAsStringSync('text'); |
| 174 new io.Directory(newPath).createSync(); |
| 175 File file = PhysicalResourceProvider.INSTANCE.getResource(oldPath); |
| 176 expect(() { |
| 177 file.renameSync(newPath); |
| 178 }, throwsA(_isFileSystemException)); |
| 179 expect(file.path, oldPath); |
| 180 expect(file.exists, isTrue); |
| 181 } |
| 182 |
| 183 void test_resolveSymbolicLinksSync_links() { |
| 184 Context pathContext = PhysicalResourceProvider.INSTANCE.pathContext; |
| 185 String pathA = pathContext.join(tempPath, 'a'); |
| 186 String pathB = pathContext.join(pathA, 'b'); |
| 187 new io.Directory(pathB).createSync(recursive: true); |
| 188 String filePath = pathContext.join(pathB, 'test.txt'); |
| 189 io.File testFile = new io.File(filePath); |
| 190 testFile.writeAsStringSync('test'); |
| 191 |
| 192 String pathC = pathContext.join(tempPath, 'c'); |
| 193 String pathD = pathContext.join(pathC, 'd'); |
| 194 new io.Link(pathD).createSync(pathA, recursive: true); |
| 195 |
| 196 String pathE = pathContext.join(tempPath, 'e'); |
| 197 String pathF = pathContext.join(pathE, 'f'); |
| 198 new io.Link(pathF).createSync(pathC, recursive: true); |
| 199 |
| 200 String linkPath = |
| 201 pathContext.join(tempPath, 'e', 'f', 'd', 'b', 'test.txt'); |
| 202 File file = PhysicalResourceProvider.INSTANCE.getFile(linkPath); |
| 203 expect(file.resolveSymbolicLinksSync().path, |
| 204 testFile.resolveSymbolicLinksSync()); |
| 205 } |
| 206 |
| 207 void test_resolveSymbolicLinksSync_noLinks() { |
| 208 // |
| 209 // On some platforms the path to the temp directory includes a symbolic |
| 210 // link. We remove that from the equation before creating the File in order |
| 211 // to show that the operation works as expected without symbolic links. |
| 212 // |
| 213 io.File ioFile = new io.File(path); |
| 214 ioFile.writeAsStringSync('test'); |
| 215 file = PhysicalResourceProvider.INSTANCE |
| 216 .getFile(ioFile.resolveSymbolicLinksSync()); |
| 217 expect(file.resolveSymbolicLinksSync(), file); |
| 218 } |
| 219 |
| 120 void test_shortName() { | 220 void test_shortName() { |
| 121 expect(file.shortName, 'file.txt'); | 221 expect(file.shortName, 'file.txt'); |
| 122 } | 222 } |
| 123 | 223 |
| 124 void test_toString() { | 224 void test_toString() { |
| 125 expect(file.toString(), path); | 225 expect(file.toString(), path); |
| 126 } | 226 } |
| 227 |
| 228 void test_toUri() { |
| 229 String path = '/foo/file.txt'; |
| 230 File file = PhysicalResourceProvider.INSTANCE.getFile(path); |
| 231 expect(file.toUri(), new Uri.file(path)); |
| 232 } |
| 233 |
| 234 void test_writeAsBytesSync() { |
| 235 List<int> content = <int>[1, 2]; |
| 236 new io.File(path).writeAsBytesSync(content); |
| 237 expect(file.readAsBytesSync(), content); |
| 238 // write new bytes |
| 239 content = <int>[10, 20]; |
| 240 file.writeAsBytesSync(content); |
| 241 expect(file.readAsBytesSync(), content); |
| 242 } |
| 243 |
| 244 void test_writeAsStringSync() { |
| 245 String content = 'ab'; |
| 246 new io.File(path).writeAsStringSync(content); |
| 247 expect(file.readAsStringSync(), content); |
| 248 // write new bytes |
| 249 content = 'CD'; |
| 250 file.writeAsStringSync(content); |
| 251 expect(file.readAsStringSync(), content); |
| 252 } |
| 127 } | 253 } |
| 128 | 254 |
| 129 @reflectiveTest | 255 @reflectiveTest |
| 130 class FolderTest extends _BaseTest { | 256 class FolderTest extends _BaseTest { |
| 131 String path; | 257 String path; |
| 132 Folder folder; | 258 Folder folder; |
| 133 | 259 |
| 134 setUp() { | 260 setUp() { |
| 135 super.setUp(); | 261 super.setUp(); |
| 136 path = join(tempPath, 'folder'); | 262 path = join(tempPath, 'folder'); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 152 equals(join(path2, 'baz'))); | 278 equals(join(path2, 'baz'))); |
| 153 } | 279 } |
| 154 | 280 |
| 155 void test_contains() { | 281 void test_contains() { |
| 156 expect(folder.contains(join(path, 'aaa.txt')), isTrue); | 282 expect(folder.contains(join(path, 'aaa.txt')), isTrue); |
| 157 expect(folder.contains(join(path, 'aaa', 'bbb.txt')), isTrue); | 283 expect(folder.contains(join(path, 'aaa', 'bbb.txt')), isTrue); |
| 158 expect(folder.contains(join(tempPath, 'baz.txt')), isFalse); | 284 expect(folder.contains(join(tempPath, 'baz.txt')), isFalse); |
| 159 expect(folder.contains(path), isFalse); | 285 expect(folder.contains(path), isFalse); |
| 160 } | 286 } |
| 161 | 287 |
| 288 void test_delete() { |
| 289 new io.File(join(path, 'myFile')).createSync(); |
| 290 var child = folder.getChild('myFile'); |
| 291 expect(child, _isFile); |
| 292 expect(child.exists, isTrue); |
| 293 // delete "folder" |
| 294 folder.delete(); |
| 295 expect(child.exists, isFalse); |
| 296 } |
| 297 |
| 162 void test_equals_differentPaths() { | 298 void test_equals_differentPaths() { |
| 163 String path2 = join(tempPath, 'folder2'); | 299 String path2 = join(tempPath, 'folder2'); |
| 164 new io.Directory(path2).createSync(); | 300 new io.Directory(path2).createSync(); |
| 165 Folder folder2 = PhysicalResourceProvider.INSTANCE.getResource(path2); | 301 Folder folder2 = PhysicalResourceProvider.INSTANCE.getResource(path2); |
| 166 expect(folder == folder2, isFalse); | 302 expect(folder == folder2, isFalse); |
| 167 } | 303 } |
| 168 | 304 |
| 169 void test_equals_samePath() { | 305 void test_equals_samePath() { |
| 170 Folder folder2 = PhysicalResourceProvider.INSTANCE.getResource(path); | 306 Folder folder2 = PhysicalResourceProvider.INSTANCE.getResource(path); |
| 171 expect(folder == folder2, isTrue); | 307 expect(folder == folder2, isTrue); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 184 expect(child.exists, isTrue); | 320 expect(child.exists, isTrue); |
| 185 } | 321 } |
| 186 | 322 |
| 187 void test_getChild_folder() { | 323 void test_getChild_folder() { |
| 188 new io.Directory(join(path, 'myFolder')).createSync(); | 324 new io.Directory(join(path, 'myFolder')).createSync(); |
| 189 var child = folder.getChild('myFolder'); | 325 var child = folder.getChild('myFolder'); |
| 190 expect(child, _isFolder); | 326 expect(child, _isFolder); |
| 191 expect(child.exists, isTrue); | 327 expect(child.exists, isTrue); |
| 192 } | 328 } |
| 193 | 329 |
| 330 void test_getChildAssumingFile_doesNotExist() { |
| 331 File child = folder.getChildAssumingFile('no-such-resource'); |
| 332 expect(child, isNotNull); |
| 333 expect(child.exists, isFalse); |
| 334 } |
| 335 |
| 336 void test_getChildAssumingFile_file() { |
| 337 new io.File(join(path, 'myFile')).createSync(); |
| 338 File child = folder.getChildAssumingFile('myFile'); |
| 339 expect(child, isNotNull); |
| 340 expect(child.exists, isTrue); |
| 341 } |
| 342 |
| 343 void test_getChildAssumingFile_folder() { |
| 344 new io.Directory(join(path, 'myFolder')).createSync(); |
| 345 File child = folder.getChildAssumingFile('myFolder'); |
| 346 expect(child, isNotNull); |
| 347 expect(child.exists, isFalse); |
| 348 } |
| 349 |
| 194 void test_getChildAssumingFolder_doesNotExist() { | 350 void test_getChildAssumingFolder_doesNotExist() { |
| 195 Folder child = folder.getChildAssumingFolder('no-such-resource'); | 351 Folder child = folder.getChildAssumingFolder('no-such-resource'); |
| 196 expect(child, isNotNull); | 352 expect(child, isNotNull); |
| 197 expect(child.exists, isFalse); | 353 expect(child.exists, isFalse); |
| 198 } | 354 } |
| 199 | 355 |
| 200 void test_getChildAssumingFolder_file() { | 356 void test_getChildAssumingFolder_file() { |
| 201 new io.File(join(path, 'myFile')).createSync(); | 357 new io.File(join(path, 'myFile')).createSync(); |
| 202 Folder child = folder.getChildAssumingFolder('myFile'); | 358 Folder child = folder.getChildAssumingFolder('myFile'); |
| 203 expect(child, isNotNull); | 359 expect(child, isNotNull); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 while (true) { | 421 while (true) { |
| 266 Resource grandParent = parent.parent; | 422 Resource grandParent = parent.parent; |
| 267 if (grandParent == null) { | 423 if (grandParent == null) { |
| 268 break; | 424 break; |
| 269 } | 425 } |
| 270 expect(grandParent, new isInstanceOf<Folder>()); | 426 expect(grandParent, new isInstanceOf<Folder>()); |
| 271 expect(grandParent.path.length, lessThan(parent.path.length)); | 427 expect(grandParent.path.length, lessThan(parent.path.length)); |
| 272 parent = grandParent; | 428 parent = grandParent; |
| 273 } | 429 } |
| 274 } | 430 } |
| 431 |
| 432 void test_toUri() { |
| 433 String path = '/foo/directory'; |
| 434 Folder folder = PhysicalResourceProvider.INSTANCE.getFolder(path); |
| 435 expect(folder.toUri(), new Uri.directory(path)); |
| 436 } |
| 275 } | 437 } |
| 276 | 438 |
| 277 @reflectiveTest | 439 @reflectiveTest |
| 278 class PhysicalResourceProviderTest extends _BaseTest { | 440 class PhysicalResourceProviderTest extends _BaseTest { |
| 441 test_getFolder_trailingSeparator() { |
| 442 String path = tempPath; |
| 443 PhysicalResourceProvider provider = PhysicalResourceProvider.INSTANCE; |
| 444 Folder folder = provider.getFolder('$path$separator'); |
| 445 expect(folder.path, path); |
| 446 } |
| 447 |
| 448 test_getModificationTimes() async { |
| 449 PhysicalResourceProvider provider = PhysicalResourceProvider.INSTANCE; |
| 450 String path = join(tempPath, 'file1.txt'); |
| 451 new io.File(path).writeAsStringSync(''); |
| 452 Source source = provider.getFile(path).createSource(); |
| 453 List<int> times = await provider.getModificationTimes([source]); |
| 454 expect(times, [source.modificationStamp]); |
| 455 } |
| 456 |
| 279 void test_getStateLocation_uniqueness() { | 457 void test_getStateLocation_uniqueness() { |
| 280 PhysicalResourceProvider provider = PhysicalResourceProvider.INSTANCE; | 458 PhysicalResourceProvider provider = PhysicalResourceProvider.INSTANCE; |
| 281 String idOne = 'one'; | 459 String idOne = 'one'; |
| 282 Folder folderOne = provider.getStateLocation(idOne); | 460 Folder folderOne = provider.getStateLocation(idOne); |
| 283 expect(folderOne, isNotNull); | 461 expect(folderOne, isNotNull); |
| 284 String idTwo = 'two'; | 462 String idTwo = 'two'; |
| 285 Folder folderTwo = provider.getStateLocation(idTwo); | 463 Folder folderTwo = provider.getStateLocation(idTwo); |
| 286 expect(folderTwo, isNotNull); | 464 expect(folderTwo, isNotNull); |
| 287 expect(folderTwo, isNot(equals(folderOne))); | 465 expect(folderTwo, isNot(equals(folderOne))); |
| 288 expect(provider.getStateLocation(idOne), equals(folderOne)); | 466 expect(provider.getStateLocation(idOne), equals(folderOne)); |
| 289 } | 467 } |
| 290 | 468 |
| 291 test_watchFile_delete() { | 469 test_watchFile_delete() { |
| 292 var path = join(tempPath, 'foo'); | 470 var path = join(tempPath, 'foo'); |
| 293 var file = new io.File(path); | 471 var file = new io.File(path); |
| 294 file.writeAsStringSync('contents 1'); | 472 file.writeAsStringSync('contents 1'); |
| 295 return _watchingFile(path, (changesReceived) { | 473 return _watchingFile(path, (changesReceived) { |
| 296 expect(changesReceived, hasLength(0)); | 474 expect(changesReceived, hasLength(0)); |
| 297 file.deleteSync(); | 475 file.deleteSync(); |
| 298 return _delayed(() { | 476 return _delayed(() { |
| 299 expect(changesReceived, hasLength(1)); | 477 expect(changesReceived, hasLength(1)); |
| 300 if (io.Platform.isWindows) { | 478 if (io.Platform.isWindows) { |
| 301 // See https://github.com/dart-lang/sdk/issues/23762 | 479 // See https://github.com/dart-lang/sdk/issues/23762 |
| 302 // Not sure why this breaks under Windows, but testing to see whether | 480 // Not sure why this breaks under Windows, but testing to see whether |
| 303 // we are running Windows causes the type to change. For now we print | 481 // we are running Windows causes the type to change. For now we print |
| 304 // the type out of curriosity. | 482 // the type out of curiosity. |
| 305 print( | 483 print( |
| 306 'PhysicalResourceProviderTest:test_watchFile_delete received an ev
ent with type = ${changesReceived[0].type}'); | 484 'PhysicalResourceProviderTest:test_watchFile_delete received an ev
ent with type = ${changesReceived[0].type}'); |
| 307 } else { | 485 } else { |
| 308 expect(changesReceived[0].type, equals(ChangeType.REMOVE)); | 486 expect(changesReceived[0].type, equals(ChangeType.REMOVE)); |
| 309 } | 487 } |
| 310 expect(changesReceived[0].path, equals(path)); | 488 expect(changesReceived[0].path, equals(path)); |
| 311 }); | 489 }); |
| 312 }); | 490 }); |
| 313 } | 491 } |
| 314 | 492 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 file.writeAsStringSync('contents 2'); | 549 file.writeAsStringSync('contents 2'); |
| 372 return _delayed(() { | 550 return _delayed(() { |
| 373 expect(changesReceived, hasLength(1)); | 551 expect(changesReceived, hasLength(1)); |
| 374 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); | 552 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); |
| 375 expect(changesReceived[0].path, equals(path)); | 553 expect(changesReceived[0].path, equals(path)); |
| 376 }); | 554 }); |
| 377 }); | 555 }); |
| 378 } | 556 } |
| 379 | 557 |
| 380 test_watchFolder_modifyFile_inSubDir() { | 558 test_watchFolder_modifyFile_inSubDir() { |
| 381 var subdirPath = join(tempPath, 'foo'); | 559 var fooPath = join(tempPath, 'foo'); |
| 382 new io.Directory(subdirPath).createSync(); | 560 new io.Directory(fooPath).createSync(); |
| 383 var path = join(tempPath, 'bar'); | 561 var path = join(tempPath, 'bar'); |
| 384 var file = new io.File(path); | 562 var file = new io.File(path); |
| 385 file.writeAsStringSync('contents 1'); | 563 file.writeAsStringSync('contents 1'); |
| 386 return _watchingFolder(tempPath, (changesReceived) { | 564 return _watchingFolder(tempPath, (changesReceived) { |
| 387 expect(changesReceived, hasLength(0)); | 565 expect(changesReceived, hasLength(0)); |
| 388 file.writeAsStringSync('contents 2'); | 566 file.writeAsStringSync('contents 2'); |
| 389 return _delayed(() { | 567 return _delayed(() { |
| 390 expect(changesReceived, hasLength(1)); | 568 expect(changesReceived, hasLength(1)); |
| 391 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); | 569 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); |
| 392 expect(changesReceived[0].path, equals(path)); | 570 expect(changesReceived[0].path, equals(path)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 403 | 581 |
| 404 _watchingFile(String path, test(List<WatchEvent> changesReceived)) { | 582 _watchingFile(String path, test(List<WatchEvent> changesReceived)) { |
| 405 // Delay before we start watching the file. This is necessary | 583 // Delay before we start watching the file. This is necessary |
| 406 // because on MacOS, file modifications that occur just before we | 584 // because on MacOS, file modifications that occur just before we |
| 407 // start watching are sometimes misclassified as happening just after | 585 // start watching are sometimes misclassified as happening just after |
| 408 // we start watching. | 586 // we start watching. |
| 409 return _delayed(() { | 587 return _delayed(() { |
| 410 File file = PhysicalResourceProvider.INSTANCE.getResource(path); | 588 File file = PhysicalResourceProvider.INSTANCE.getResource(path); |
| 411 var changesReceived = <WatchEvent>[]; | 589 var changesReceived = <WatchEvent>[]; |
| 412 var subscription = file.changes.listen(changesReceived.add); | 590 var subscription = file.changes.listen(changesReceived.add); |
| 413 // Delay running the rest of the test to allow file.changes propogate. | 591 // Delay running the rest of the test to allow file.changes propagate. |
| 414 return _delayed(() => test(changesReceived)).whenComplete(() { | 592 return _delayed(() => test(changesReceived)).whenComplete(() { |
| 415 subscription.cancel(); | 593 subscription.cancel(); |
| 416 }); | 594 }); |
| 417 }); | 595 }); |
| 418 } | 596 } |
| 419 | 597 |
| 420 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) { | 598 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) { |
| 421 // Delay before we start watching the folder. This is necessary | 599 // Delay before we start watching the folder. This is necessary |
| 422 // because on MacOS, file modifications that occur just before we | 600 // because on MacOS, file modifications that occur just before we |
| 423 // start watching are sometimes misclassified as happening just after | 601 // start watching are sometimes misclassified as happening just after |
| (...skipping 19 matching lines...) Expand all Loading... |
| 443 | 621 |
| 444 setUp() { | 622 setUp() { |
| 445 tempDirectory = io.Directory.systemTemp.createTempSync('test_resource'); | 623 tempDirectory = io.Directory.systemTemp.createTempSync('test_resource'); |
| 446 tempPath = tempDirectory.absolute.path; | 624 tempPath = tempDirectory.absolute.path; |
| 447 } | 625 } |
| 448 | 626 |
| 449 tearDown() { | 627 tearDown() { |
| 450 tempDirectory.deleteSync(recursive: true); | 628 tempDirectory.deleteSync(recursive: true); |
| 451 } | 629 } |
| 452 } | 630 } |
| OLD | NEW |