@@ -12,6 +12,9 @@ import 'package:test_descriptor/test_descriptor.dart' as d;
1212import 'package:watcher/src/stat.dart' ;
1313import 'package:watcher/watcher.dart' ;
1414
15+ /// Edit this to run fast-running tests many times.
16+ int runsPerTest = 1 ;
17+
1518typedef WatcherFactory = Watcher Function (String directory);
1619
1720/// Sets the function used to create the watcher.
@@ -164,62 +167,18 @@ void startClosingEventStream() async {
164167 await _watcherEvents.cancel (immediate: true );
165168}
166169
167- /// A list of [StreamMatcher] s that have been collected using
168- /// [_collectStreamMatcher] .
169- List <StreamMatcher >? _collectedStreamMatchers;
170-
171- /// Collects all stream matchers that are registered within [block] into a
172- /// single stream matcher.
173- ///
174- /// The returned matcher will match each of the collected matchers in order.
175- StreamMatcher _collectStreamMatcher (void Function () block) {
176- var oldStreamMatchers = _collectedStreamMatchers;
177- var collectedStreamMatchers = _collectedStreamMatchers = < StreamMatcher > [];
178- try {
179- block ();
180- return emitsInOrder (collectedStreamMatchers);
181- } finally {
182- _collectedStreamMatchers = oldStreamMatchers;
183- }
184- }
185-
186- /// Either add [streamMatcher] as an expectation to [_watcherEvents] , or collect
187- /// it with [_collectStreamMatcher] .
170+ /// Add [streamMatcher] as an expectation to [_watcherEvents] .
188171///
189172/// [streamMatcher] can be a [StreamMatcher] , a [Matcher] , or a value.
190- Future _expectOrCollect (Matcher streamMatcher) {
191- var collectedStreamMatchers = _collectedStreamMatchers;
192- if (collectedStreamMatchers != null ) {
193- collectedStreamMatchers.add (emits (streamMatcher));
194- return Future .sync (() {});
195- } else {
196- return expectLater (_watcherEvents, emits (streamMatcher));
197- }
173+ Future _expect (Matcher streamMatcher) {
174+ return expectLater (_watcherEvents, emits (streamMatcher));
198175}
199176
200177/// Expects that [matchers] will match emitted events in any order.
201178///
202179/// [matchers] may be [Matcher] s or values, but not [StreamMatcher] s.
203- Future inAnyOrder (Iterable matchers) {
204- matchers = matchers.toSet ();
205- return _expectOrCollect (emitsInAnyOrder (matchers));
206- }
207-
208- /// Expects that the expectations established in either [block1] or [block2]
209- /// will match the emitted events.
210- ///
211- /// If both blocks match, the one that consumed more events will be used.
212- Future allowEither (void Function () block1, void Function () block2) =>
213- _expectOrCollect (emitsAnyOf (
214- [_collectStreamMatcher (block1), _collectStreamMatcher (block2)]));
215-
216- /// Allows the expectations established in [block] to match the emitted events.
217- ///
218- /// If the expectations in [block] don't match, no error will be raised and no
219- /// events will be consumed. If this is used at the end of a test,
220- /// [startClosingEventStream] should be called before it.
221- Future allowEvents (void Function () block) =>
222- _expectOrCollect (mayEmit (_collectStreamMatcher (block)));
180+ Future inAnyOrder (Iterable matchers) =>
181+ _expect (emitsInAnyOrder (matchers.toSet ()));
223182
224183/// Returns a StreamMatcher that matches a [WatchEvent] with the given [type]
225184/// and [path] .
@@ -274,24 +233,16 @@ Future<List<WatchEvent>> takeEvents({required Duration duration}) async {
274233
275234/// Expects that the next event emitted will be for an add event for [path] .
276235Future expectAddEvent (String path) =>
277- _expectOrCollect (isWatchEvent (ChangeType .ADD , path));
236+ _expect (isWatchEvent (ChangeType .ADD , path));
278237
279238/// Expects that the next event emitted will be for a modification event for
280239/// [path] .
281240Future expectModifyEvent (String path) =>
282- _expectOrCollect (isWatchEvent (ChangeType .MODIFY , path));
241+ _expect (isWatchEvent (ChangeType .MODIFY , path));
283242
284243/// Expects that the next event emitted will be for a removal event for [path] .
285244Future expectRemoveEvent (String path) =>
286- _expectOrCollect (isWatchEvent (ChangeType .REMOVE , path));
287-
288- /// Consumes a modification event for [path] if one is emitted at this point in
289- /// the schedule, but doesn't throw an error if it isn't.
290- ///
291- /// If this is used at the end of a test, [startClosingEventStream] should be
292- /// called before it.
293- Future allowModifyEvent (String path) =>
294- _expectOrCollect (mayEmit (isWatchEvent (ChangeType .MODIFY , path)));
245+ _expect (isWatchEvent (ChangeType .REMOVE , path));
295246
296247/// Track a fake timestamp to be used when writing files. This always increases
297248/// so that files that are deleted and re-created do not have their timestamp
0 commit comments