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 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 104 } |
105 }, onError: (e) { | 105 }, onError: (e) { |
106 dir.deleteSync(recursive: true); | 106 dir.deleteSync(recursive: true); |
107 throw e; | 107 throw e; |
108 }); | 108 }); |
109 | 109 |
110 file.deleteSync(); | 110 file.deleteSync(); |
111 } | 111 } |
112 | 112 |
113 | 113 |
| 114 void testWatchDeleteDir() { |
| 115 var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher'); |
| 116 var watcher = dir.watch(events: 0); |
| 117 |
| 118 asyncStart(); |
| 119 var sub; |
| 120 sub = watcher.listen((event) { |
| 121 if (event is FileSystemDeleteEvent) { |
| 122 Expect.isTrue(event.path == dir.path); |
| 123 } |
| 124 }, onDone: () { |
| 125 asyncEnd(); |
| 126 }); |
| 127 |
| 128 dir.deleteSync(); |
| 129 } |
| 130 |
| 131 |
114 void testWatchOnlyModifyFile() { | 132 void testWatchOnlyModifyFile() { |
115 var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher'); | 133 var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher'); |
116 var file = new File(dir.path + '/file'); | 134 var file = new File(dir.path + '/file'); |
117 | 135 |
118 var watcher = dir.watch(events: FileSystemEvent.MODIFY); | 136 var watcher = dir.watch(events: FileSystemEvent.MODIFY); |
119 | 137 |
120 asyncStart(); | 138 asyncStart(); |
121 var sub; | 139 var sub; |
122 sub = watcher.listen((event) { | 140 sub = watcher.listen((event) { |
123 Expect.isTrue(event is FileSystemModifyEvent); | 141 Expect.isTrue(event is FileSystemModifyEvent); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 }); | 255 }); |
238 } | 256 } |
239 | 257 |
240 | 258 |
241 void main() { | 259 void main() { |
242 if (!FileSystemEntity.isWatchSupported) return; | 260 if (!FileSystemEntity.isWatchSupported) return; |
243 testWatchCreateFile(); | 261 testWatchCreateFile(); |
244 testWatchModifyFile(); | 262 testWatchModifyFile(); |
245 testWatchMoveFile(); | 263 testWatchMoveFile(); |
246 testWatchDeleteFile(); | 264 testWatchDeleteFile(); |
| 265 testWatchDeleteDir(); |
247 testWatchOnlyModifyFile(); | 266 testWatchOnlyModifyFile(); |
248 testMultipleEvents(); | 267 testMultipleEvents(); |
249 testWatchNonRecursive(); | 268 testWatchNonRecursive(); |
250 } | 269 } |
OLD | NEW |