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

Side by Side Diff: pkg/watcher/test/directory_watcher/shared.dart

Issue 46843003: Wrap Directory.watch on linux for the watcher package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review 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
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'package:scheduled_test/scheduled_test.dart';
6
7 import '../utils.dart';
8
9 sharedTests() {
10 test('does not notify for files that already exist when started', () {
11 // Make some pre-existing files.
12 writeFile("a.txt");
13 writeFile("b.txt");
14
15 startWatcher();
16
17 // Change one after the watcher is running.
18 writeFile("b.txt", contents: "modified");
19
20 // We should get a modify event for the changed file, but no add events
21 // for them before this.
22 expectModifyEvent("b.txt");
23 });
24
25 test('notifies when a file is added', () {
26 startWatcher();
27 writeFile("file.txt");
28 expectAddEvent("file.txt");
29 });
30
31 test('notifies when a file is modified', () {
32 writeFile("file.txt");
33 startWatcher();
34 writeFile("file.txt", contents: "modified");
35 expectModifyEvent("file.txt");
36 });
37
38 test('notifies when a file is removed', () {
39 writeFile("file.txt");
40 startWatcher();
41 deleteFile("file.txt");
42 expectRemoveEvent("file.txt");
43 });
44
45 test('notifies when a file is modified multiple times', () {
46 writeFile("file.txt");
47 startWatcher();
48 writeFile("file.txt", contents: "modified");
49 expectModifyEvent("file.txt");
50 writeFile("file.txt", contents: "modified again");
51 expectModifyEvent("file.txt");
52 });
53
54 test('when the watched directory is deleted, removes all files', () {
55 writeFile("dir/a.txt");
56 writeFile("dir/b.txt");
57
58 startWatcher(dir: "dir");
59
60 deleteDir("dir");
61 inAnyOrder(() {
62 expectRemoveEvent("dir/a.txt");
63 expectRemoveEvent("dir/b.txt");
64 });
65 });
66
67 group("moves", () {
68 test('notifies when a file is moved within the watched directory', () {
69 writeFile("old.txt");
70 startWatcher();
71 renameFile("old.txt", "new.txt");
72
73 inAnyOrder(() {
74 expectAddEvent("new.txt");
75 expectRemoveEvent("old.txt");
76 });
77 });
78
79 test('notifies when a file is moved from outside the watched directory',
80 () {
81 writeFile("old.txt");
82 createDir("dir");
83 startWatcher(dir: "dir");
84
85 renameFile("old.txt", "dir/new.txt");
86 expectAddEvent("dir/new.txt");
87 });
88
89 test('notifies when a file is moved outside the watched directory', () {
90 writeFile("dir/old.txt");
91 startWatcher(dir: "dir");
92
93 renameFile("dir/old.txt", "new.txt");
94 expectRemoveEvent("dir/old.txt");
95 });
96 });
97
98 group("clustered changes", () {
99 test("doesn't notify when a file is created and then immediately removed",
100 () {
101 startWatcher();
102 writeFile("file.txt");
103 deleteFile("file.txt");
104
105 // [startWatcher] will assert that no events were fired.
106 });
107
108 test("reports a modification when a file is deleted and then immediately "
109 "recreated", () {
110 writeFile("file.txt");
111 startWatcher();
112
113 deleteFile("file.txt");
114 writeFile("file.txt", contents: "re-created");
115 expectModifyEvent("file.txt");
116 });
117
118 test("reports a modification when a file is moved and then immediately "
119 "recreated", () {
120 writeFile("old.txt");
121 startWatcher();
122
123 renameFile("old.txt", "new.txt");
124 writeFile("old.txt", contents: "re-created");
125 inAnyOrder(() {
126 expectModifyEvent("old.txt");
127 expectAddEvent("new.txt");
128 });
129 });
130
131 test("reports a removal when a file is modified and then immediately "
132 "removed", () {
133 writeFile("file.txt");
134 startWatcher();
135
136 writeFile("file.txt", contents: "modified");
137 deleteFile("file.txt");
138 expectRemoveEvent("file.txt");
139 });
140
141 test("reports an add when a file is added and then immediately modified",
142 () {
143 startWatcher();
144
145 writeFile("file.txt");
146 writeFile("file.txt", contents: "modified");
147 expectAddEvent("file.txt");
148 });
149 });
150
151 group("subdirectories", () {
152 test('watches files in subdirectories', () {
153 startWatcher();
154 writeFile("a/b/c/d/file.txt");
155 expectAddEvent("a/b/c/d/file.txt");
156 });
157
158 test('notifies when a subdirectory is moved within the watched directory '
159 'and then its contents are modified', () {
160 writeFile("old/file.txt");
161 startWatcher();
162
163 renameDir("old", "new");
164 inAnyOrder(() {
165 expectRemoveEvent("old/file.txt");
166 expectAddEvent("new/file.txt");
167 });
168
169 writeFile("new/file.txt", contents: "modified");
170 expectModifyEvent("new/file.txt");
171 });
172
173 test('emits events for many nested files added at once', () {
174 withPermutations((i, j, k) =>
175 writeFile("sub/sub-$i/sub-$j/file-$k.txt"));
176
177 createDir("dir");
178 startWatcher(dir: "dir");
179 renameDir("sub", "dir/sub");
180
181 inAnyOrder(() {
182 withPermutations((i, j, k) =>
183 expectAddEvent("dir/sub/sub-$i/sub-$j/file-$k.txt"));
184 });
185 });
186
187 test('emits events for many nested files removed at once', () {
188 withPermutations((i, j, k) =>
189 writeFile("dir/sub/sub-$i/sub-$j/file-$k.txt"));
190
191 createDir("dir");
192 startWatcher(dir: "dir");
193
194 // Rename the directory rather than deleting it because native watchers
195 // report a rename as a single DELETE event for the directory, whereas
196 // they report recursive deletion with DELETE events for every file in the
197 // directory.
198 renameDir("dir/sub", "sub");
199
200 inAnyOrder(() {
201 withPermutations((i, j, k) =>
202 expectRemoveEvent("dir/sub/sub-$i/sub-$j/file-$k.txt"));
203 });
204 });
205
206 test('emits events for many nested files moved at once', () {
207 withPermutations((i, j, k) =>
208 writeFile("dir/old/sub-$i/sub-$j/file-$k.txt"));
209
210 createDir("dir");
211 startWatcher(dir: "dir");
212 renameDir("dir/old", "dir/new");
213
214 inAnyOrder(() {
215 withPermutations((i, j, k) {
216 expectRemoveEvent("dir/old/sub-$i/sub-$j/file-$k.txt");
217 expectAddEvent("dir/new/sub-$i/sub-$j/file-$k.txt");
218 });
219 });
220 });
221 });
222 }
OLDNEW
« no previous file with comments | « pkg/watcher/test/directory_watcher/polling_test.dart ('k') | pkg/watcher/test/directory_watcher_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698