Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: tests/standalone/io/file_system_watcher_test.dart

Issue 48613002: Add 'isDir' to FileSystemEvent. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review fixes. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11
12 void testWatchCreateFile() { 12 void testWatchCreateFile() {
13 var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher'); 13 var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
14 var file = new File(dir.path + '/file'); 14 var file = new File(dir.path + '/file');
15 15
16 var watcher = dir.watch(); 16 var watcher = dir.watch();
17 17
18 asyncStart(); 18 asyncStart();
19 var sub; 19 var sub;
20 sub = watcher.listen((event) { 20 sub = watcher.listen((event) {
21 if (event is FileSystemCreateEvent && 21 if (event is FileSystemCreateEvent &&
22 event.path.endsWith('file')) { 22 event.path.endsWith('file')) {
23 Expect.isFalse(event.isDirectory);
23 asyncEnd(); 24 asyncEnd();
24 sub.cancel(); 25 sub.cancel();
25 dir.deleteSync(recursive: true); 26 dir.deleteSync(recursive: true);
26 } 27 }
27 }, onError: (e) { 28 }, onError: (e) {
28 dir.deleteSync(recursive: true); 29 dir.deleteSync(recursive: true);
29 throw e; 30 throw e;
30 }); 31 });
31 32
32 file.createSync(); 33 file.createSync();
33 } 34 }
34 35
35 36
37 void testWatchCreateDir() {
38 var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
39 var dir2 = new Directory(dir.path + '/dir');
Bill Hesse 2013/10/28 17:05:33 I really think we should always use join(dir.path,
Anders Johnsen 2013/10/28 17:14:41 Done.
40
41 var watcher = dir.watch();
42
43 asyncStart();
44 var sub;
45 sub = watcher.listen((event) {
46 if (event is FileSystemCreateEvent &&
47 event.path.endsWith('dir')) {
48 Expect.isTrue(event.isDirectory);
49 asyncEnd();
50 sub.cancel();
51 dir.deleteSync(recursive: true);
52 }
53 }, onError: (e) {
54 dir.deleteSync(recursive: true);
55 throw e;
56 });
57
58 dir2.createSync();
Bill Hesse 2013/10/28 17:05:33 Why not just dir2.create?
Anders Johnsen 2013/10/28 17:14:41 It does not add anything either way for this tests
59 }
60
61
36 void testWatchModifyFile() { 62 void testWatchModifyFile() {
37 var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher'); 63 var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
38 var file = new File(dir.path + '/file'); 64 var file = new File(dir.path + '/file');
39 file.createSync(); 65 file.createSync();
40 66
41 var watcher = dir.watch(); 67 var watcher = dir.watch();
42 68
43 asyncStart(); 69 asyncStart();
44 var sub; 70 var sub;
45 sub = watcher.listen((event) { 71 sub = watcher.listen((event) {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 }, onError: (e) { 292 }, onError: (e) {
267 asyncEnd(); 293 asyncEnd();
268 Expect.isTrue(e is FileSystemException); 294 Expect.isTrue(e is FileSystemException);
269 }); 295 });
270 } 296 }
271 297
272 298
273 void main() { 299 void main() {
274 if (!FileSystemEntity.isWatchSupported) return; 300 if (!FileSystemEntity.isWatchSupported) return;
275 testWatchCreateFile(); 301 testWatchCreateFile();
302 testWatchCreateDir();
276 testWatchModifyFile(); 303 testWatchModifyFile();
277 testWatchMoveFile(); 304 testWatchMoveFile();
278 testWatchDeleteFile(); 305 testWatchDeleteFile();
279 testWatchDeleteDir(); 306 testWatchDeleteDir();
280 testWatchOnlyModifyFile(); 307 testWatchOnlyModifyFile();
281 testMultipleEvents(); 308 testMultipleEvents();
282 testWatchNonRecursive(); 309 testWatchNonRecursive();
283 testWatchNonExisting(); 310 testWatchNonExisting();
284 } 311 }
OLDNEW
« runtime/bin/file_patch.dart ('K') | « sdk/lib/io/file_system_entity.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698