OLD | NEW |
---|---|
(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"); | |
Bob Nystrom
2013/11/06 19:24:04
Why doesn't this notify?
nweiz
2013/11/07 00:46:37
Because the file is no longer there, and we know t
| |
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 renameDir("dir/sub", "sub"); | |
Bob Nystrom
2013/11/06 19:24:04
deleteDir()?
nweiz
2013/11/07 00:46:37
Deleting a directory recursively is different than
Bob Nystrom
2013/11/07 18:16:05
OK, document this then.
nweiz
2013/11/07 22:46:28
Done.
| |
194 | |
195 inAnyOrder(() { | |
196 withPermutations((i, j, k) => | |
197 expectRemoveEvent("dir/sub/sub-$i/sub-$j/file-$k.txt")); | |
Bob Nystrom
2013/11/06 19:24:04
Do you test that you *don't* receive spurious even
nweiz
2013/11/07 00:46:37
Yes; my change to [startWatcher] asserts that no u
| |
198 }); | |
199 }); | |
200 | |
201 test('emits events for many nested files moved at once', () { | |
202 withPermutations((i, j, k) => | |
203 writeFile("dir/old/sub-$i/sub-$j/file-$k.txt")); | |
204 | |
205 createDir("dir"); | |
206 startWatcher(dir: "dir"); | |
207 renameDir("dir/old", "dir/new"); | |
208 | |
209 inAnyOrder(() { | |
210 withPermutations((i, j, k) { | |
211 expectRemoveEvent("dir/old/sub-$i/sub-$j/file-$k.txt"); | |
212 expectAddEvent("dir/new/sub-$i/sub-$j/file-$k.txt"); | |
213 }); | |
214 }); | |
215 }); | |
216 }); | |
217 } | |
OLD | NEW |