Fix some analyzer warnings and hints in pkg/watcher. R=rnystrom@google.com BUG= Review URL: https://codereview.chromium.org//69013003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/watcher@30172 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/pkgs/watcher/lib/src/constructable_file_system_event.dart b/pkgs/watcher/lib/src/constructable_file_system_event.dart index e65e258..010d297 100644 --- a/pkgs/watcher/lib/src/constructable_file_system_event.dart +++ b/pkgs/watcher/lib/src/constructable_file_system_event.dart
@@ -9,7 +9,7 @@ abstract class _ConstructableFileSystemEvent implements FileSystemEvent { final bool isDirectory; final String path; - final int type; + int get type; _ConstructableFileSystemEvent(this.path, this.isDirectory); }
diff --git a/pkgs/watcher/lib/src/directory_watcher/linux.dart b/pkgs/watcher/lib/src/directory_watcher/linux.dart index f0622f6..5196078 100644 --- a/pkgs/watcher/lib/src/directory_watcher/linux.dart +++ b/pkgs/watcher/lib/src/directory_watcher/linux.dart
@@ -7,7 +7,6 @@ import 'dart:async'; import 'dart:io'; -import '../directory_watcher.dart'; import '../utils.dart'; import '../watch_event.dart'; import 'resubscribable.dart';
diff --git a/pkgs/watcher/lib/src/directory_watcher/mac_os.dart b/pkgs/watcher/lib/src/directory_watcher/mac_os.dart index 9d3660d..5b1feb3 100644 --- a/pkgs/watcher/lib/src/directory_watcher/mac_os.dart +++ b/pkgs/watcher/lib/src/directory_watcher/mac_os.dart
@@ -13,8 +13,6 @@ import '../watch_event.dart'; import 'resubscribable.dart'; -import 'package:path/path.dart' as p; - /// Uses the FSEvents subsystem to watch for filesystem events. /// /// FSEvents has two main idiosyncrasies that this class works around. First, it @@ -337,7 +335,7 @@ /// Emit an error, then close the watcher. void _emitError(error, StackTrace stackTrace) { - _eventsController.add(error, stackTrace); + _eventsController.addError(error, stackTrace); close(); }
diff --git a/pkgs/watcher/lib/src/directory_watcher/polling.dart b/pkgs/watcher/lib/src/directory_watcher/polling.dart index 91ca005..0e190b0 100644 --- a/pkgs/watcher/lib/src/directory_watcher/polling.dart +++ b/pkgs/watcher/lib/src/directory_watcher/polling.dart
@@ -10,7 +10,6 @@ import 'package:crypto/crypto.dart'; import '../async_queue.dart'; -import '../directory_watcher.dart'; import '../stat.dart'; import '../utils.dart'; import '../watch_event.dart';
diff --git a/pkgs/watcher/lib/src/directory_watcher/resubscribable.dart b/pkgs/watcher/lib/src/directory_watcher/resubscribable.dart index daa813a..7d99fc0 100644 --- a/pkgs/watcher/lib/src/directory_watcher/resubscribable.dart +++ b/pkgs/watcher/lib/src/directory_watcher/resubscribable.dart
@@ -5,10 +5,8 @@ library watcher.directory_watcher.resubscribable; import 'dart:async'; -import 'dart:io'; import '../directory_watcher.dart'; -import '../utils.dart'; import '../watch_event.dart'; typedef ManuallyClosedDirectoryWatcher WatcherFactory();
diff --git a/pkgs/watcher/test/directory_watcher/shared.dart b/pkgs/watcher/test/directory_watcher/shared.dart index 34b5e62..fe76a03 100644 --- a/pkgs/watcher/test/directory_watcher/shared.dart +++ b/pkgs/watcher/test/directory_watcher/shared.dart
@@ -6,8 +6,6 @@ import '../utils.dart'; -import 'dart:async'; - sharedTests() { test('does not notify for files that already exist when started', () { // Make some pre-existing files.
diff --git a/pkgs/watcher/test/no_subscription/shared.dart b/pkgs/watcher/test/no_subscription/shared.dart index cd279e1..6623ba3 100644 --- a/pkgs/watcher/test/no_subscription/shared.dart +++ b/pkgs/watcher/test/no_subscription/shared.dart
@@ -19,8 +19,7 @@ // Subscribe to the events. var completer = new Completer(); var subscription = watcher.events.listen(wrapAsync((event) { - expect(event.type, equals(ChangeType.ADD)); - expect(event.path, endsWith("file.txt")); + expect(event, isWatchEvent(ChangeType.ADD, "file.txt")); completer.complete(); })); @@ -41,10 +40,19 @@ schedule(() { completer = new Completer(); subscription = watcher.events.listen(wrapAsync((event) { + // TODO(nweiz): Remove this when either issue 14373 or 14793 is fixed. + // Issue 14373 means that the new [Directory.watch] will emit an event + // for "unwatched.txt" being created, and issue 14793 means we have to + // check the filesystem, which leads us to assume that the file has been + // modified. + if (Platform.isMacOS && event.path.endsWith("unwatched.txt")) { + expect(event, isWatchEvent(ChangeType.MODIFY, "unwatched.txt")); + return; + } + // We should get an event for the third file, not the one added while // we weren't subscribed. - expect(event.type, equals(ChangeType.ADD)); - expect(event.path, endsWith("added.txt")); + expect(event, isWatchEvent(ChangeType.ADD, "added.txt")); completer.complete(); }));
diff --git a/pkgs/watcher/test/utils.dart b/pkgs/watcher/test/utils.dart index e18c7e8..651fd6d 100644 --- a/pkgs/watcher/test/utils.dart +++ b/pkgs/watcher/test/utils.dart
@@ -176,11 +176,6 @@ /// Multiple calls to [expectEvent] require that the events are received in that /// order unless they're called in an [inAnyOrder] block. void expectEvent(ChangeType type, String path) { - var matcher = predicate((e) { - return e is WatchEvent && e.type == type && - e.path == p.join(_sandboxDir, p.normalize(path)); - }, "is $type $path"); - if (_unorderedEventFuture != null) { // Assign this to a local variable since it will be un-assigned by the time // the scheduled callback runs. @@ -188,7 +183,7 @@ expect( schedule(() => future, "should fire $type event on $path"), - completion(contains(matcher))); + completion(contains(isWatchEvent(type, path)))); } else { var future = currentSchedule.wrapFuture( _watcherEvents.elementAt(_nextEvent), @@ -196,11 +191,20 @@ expect( schedule(() => future, "should fire $type event on $path"), - completion(matcher)); + completion(isWatchEvent(type, path))); } _nextEvent++; } +/// Returns a matcher that matches a [WatchEvent] with the given [type] and +/// [path]. +Match isWatchEvent(ChangeType type, String path) { + return predicate((e) { + return e is WatchEvent && e.type == type && + e.path == p.join(_sandboxDir, p.normalize(path)); + }, "is $type $path"); +} + void expectAddEvent(String path) => expectEvent(ChangeType.ADD, path); void expectModifyEvent(String path) => expectEvent(ChangeType.MODIFY, path); void expectRemoveEvent(String path) => expectEvent(ChangeType.REMOVE, path);