Skip to content

Commit 19f91a0

Browse files
authored
Run file watcher symlink tests. (#2189)
1 parent 7929379 commit 19f91a0

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

pkgs/watcher/test/file_watcher/link_tests.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void linkTests({required bool isNative}) {
9898

9999
test('notifies when a link is moved away', () async {
100100
await startWatcher(path: 'link.txt');
101-
renameFile('link.txt', 'new.txt');
101+
renameLink('link.txt', 'new.txt');
102102

103103
// TODO(davidmorgan): reconcile differences.
104104
if (isNative) {

pkgs/watcher/test/file_watcher/native_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import 'package:watcher/src/file_watcher/native.dart';
1010

1111
import '../utils.dart';
1212
import 'file_tests.dart';
13+
import 'link_tests.dart';
1314
import 'startup_race_tests.dart';
1415

1516
void main() {
1617
watcherFactory = NativeFileWatcher.new;
1718

1819
fileTests(isNative: true);
20+
linkTests(isNative: true);
1921
startupRaceTests(isNative: true);
2022
}

pkgs/watcher/test/file_watcher/polling_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import 'package:watcher/watcher.dart';
66

77
import '../utils.dart';
88
import 'file_tests.dart';
9+
import 'link_tests.dart';
910
import 'startup_race_tests.dart';
1011

1112
void main() {
1213
watcherFactory = (file) =>
1314
PollingFileWatcher(file, pollingDelay: const Duration(milliseconds: 100));
1415

1516
fileTests(isNative: false);
17+
linkTests(isNative: false);
1618
startupRaceTests(isNative: false);
1719
}

pkgs/watcher/test/utils.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,20 @@ void renameFile(String from, String to) {
292292
ifAbsent: () => 1);
293293
}
294294

295+
/// Schedules renaming a link in the sandbox from [from] to [to].
296+
///
297+
/// On MacOS and Linux links can also be named with `renameFile`. On Windows,
298+
/// however, a link must be renamed with this method.
299+
void renameLink(String from, String to) {
300+
Link(p.join(d.sandbox, from)).renameSync(p.join(d.sandbox, to));
301+
302+
// Make sure we always use the same separator on Windows.
303+
to = p.normalize(to);
304+
305+
_mockFileModificationTimes.update(to, (value) => value + 1,
306+
ifAbsent: () => 1);
307+
}
308+
295309
/// Schedules creating a directory in the sandbox at [path].
296310
void createDir(String path) {
297311
Directory(p.join(d.sandbox, path)).createSync();

0 commit comments

Comments
 (0)