| 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 test.physical_file_system; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:core' hide Resource; | 8 import 'dart:core' hide Resource; |
| 9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
| 10 | 10 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 file.writeAsStringSync('contents 1'); | 294 file.writeAsStringSync('contents 1'); |
| 295 return _watchingFile(path, (changesReceived) { | 295 return _watchingFile(path, (changesReceived) { |
| 296 expect(changesReceived, hasLength(0)); | 296 expect(changesReceived, hasLength(0)); |
| 297 file.deleteSync(); | 297 file.deleteSync(); |
| 298 return _delayed(() { | 298 return _delayed(() { |
| 299 expect(changesReceived, hasLength(1)); | 299 expect(changesReceived, hasLength(1)); |
| 300 if (io.Platform.isWindows) { | 300 if (io.Platform.isWindows) { |
| 301 // See https://github.com/dart-lang/sdk/issues/23762 | 301 // See https://github.com/dart-lang/sdk/issues/23762 |
| 302 // Not sure why this breaks under Windows, but testing to see whether | 302 // 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 | 303 // we are running Windows causes the type to change. For now we print |
| 304 // the type out of curriosity. | 304 // the type out of curiosity. |
| 305 print( | 305 print( |
| 306 'PhysicalResourceProviderTest:test_watchFile_delete received an ev
ent with type = ${changesReceived[0].type}'); | 306 'PhysicalResourceProviderTest:test_watchFile_delete received an ev
ent with type = ${changesReceived[0].type}'); |
| 307 } else { | 307 } else { |
| 308 expect(changesReceived[0].type, equals(ChangeType.REMOVE)); | 308 expect(changesReceived[0].type, equals(ChangeType.REMOVE)); |
| 309 } | 309 } |
| 310 expect(changesReceived[0].path, equals(path)); | 310 expect(changesReceived[0].path, equals(path)); |
| 311 }); | 311 }); |
| 312 }); | 312 }); |
| 313 } | 313 } |
| 314 | 314 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 file.writeAsStringSync('contents 2'); | 371 file.writeAsStringSync('contents 2'); |
| 372 return _delayed(() { | 372 return _delayed(() { |
| 373 expect(changesReceived, hasLength(1)); | 373 expect(changesReceived, hasLength(1)); |
| 374 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); | 374 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); |
| 375 expect(changesReceived[0].path, equals(path)); | 375 expect(changesReceived[0].path, equals(path)); |
| 376 }); | 376 }); |
| 377 }); | 377 }); |
| 378 } | 378 } |
| 379 | 379 |
| 380 test_watchFolder_modifyFile_inSubDir() { | 380 test_watchFolder_modifyFile_inSubDir() { |
| 381 var subdirPath = join(tempPath, 'foo'); | 381 var fooPath = join(tempPath, 'foo'); |
| 382 new io.Directory(subdirPath).createSync(); | 382 new io.Directory(fooPath).createSync(); |
| 383 var path = join(tempPath, 'bar'); | 383 var path = join(tempPath, 'bar'); |
| 384 var file = new io.File(path); | 384 var file = new io.File(path); |
| 385 file.writeAsStringSync('contents 1'); | 385 file.writeAsStringSync('contents 1'); |
| 386 return _watchingFolder(tempPath, (changesReceived) { | 386 return _watchingFolder(tempPath, (changesReceived) { |
| 387 expect(changesReceived, hasLength(0)); | 387 expect(changesReceived, hasLength(0)); |
| 388 file.writeAsStringSync('contents 2'); | 388 file.writeAsStringSync('contents 2'); |
| 389 return _delayed(() { | 389 return _delayed(() { |
| 390 expect(changesReceived, hasLength(1)); | 390 expect(changesReceived, hasLength(1)); |
| 391 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); | 391 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); |
| 392 expect(changesReceived[0].path, equals(path)); | 392 expect(changesReceived[0].path, equals(path)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 403 | 403 |
| 404 _watchingFile(String path, test(List<WatchEvent> changesReceived)) { | 404 _watchingFile(String path, test(List<WatchEvent> changesReceived)) { |
| 405 // Delay before we start watching the file. This is necessary | 405 // Delay before we start watching the file. This is necessary |
| 406 // because on MacOS, file modifications that occur just before we | 406 // because on MacOS, file modifications that occur just before we |
| 407 // start watching are sometimes misclassified as happening just after | 407 // start watching are sometimes misclassified as happening just after |
| 408 // we start watching. | 408 // we start watching. |
| 409 return _delayed(() { | 409 return _delayed(() { |
| 410 File file = PhysicalResourceProvider.INSTANCE.getResource(path); | 410 File file = PhysicalResourceProvider.INSTANCE.getResource(path); |
| 411 var changesReceived = <WatchEvent>[]; | 411 var changesReceived = <WatchEvent>[]; |
| 412 var subscription = file.changes.listen(changesReceived.add); | 412 var subscription = file.changes.listen(changesReceived.add); |
| 413 // Delay running the rest of the test to allow file.changes propogate. | 413 // Delay running the rest of the test to allow file.changes propagate. |
| 414 return _delayed(() => test(changesReceived)).whenComplete(() { | 414 return _delayed(() => test(changesReceived)).whenComplete(() { |
| 415 subscription.cancel(); | 415 subscription.cancel(); |
| 416 }); | 416 }); |
| 417 }); | 417 }); |
| 418 } | 418 } |
| 419 | 419 |
| 420 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) { | 420 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) { |
| 421 // Delay before we start watching the folder. This is necessary | 421 // Delay before we start watching the folder. This is necessary |
| 422 // because on MacOS, file modifications that occur just before we | 422 // because on MacOS, file modifications that occur just before we |
| 423 // start watching are sometimes misclassified as happening just after | 423 // start watching are sometimes misclassified as happening just after |
| (...skipping 19 matching lines...) Expand all Loading... |
| 443 | 443 |
| 444 setUp() { | 444 setUp() { |
| 445 tempDirectory = io.Directory.systemTemp.createTempSync('test_resource'); | 445 tempDirectory = io.Directory.systemTemp.createTempSync('test_resource'); |
| 446 tempPath = tempDirectory.absolute.path; | 446 tempPath = tempDirectory.absolute.path; |
| 447 } | 447 } |
| 448 | 448 |
| 449 tearDown() { | 449 tearDown() { |
| 450 tempDirectory.deleteSync(recursive: true); | 450 tempDirectory.deleteSync(recursive: true); |
| 451 } | 451 } |
| 452 } | 452 } |
| OLD | NEW |