Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions pkgs/watcher/test/directory_watcher/file_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import 'package:watcher/src/utils.dart';

import '../utils.dart';

void fileTests() {
void fileTests({required bool isNative}) {
for (var i = 0; i != runsPerTest; ++i) {
_fileTests();
_fileTests(isNative: isNative);
}
}

void _fileTests() {
void _fileTests({required bool isNative}) {
test('does not notify for files that already exist when started', () async {
// Make some pre-existing files.
writeFile('a.txt');
Expand Down Expand Up @@ -297,6 +297,29 @@ void _fileTests() {
})));
});

test(
'emits events for many nested files moved out then immediately back in',
() async {
withPermutations(
(i, j, k) => writeFile('dir/sub/sub-$i/sub-$j/file-$k.txt'));

await startWatcher(path: 'dir');

renameDir('dir/sub', 'sub');
renameDir('sub', 'dir/sub');

if (isNative) {
await inAnyOrder(withPermutations(
(i, j, k) => isRemoveEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
await inAnyOrder(withPermutations(
(i, j, k) => isAddEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
} else {
// Polling watchers can't detect this as directory contents mtimes
// aren't updated when the directory is moved.
await expectNoEvents();
}
});

test(
'emits events for many files added at once in a subdirectory with the '
'same name as a removed file', () async {
Expand Down Expand Up @@ -334,4 +357,32 @@ void _fileTests() {
}
});
});

test(
'does not notify about the watched directory being deleted and '
'recreated immediately before watching', () async {
createDir('dir');
writeFile('dir/old.txt');
deleteDir('dir');
createDir('dir');

await startWatcher(path: 'dir');
writeFile('dir/newer.txt');
await expectAddEvent('dir/newer.txt');
});

test('does not suppress files with the same prefix as a directory', () async {
// Regression test for https://github.com/dart-lang/watcher/issues/83
writeFile('some_name.txt');

await startWatcher();

writeFile('some_name/some_name.txt');
deleteFile('some_name.txt');

await inAnyOrder([
isAddEvent('some_name/some_name.txt'),
isRemoveEvent('some_name.txt')
]);
});
}
17 changes: 1 addition & 16 deletions pkgs/watcher/test/directory_watcher/linux_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,10 @@ import 'link_tests.dart';
void main() {
watcherFactory = LinuxDirectoryWatcher.new;

fileTests();
fileTests(isNative: true);
linkTests(isNative: true);

test('DirectoryWatcher creates a LinuxDirectoryWatcher on Linux', () {
expect(DirectoryWatcher('.'), const TypeMatcher<LinuxDirectoryWatcher>());
});

test('emits events for many nested files moved out then immediately back in',
() async {
withPermutations(
(i, j, k) => writeFile('dir/sub/sub-$i/sub-$j/file-$k.txt'));
await startWatcher(path: 'dir');

renameDir('dir/sub', 'sub');
renameDir('sub', 'dir/sub');

await inAnyOrder(withPermutations(
(i, j, k) => isRemoveEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
await inAnyOrder(withPermutations(
(i, j, k) => isAddEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
});
}
42 changes: 1 addition & 41 deletions pkgs/watcher/test/directory_watcher/mac_os_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,10 @@ import 'link_tests.dart';
void main() {
watcherFactory = MacOSDirectoryWatcher.new;

fileTests();
fileTests(isNative: true);
linkTests(isNative: true);

test('DirectoryWatcher creates a MacOSDirectoryWatcher on Mac OS', () {
expect(DirectoryWatcher('.'), const TypeMatcher<MacOSDirectoryWatcher>());
});

test(
'does not notify about the watched directory being deleted and '
'recreated immediately before watching', () async {
createDir('dir');
writeFile('dir/old.txt');
deleteDir('dir');
createDir('dir');

await startWatcher(path: 'dir');
writeFile('dir/newer.txt');
await expectAddEvent('dir/newer.txt');
});

test('emits events for many nested files moved out then immediately back in',
() async {
withPermutations(
(i, j, k) => writeFile('dir/sub/sub-$i/sub-$j/file-$k.txt'));

await startWatcher(path: 'dir');

renameDir('dir/sub', 'sub');
renameDir('sub', 'dir/sub');

await inAnyOrder(withPermutations(
(i, j, k) => isRemoveEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
await inAnyOrder(withPermutations(
(i, j, k) => isAddEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
});
test('does not suppress files with the same prefix as a directory', () async {
// Regression test for https://github.com/dart-lang/watcher/issues/83
writeFile('some_name.txt');

await startWatcher();

writeFile('some_name/some_name.txt');
deleteFile('some_name.txt');

await expectRemoveEvent('some_name.txt');
});
}
4 changes: 2 additions & 2 deletions pkgs/watcher/test/directory_watcher/polling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
group('with mock mtime', () {
setUp(enableMockModificationTimes);

fileTests();
fileTests(isNative: false);
linkTests(isNative: false);

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

fileTests();
fileTests(isNative: false);
linkTests(isNative: false);
});
}
2 changes: 1 addition & 1 deletion pkgs/watcher/test/directory_watcher/windows_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import 'link_tests.dart';
void main() {
watcherFactory = WindowsDirectoryWatcher.new;

fileTests();
fileTests(isNative: true);
linkTests(isNative: true);

test('DirectoryWatcher creates a WindowsDirectoryWatcher on Windows', () {
Expand Down
Loading