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

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

Issue 23668006: Run file system operations in file_system_watcher_test after a runAsync delay. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 11 matching lines...) Expand all
22 event.path.endsWith('file')) { 22 event.path.endsWith('file')) {
23 asyncEnd(); 23 asyncEnd();
24 sub.cancel(); 24 sub.cancel();
25 dir.deleteSync(recursive: true); 25 dir.deleteSync(recursive: true);
26 } 26 }
27 }, onError: (e) { 27 }, onError: (e) {
28 dir.deleteSync(recursive: true); 28 dir.deleteSync(recursive: true);
29 throw e; 29 throw e;
30 }); 30 });
31 31
32 file.createSync(); 32 runAsync(file.createSync);
33 } 33 }
34 34
35 35
36 void testWatchModifyFile() { 36 void testWatchModifyFile() {
37 var dir = new Directory('').createTempSync(); 37 var dir = new Directory('').createTempSync();
38 var file = new File(dir.path + '/file'); 38 var file = new File(dir.path + '/file');
39 file.createSync(); 39 file.createSync();
40 40
41 var watcher = dir.watch(); 41 var watcher = dir.watch();
42 42
43 asyncStart(); 43 asyncStart();
44 var sub; 44 var sub;
45 sub = watcher.listen((event) { 45 sub = watcher.listen((event) {
46 if (event is FileSystemModifyEvent) { 46 if (event is FileSystemModifyEvent) {
47 Expect.isTrue(event.path.endsWith('file')); 47 Expect.isTrue(event.path.endsWith('file'));
48 sub.cancel(); 48 sub.cancel();
49 asyncEnd(); 49 asyncEnd();
50 dir.deleteSync(recursive: true); 50 dir.deleteSync(recursive: true);
51 } 51 }
52 }, onError: (e) { 52 }, onError: (e) {
53 dir.deleteSync(recursive: true); 53 dir.deleteSync(recursive: true);
54 throw e; 54 throw e;
55 }); 55 });
56 56
57 file.writeAsStringSync('a'); 57 runAsync(() => file.writeAsStringSync('a'));
58 } 58 }
59 59
60 60
61 void testWatchMoveFile() { 61 void testWatchMoveFile() {
62 var dir = new Directory('').createTempSync(); 62 var dir = new Directory('').createTempSync();
63 var file = new File(dir.path + '/file'); 63 var file = new File(dir.path + '/file');
64 file.createSync(); 64 file.createSync();
65 65
66 var watcher = dir.watch(); 66 var watcher = dir.watch();
67 67
68 asyncStart(); 68 asyncStart();
69 var sub; 69 var sub;
70 sub = watcher.listen((event) { 70 sub = watcher.listen((event) {
71 if (event is FileSystemMoveEvent) { 71 if (event is FileSystemMoveEvent) {
72 Expect.isTrue(event.path.endsWith('file')); 72 Expect.isTrue(event.path.endsWith('file'));
73 Expect.isTrue(event.destination.endsWith('file2')); 73 Expect.isTrue(event.destination.endsWith('file2'));
74 sub.cancel(); 74 sub.cancel();
75 asyncEnd(); 75 asyncEnd();
76 dir.deleteSync(recursive: true); 76 dir.deleteSync(recursive: true);
77 } 77 }
78 }, onError: (e) { 78 }, onError: (e) {
79 dir.deleteSync(recursive: true); 79 dir.deleteSync(recursive: true);
80 throw e; 80 throw e;
81 }); 81 });
82 82
83 file.renameSync(dir.path + '/file2'); 83 runAsync(() => file.renameSync(dir.path + '/file2'));
84 } 84 }
85 85
86 86
87 void testWatchDeleteFile() { 87 void testWatchDeleteFile() {
88 var dir = new Directory('').createTempSync(); 88 var dir = new Directory('').createTempSync();
89 var file = new File(dir.path + '/file'); 89 var file = new File(dir.path + '/file');
90 file.createSync(); 90 file.createSync();
91 91
92 var watcher = dir.watch(); 92 var watcher = dir.watch();
93 93
94 asyncStart(); 94 asyncStart();
95 var sub; 95 var sub;
96 sub = watcher.listen((event) { 96 sub = watcher.listen((event) {
97 if (event is FileSystemDeleteEvent) { 97 if (event is FileSystemDeleteEvent) {
98 Expect.isTrue(event.path.endsWith('file')); 98 Expect.isTrue(event.path.endsWith('file'));
99 sub.cancel(); 99 sub.cancel();
100 asyncEnd(); 100 asyncEnd();
101 dir.deleteSync(recursive: true); 101 dir.deleteSync(recursive: true);
102 } 102 }
103 }, onError: (e) { 103 }, onError: (e) {
104 dir.deleteSync(recursive: true); 104 dir.deleteSync(recursive: true);
105 throw e; 105 throw e;
106 }); 106 });
107 107
108 file.deleteSync(); 108 runAsync(file.deleteSync);
109 } 109 }
110 110
111 111
112 void testWatchOnlyModifyFile() { 112 void testWatchOnlyModifyFile() {
113 var dir = new Directory('').createTempSync(); 113 var dir = new Directory('').createTempSync();
114 var file = new File(dir.path + '/file'); 114 var file = new File(dir.path + '/file');
115 115
116 var watcher = dir.watch(events: FileSystemEvent.MODIFY); 116 var watcher = dir.watch(events: FileSystemEvent.MODIFY);
117 117
118 asyncStart(); 118 asyncStart();
119 var sub; 119 var sub;
120 sub = watcher.listen((event) { 120 sub = watcher.listen((event) {
121 Expect.isTrue(event is FileSystemModifyEvent); 121 Expect.isTrue(event is FileSystemModifyEvent);
122 Expect.isTrue(event.path.endsWith('file')); 122 Expect.isTrue(event.path.endsWith('file'));
123 sub.cancel(); 123 sub.cancel();
124 asyncEnd(); 124 asyncEnd();
125 dir.deleteSync(recursive: true); 125 dir.deleteSync(recursive: true);
126 }, onError: (e) { 126 }, onError: (e) {
127 dir.deleteSync(recursive: true); 127 dir.deleteSync(recursive: true);
128 throw e; 128 throw e;
129 }); 129 });
130 130
131 file.createSync(); 131 runAsync(() {
132 file.writeAsStringSync('a'); 132 file.createSync();
133 file.writeAsStringSync('a');
134 });
133 } 135 }
134 136
135 137
136 void testMultipleEvents() { 138 void testMultipleEvents() {
137 var dir = new Directory('').createTempSync(); 139 var dir = new Directory('').createTempSync();
138 var file = new File(dir.path + '/file'); 140 var file = new File(dir.path + '/file');
139 var file2 = new File(dir.path + '/file2'); 141 var file2 = new File(dir.path + '/file2');
140 142
141 var watcher = dir.watch(); 143 var watcher = dir.watch();
142 144
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 if (event.path.endsWith('file')) { 198 if (event.path.endsWith('file')) {
197 sub.cancel(); 199 sub.cancel();
198 asyncEnd(); 200 asyncEnd();
199 dir.deleteSync(recursive: true); 201 dir.deleteSync(recursive: true);
200 } 202 }
201 }, onError: (e) { 203 }, onError: (e) {
202 dir.deleteSync(recursive: true); 204 dir.deleteSync(recursive: true);
203 throw e; 205 throw e;
204 }); 206 });
205 207
206 file.createSync(); 208 runAsync(file.createSync());
207 } 209 }
208 210
209 211
210 void testWatchNonRecursive() { 212 void testWatchNonRecursive() {
211 var dir = new Directory('').createTempSync(); 213 var dir = new Directory('').createTempSync();
212 var dir2 = new Directory(dir.path + '/dir'); 214 var dir2 = new Directory(dir.path + '/dir');
213 dir2.createSync(); 215 dir2.createSync();
214 var file = new File(dir.path + '/dir/file'); 216 var file = new File(dir.path + '/dir/file');
215 217
216 var watcher = dir.watch(recursive: false); 218 var watcher = dir.watch(recursive: false);
217 219
218 asyncStart(); 220 asyncStart();
219 var sub; 221 var sub;
220 sub = watcher.listen((event) { 222 sub = watcher.listen((event) {
221 if (event.path.endsWith('file')) { 223 if (event.path.endsWith('file')) {
222 throw "File change event not expected"; 224 throw "File change event not expected";
223 } 225 }
224 }, onError: (e) { 226 }, onError: (e) {
225 dir.deleteSync(recursive: true); 227 dir.deleteSync(recursive: true);
226 throw e; 228 throw e;
227 }); 229 });
228 230
229 file.createSync(); 231 runAsync(file.createSync);
230 232
231 new Timer(const Duration(milliseconds: 300), () { 233 new Timer(const Duration(milliseconds: 300), () {
232 sub.cancel(); 234 sub.cancel();
233 asyncEnd(); 235 asyncEnd();
234 dir.deleteSync(recursive: true); 236 dir.deleteSync(recursive: true);
235 }); 237 });
236 } 238 }
237 239
238 240
239 void main() { 241 void main() {
240 if (!FileSystemEntity.isWatchSupported) return; 242 if (!FileSystemEntity.isWatchSupported) return;
241 testWatchCreateFile(); 243 testWatchCreateFile();
242 testWatchModifyFile(); 244 testWatchModifyFile();
243 testWatchMoveFile(); 245 testWatchMoveFile();
244 testWatchDeleteFile(); 246 testWatchDeleteFile();
245 testWatchOnlyModifyFile(); 247 testWatchOnlyModifyFile();
246 testMultipleEvents(); 248 testMultipleEvents();
247 testWatchNonRecursive(); 249 testWatchNonRecursive();
248 } 250 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698