Skip to content

Commit edf4111

Browse files
committed
Unify watcher tests.
1 parent fa978cd commit edf4111

File tree

5 files changed

+59
-63
lines changed

5 files changed

+59
-63
lines changed

pkgs/watcher/test/directory_watcher/file_tests.dart

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import 'package:watcher/src/utils.dart';
1111

1212
import '../utils.dart';
1313

14-
void fileTests() {
14+
void fileTests({required bool isNative}) {
1515
for (var i = 0; i != runsPerTest; ++i) {
16-
_fileTests();
16+
_fileTests(isNative: isNative);
1717
}
1818
}
1919

20-
void _fileTests() {
20+
void _fileTests({required bool isNative}) {
2121
test('does not notify for files that already exist when started', () async {
2222
// Make some pre-existing files.
2323
writeFile('a.txt');
@@ -297,6 +297,29 @@ void _fileTests() {
297297
})));
298298
});
299299

300+
test(
301+
'emits events for many nested files moved out then immediately back in',
302+
() async {
303+
withPermutations(
304+
(i, j, k) => writeFile('dir/sub/sub-$i/sub-$j/file-$k.txt'));
305+
306+
await startWatcher(path: 'dir');
307+
308+
renameDir('dir/sub', 'sub');
309+
renameDir('sub', 'dir/sub');
310+
311+
if (isNative) {
312+
await inAnyOrder(withPermutations(
313+
(i, j, k) => isRemoveEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
314+
await inAnyOrder(withPermutations(
315+
(i, j, k) => isAddEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
316+
} else {
317+
// Polling watchers can't detect this as directory contents mtimes
318+
// aren't updated when the directory is moved.
319+
await expectNoEvents();
320+
}
321+
});
322+
300323
test(
301324
'emits events for many files added at once in a subdirectory with the '
302325
'same name as a removed file', () async {
@@ -334,4 +357,32 @@ void _fileTests() {
334357
}
335358
});
336359
});
360+
361+
test(
362+
'does not notify about the watched directory being deleted and '
363+
'recreated immediately before watching', () async {
364+
createDir('dir');
365+
writeFile('dir/old.txt');
366+
deleteDir('dir');
367+
createDir('dir');
368+
369+
await startWatcher(path: 'dir');
370+
writeFile('dir/newer.txt');
371+
await expectAddEvent('dir/newer.txt');
372+
});
373+
374+
test('does not suppress files with the same prefix as a directory', () async {
375+
// Regression test for https://github.com/dart-lang/watcher/issues/83
376+
writeFile('some_name.txt');
377+
378+
await startWatcher();
379+
380+
writeFile('some_name/some_name.txt');
381+
deleteFile('some_name.txt');
382+
383+
await inAnyOrder([
384+
isAddEvent('some_name/some_name.txt'),
385+
isRemoveEvent('some_name.txt')
386+
]);
387+
});
337388
}

pkgs/watcher/test/directory_watcher/linux_test.dart

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,10 @@ import 'link_tests.dart';
1616
void main() {
1717
watcherFactory = LinuxDirectoryWatcher.new;
1818

19-
fileTests();
19+
fileTests(isNative: true);
2020
linkTests(isNative: true);
2121

2222
test('DirectoryWatcher creates a LinuxDirectoryWatcher on Linux', () {
2323
expect(DirectoryWatcher('.'), const TypeMatcher<LinuxDirectoryWatcher>());
2424
});
25-
26-
test('emits events for many nested files moved out then immediately back in',
27-
() async {
28-
withPermutations(
29-
(i, j, k) => writeFile('dir/sub/sub-$i/sub-$j/file-$k.txt'));
30-
await startWatcher(path: 'dir');
31-
32-
renameDir('dir/sub', 'sub');
33-
renameDir('sub', 'dir/sub');
34-
35-
await inAnyOrder(withPermutations(
36-
(i, j, k) => isRemoveEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
37-
await inAnyOrder(withPermutations(
38-
(i, j, k) => isAddEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
39-
});
4025
}

pkgs/watcher/test/directory_watcher/mac_os_test.dart

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,10 @@ import 'link_tests.dart';
1616
void main() {
1717
watcherFactory = MacOSDirectoryWatcher.new;
1818

19-
fileTests();
19+
fileTests(isNative: true);
2020
linkTests(isNative: true);
2121

2222
test('DirectoryWatcher creates a MacOSDirectoryWatcher on Mac OS', () {
2323
expect(DirectoryWatcher('.'), const TypeMatcher<MacOSDirectoryWatcher>());
2424
});
25-
26-
test(
27-
'does not notify about the watched directory being deleted and '
28-
'recreated immediately before watching', () async {
29-
createDir('dir');
30-
writeFile('dir/old.txt');
31-
deleteDir('dir');
32-
createDir('dir');
33-
34-
await startWatcher(path: 'dir');
35-
writeFile('dir/newer.txt');
36-
await expectAddEvent('dir/newer.txt');
37-
});
38-
39-
test('emits events for many nested files moved out then immediately back in',
40-
() async {
41-
withPermutations(
42-
(i, j, k) => writeFile('dir/sub/sub-$i/sub-$j/file-$k.txt'));
43-
44-
await startWatcher(path: 'dir');
45-
46-
renameDir('dir/sub', 'sub');
47-
renameDir('sub', 'dir/sub');
48-
49-
await inAnyOrder(withPermutations(
50-
(i, j, k) => isRemoveEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
51-
await inAnyOrder(withPermutations(
52-
(i, j, k) => isAddEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
53-
});
54-
test('does not suppress files with the same prefix as a directory', () async {
55-
// Regression test for https://github.com/dart-lang/watcher/issues/83
56-
writeFile('some_name.txt');
57-
58-
await startWatcher();
59-
60-
writeFile('some_name/some_name.txt');
61-
deleteFile('some_name.txt');
62-
63-
await expectRemoveEvent('some_name.txt');
64-
});
6525
}

pkgs/watcher/test/directory_watcher/polling_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void main() {
2121
group('with mock mtime', () {
2222
setUp(enableMockModificationTimes);
2323

24-
fileTests();
24+
fileTests(isNative: false);
2525
linkTests(isNative: false);
2626

2727
test('does not notify if the modification time did not change', () async {
@@ -71,7 +71,7 @@ void main() {
7171
group('with real mtime', () {
7272
setUp(enableWaitingForDifferentModificationTimes);
7373

74-
fileTests();
74+
fileTests(isNative: false);
7575
linkTests(isNative: false);
7676
});
7777
}

pkgs/watcher/test/directory_watcher/windows_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import 'link_tests.dart';
2121
void main() {
2222
watcherFactory = WindowsDirectoryWatcher.new;
2323

24-
fileTests();
24+
fileTests(isNative: true);
2525
linkTests(isNative: true);
2626

2727
test('DirectoryWatcher creates a WindowsDirectoryWatcher on Windows', () {

0 commit comments

Comments
 (0)