Enable directory watcher tests on macOS.

Also fixes some timings to work with the polling watcher implementation.
This commit is contained in:
Sönke Ludwig 2017-11-23 02:42:30 +01:00
parent 19879712e6
commit e154446a9d
2 changed files with 17 additions and 22 deletions

View file

@ -26,9 +26,6 @@ FileChange[] pendingChanges;
void main() void main()
{ {
version (OSX) writefln("Directory watchers are not yet supported on macOS. Skipping test.");
else {
if (exists(testDir)) if (exists(testDir))
rmdirRecurse(testDir); rmdirRecurse(testDir);
@ -73,8 +70,6 @@ void main()
// make sure that no watchers are registered anymore // make sure that no watchers are registered anymore
auto er = eventDriver.core.processEvents(10.msecs); auto er = eventDriver.core.processEvents(10.msecs);
assert(er == ExitReason.outOfWaiters); assert(er == ExitReason.outOfWaiters);
}
} }
void testCallback(WatcherID w, in ref FileChange ch) void testCallback(WatcherID w, in ref FileChange ch)

View file

@ -6,40 +6,42 @@ module test;
import eventcore.core; import eventcore.core;
import std.stdio : File, writefln; import std.stdio : File, writefln;
import std.file : exists, remove; import std.file : exists, mkdir, remove, rmdirRecurse;
import core.time : Duration, msecs; import core.time : Duration, msecs;
bool s_done; bool s_done;
int s_cnt = 0; int s_cnt = 0;
enum testDir = "watcher_test";
enum testFilename = "test.dat"; enum testFilename = "test.dat";
void main() void main()
{ {
version (OSX) writefln("Directory watchers are not yet supported on macOS. Skipping test."); if (exists(testDir))
else { rmdirRecurse(testDir);
mkdir(testDir);
scope (exit) rmdirRecurse(testDir);
if (exists(testFilename)) auto id = eventDriver.watchers.watchDirectory(testDir, false, (id, ref change) {
remove(testFilename);
auto id = eventDriver.watchers.watchDirectory(".", false, (id, ref change) {
switch (s_cnt++) { switch (s_cnt++) {
default: assert(false); default:
import std.conv : to;
assert(false, "Unexpected change: "~change.to!string);
case 0: case 0:
assert(change.kind == FileChangeKind.added); assert(change.kind == FileChangeKind.added);
assert(change.baseDirectory == "."); assert(change.baseDirectory == testDir);
assert(change.directory == ""); assert(change.directory == "");
assert(change.name == testFilename); assert(change.name == testFilename);
break; break;
case 1: case 1:
assert(change.kind == FileChangeKind.modified); assert(change.kind == FileChangeKind.modified);
assert(change.baseDirectory == "."); assert(change.baseDirectory == testDir);
assert(change.directory == ""); assert(change.directory == "");
assert(change.name == testFilename); assert(change.name == testFilename);
break; break;
case 2: case 2:
assert(change.kind == FileChangeKind.removed); assert(change.kind == FileChangeKind.removed);
assert(change.baseDirectory == "."); assert(change.baseDirectory == testDir);
assert(change.directory == ""); assert(change.directory == "");
assert(change.name == testFilename); assert(change.name == testFilename);
eventDriver.watchers.releaseRef(id); eventDriver.watchers.releaseRef(id);
@ -48,18 +50,18 @@ void main()
} }
}); });
auto fil = File(testFilename, "wt"); auto fil = File(testDir~"/"~testFilename, "wt");
auto tm = eventDriver.timers.create(); auto tm = eventDriver.timers.create();
eventDriver.timers.set(tm, 100.msecs, 0.msecs); eventDriver.timers.set(tm, 1500.msecs, 0.msecs);
eventDriver.timers.wait(tm, (tm) { eventDriver.timers.wait(tm, (tm) {
scope (failure) assert(false); scope (failure) assert(false);
fil.write("test"); fil.write("test");
fil.close(); fil.close();
eventDriver.timers.set(tm, 100.msecs, 0.msecs); eventDriver.timers.set(tm, 1500.msecs, 0.msecs);
eventDriver.timers.wait(tm, (tm) { eventDriver.timers.wait(tm, (tm) {
scope (failure) assert(false); scope (failure) assert(false);
remove(testFilename); remove(testDir~"/"~testFilename);
}); });
}); });
@ -69,6 +71,4 @@ void main()
assert(er == ExitReason.outOfWaiters); assert(er == ExitReason.outOfWaiters);
assert(s_done); assert(s_done);
s_done = false; s_done = false;
}
} }