Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Unified Diff: pkg/analysis_server/test/resource_test.dart

Issue 303503007: Allow physical folder resources to be watched for changes to their contents. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/resource_test.dart
diff --git a/pkg/analysis_server/test/resource_test.dart b/pkg/analysis_server/test/resource_test.dart
index 1c9366b218096888e5b5f4d26daceeb005ff8674..dd8b8ee4e30a82c7323f6ea0a2913277bd4de950 100644
--- a/pkg/analysis_server/test/resource_test.dart
+++ b/pkg/analysis_server/test/resource_test.dart
@@ -4,6 +4,7 @@
library test.resource;
+import 'dart:async';
import 'dart:io' as io;
import 'package:analysis_server/src/resource.dart';
@@ -11,6 +12,7 @@ import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
import 'package:analyzer/src/generated/source_io.dart';
import 'package:path/path.dart';
import 'package:unittest/unittest.dart';
+import 'package:watcher/watcher.dart';
main() {
groupSep = ' | ';
@@ -250,6 +252,92 @@ main() {
tempDirectory.deleteSync(recursive: true);
});
+ group('Watch', () {
+
+ Future delayed(computation()) {
+ // On windows, watching the filesystem is accomplished by polling once
scheglov 2014/05/27 22:15:14 "On Windows"
Paul Berry 2014/05/27 22:37:32 Done.
+ // per second. So wait 2 seconds to give time for polling to reliably
+ // occur.
+ return new Future.delayed(new Duration(seconds: 2), computation);
+ }
+
+ watchingFolder(String path, test(List<WatchEvent> changesReceived)) {
+ // Delay before we start watching the folder. This is necessary
+ // because on MacOS, file modifications that occur just before we start
+ // watching are sometimes misclassified as happening just after we
+ // start watching.
+ return delayed(() {
+ Folder folder = PhysicalResourceProvider.INSTANCE.getResource(path);
+ var changesReceived = <WatchEvent>[];
+ var subscription = folder.changes.listen(changesReceived.add);
+ // Delay running the rest of the test to allow folder.changes to take
+ // a snapshot of the current directory state. Otherwise it won't be
+ // able to reliably distinguish new files from modified ones.
+ return delayed(() => test(changesReceived)).whenComplete(() {
+ subscription.cancel();
+ });
+ });
+ }
+
+ test('create file', () => watchingFolder(tempPath, (changesReceived) {
+ expect(changesReceived, hasLength(0));
+ var path = join(tempPath, 'foo');
+ new io.File(path).writeAsStringSync('contents');
+ return delayed(() {
+ expect(changesReceived, hasLength(1));
+ expect(changesReceived[0].type, equals(ChangeType.ADD));
+ expect(changesReceived[0].path, equals(path));
+ });
+ }));
+
+ test('modify file', () {
+ var path = join(tempPath, 'foo');
+ var file = new io.File(path);
+ file.writeAsStringSync('contents 1');
+ return watchingFolder(tempPath, (changesReceived) {
+ expect(changesReceived, hasLength(0));
+ file.writeAsStringSync('contents 2');
+ return delayed(() {
+ expect(changesReceived, hasLength(1));
+ expect(changesReceived[0].type, equals(ChangeType.MODIFY));
+ expect(changesReceived[0].path, equals(path));
+ });
+ });
+ });
+
+ test('modify file in subdir', () {
+ var subdirPath = join(tempPath, 'foo');
+ new io.Directory(subdirPath).createSync();
+ var path = join(tempPath, 'bar');
+ var file = new io.File(path);
+ file.writeAsStringSync('contents 1');
+ return watchingFolder(tempPath, (changesReceived) {
+ expect(changesReceived, hasLength(0));
+ file.writeAsStringSync('contents 2');
+ return delayed(() {
+ expect(changesReceived, hasLength(1));
+ expect(changesReceived[0].type, equals(ChangeType.MODIFY));
+ expect(changesReceived[0].path, equals(path));
+ });
+ });
+ });
+
+ test('delete file', () {
+ var path = join(tempPath, 'foo');
+ var file = new io.File(path);
+ file.writeAsStringSync('contents 1');
+ return watchingFolder(tempPath, (changesReceived) {
+ expect(changesReceived, hasLength(0));
+ file.deleteSync();
+ return delayed(() {
+ expect(changesReceived, hasLength(1));
+ expect(changesReceived[0].type, equals(ChangeType.REMOVE));
+ expect(changesReceived[0].path, equals(path));
+ });
+ });
+ });
+ });
+
group('File', () {
String path;
File file;
« no previous file with comments | « pkg/analysis_server/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698