|
@@ -1,5 +1,6 @@
|
|
package test;
|
|
package test;
|
|
|
|
|
|
|
|
+import asys.FileWatcherEvent;
|
|
import utest.Async;
|
|
import utest.Async;
|
|
import asys.FileSystem as NewFS;
|
|
import asys.FileSystem as NewFS;
|
|
import asys.io.File as NewFile;
|
|
import asys.io.File as NewFile;
|
|
@@ -73,17 +74,20 @@ class TestAsyncFileSystem extends Test {
|
|
eq(asyncDone, 0);
|
|
eq(asyncDone, 0);
|
|
}
|
|
}
|
|
|
|
|
|
- @:timeout(3000)
|
|
|
|
function testWatcher(async:Async) {
|
|
function testWatcher(async:Async) {
|
|
- if (Sys.systemName() == "Windows" || Sys.systemName() == "Linux") { // TODO
|
|
|
|
- t(true);
|
|
|
|
- async.done();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
var dir = "resources-rw/watch";
|
|
var dir = "resources-rw/watch";
|
|
sys.FileSystem.createDirectory(dir);
|
|
sys.FileSystem.createDirectory(dir);
|
|
- var events = [];
|
|
|
|
|
|
+ var expectedEvents:Array<FileWatcherEvent -> Bool> = [
|
|
|
|
+ event -> event.match(Rename("foo")),
|
|
|
|
+ event -> switch(event) {
|
|
|
|
+ case Rename("foo/hello.txt" | "foo\\hello.txt"): true;
|
|
|
|
+ case _: false;
|
|
|
|
+ },
|
|
|
|
+ event -> switch(event) {
|
|
|
|
+ case Change("foo/hello.txt" | "foo\\hello.txt"): true;
|
|
|
|
+ case _: false;
|
|
|
|
+ }
|
|
|
|
+ ];
|
|
|
|
|
|
var watcher = NewFS.watch(dir, true);
|
|
var watcher = NewFS.watch(dir, true);
|
|
watcher.closeSignal.on(_ -> {
|
|
watcher.closeSignal.on(_ -> {
|
|
@@ -91,24 +95,35 @@ class TestAsyncFileSystem extends Test {
|
|
OldFS.deleteDirectory(dir);
|
|
OldFS.deleteDirectory(dir);
|
|
});
|
|
});
|
|
watcher.errorSignal.on(e -> assert('unexpected error: ${e.message}'));
|
|
watcher.errorSignal.on(e -> assert('unexpected error: ${e.message}'));
|
|
- watcher.changeSignal.on(events.push);
|
|
|
|
-
|
|
|
|
- NewFS.mkdir('$dir/foo');
|
|
|
|
-
|
|
|
|
- t(events.length == 1 && events[0].match(Rename("foo")));
|
|
|
|
- events.resize(0);
|
|
|
|
-
|
|
|
|
- var file = NewFS.open('$dir/foo/hello.txt', "w");
|
|
|
|
- file.truncate(10);
|
|
|
|
- file.close();
|
|
|
|
- NewFS.unlink('$dir/foo/hello.txt');
|
|
|
|
|
|
|
|
- NewFS.rmdir('$dir/foo');
|
|
|
|
-
|
|
|
|
- t(events.length == 2 && events[0].match(Rename("foo/hello.txt")));
|
|
|
|
- t(events.length == 2 && events[1].match(Rename("foo")));
|
|
|
|
- events.resize(0);
|
|
|
|
|
|
+ var continuations = [];
|
|
|
|
+
|
|
|
|
+ watcher.changeSignal.on(event -> {
|
|
|
|
+ t(expectedEvents.length > 0);
|
|
|
|
+ var expected = expectedEvents.shift();
|
|
|
|
+ t(expected(event));
|
|
|
|
+ if (continuations.length > 0) {
|
|
|
|
+ continuations.shift()();
|
|
|
|
+ }
|
|
|
|
+ if (expectedEvents.length == 0) {
|
|
|
|
+ watcher.close();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
- watcher.close();
|
|
|
|
|
|
+ continuations.push(() -> {
|
|
|
|
+ var file = NewFS.open('$dir/foo/hello.txt', "w");
|
|
|
|
+ file.truncate(10);
|
|
|
|
+ file.close();
|
|
|
|
+ });
|
|
|
|
+ continuations.push(() -> {
|
|
|
|
+ var file = NewFS.open('$dir/foo/hello.txt', "w");
|
|
|
|
+ file.truncate(5);
|
|
|
|
+ file.close();
|
|
|
|
+ });
|
|
|
|
+ continuations.push(() -> {
|
|
|
|
+ NewFS.unlink('$dir/foo/hello.txt');
|
|
|
|
+ NewFS.rmdir('$dir/foo');
|
|
|
|
+ });
|
|
|
|
+ NewFS.mkdir('$dir/foo');
|
|
}
|
|
}
|
|
}
|
|
}
|