diff --git a/pkgs/watcher/test/file_watcher/link_tests.dart b/pkgs/watcher/test/file_watcher/link_tests.dart index a6eef1403..6b86cc236 100644 --- a/pkgs/watcher/test/file_watcher/link_tests.dart +++ b/pkgs/watcher/test/file_watcher/link_tests.dart @@ -98,7 +98,7 @@ void linkTests({required bool isNative}) { test('notifies when a link is moved away', () async { await startWatcher(path: 'link.txt'); - renameFile('link.txt', 'new.txt'); + renameLink('link.txt', 'new.txt'); // TODO(davidmorgan): reconcile differences. if (isNative) { diff --git a/pkgs/watcher/test/file_watcher/native_test.dart b/pkgs/watcher/test/file_watcher/native_test.dart index 30f319432..92224327d 100644 --- a/pkgs/watcher/test/file_watcher/native_test.dart +++ b/pkgs/watcher/test/file_watcher/native_test.dart @@ -10,11 +10,13 @@ import 'package:watcher/src/file_watcher/native.dart'; import '../utils.dart'; import 'file_tests.dart'; +import 'link_tests.dart'; import 'startup_race_tests.dart'; void main() { watcherFactory = NativeFileWatcher.new; fileTests(isNative: true); + linkTests(isNative: true); startupRaceTests(isNative: true); } diff --git a/pkgs/watcher/test/file_watcher/polling_test.dart b/pkgs/watcher/test/file_watcher/polling_test.dart index b8e41570d..c1590e783 100644 --- a/pkgs/watcher/test/file_watcher/polling_test.dart +++ b/pkgs/watcher/test/file_watcher/polling_test.dart @@ -6,6 +6,7 @@ import 'package:watcher/watcher.dart'; import '../utils.dart'; import 'file_tests.dart'; +import 'link_tests.dart'; import 'startup_race_tests.dart'; void main() { @@ -13,5 +14,6 @@ void main() { PollingFileWatcher(file, pollingDelay: const Duration(milliseconds: 100)); fileTests(isNative: false); + linkTests(isNative: false); startupRaceTests(isNative: false); } diff --git a/pkgs/watcher/test/utils.dart b/pkgs/watcher/test/utils.dart index aa5cc2ea4..6f61f9a8b 100644 --- a/pkgs/watcher/test/utils.dart +++ b/pkgs/watcher/test/utils.dart @@ -292,6 +292,20 @@ void renameFile(String from, String to) { ifAbsent: () => 1); } +/// Schedules renaming a link in the sandbox from [from] to [to]. +/// +/// On MacOS and Linux links can also be named with `renameFile`. On Windows, +/// however, a link must be renamed with this method. +void renameLink(String from, String to) { + Link(p.join(d.sandbox, from)).renameSync(p.join(d.sandbox, to)); + + // Make sure we always use the same separator on Windows. + to = p.normalize(to); + + _mockFileModificationTimes.update(to, (value) => value + 1, + ifAbsent: () => 1); +} + /// Schedules creating a directory in the sandbox at [path]. void createDir(String path) { Directory(p.join(d.sandbox, path)).createSync();