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
2 changes: 1 addition & 1 deletion pkgs/watcher/test/file_watcher/link_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions pkgs/watcher/test/file_watcher/native_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions pkgs/watcher/test/file_watcher/polling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import 'package:watcher/watcher.dart';

import '../utils.dart';
import 'file_tests.dart';
import 'link_tests.dart';
import 'startup_race_tests.dart';

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

fileTests(isNative: false);
linkTests(isNative: false);
startupRaceTests(isNative: false);
}
14 changes: 14 additions & 0 deletions pkgs/watcher/test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down