From e154446a9dfd63ef70a8950ecb2bdfcd84184f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 23 Nov 2017 02:42:30 +0100 Subject: [PATCH] Enable directory watcher tests on macOS. Also fixes some timings to work with the polling watcher implementation. --- tests/0-dirwatcher-rec.d | 5 ----- tests/0-dirwatcher.d | 34 +++++++++++++++++----------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/tests/0-dirwatcher-rec.d b/tests/0-dirwatcher-rec.d index 67cac90..a38a25d 100644 --- a/tests/0-dirwatcher-rec.d +++ b/tests/0-dirwatcher-rec.d @@ -26,9 +26,6 @@ FileChange[] pendingChanges; void main() { - version (OSX) writefln("Directory watchers are not yet supported on macOS. Skipping test."); - else { - if (exists(testDir)) rmdirRecurse(testDir); @@ -73,8 +70,6 @@ void main() // make sure that no watchers are registered anymore auto er = eventDriver.core.processEvents(10.msecs); assert(er == ExitReason.outOfWaiters); - - } } void testCallback(WatcherID w, in ref FileChange ch) diff --git a/tests/0-dirwatcher.d b/tests/0-dirwatcher.d index c6ff710..c423b74 100644 --- a/tests/0-dirwatcher.d +++ b/tests/0-dirwatcher.d @@ -6,40 +6,42 @@ module test; import eventcore.core; import std.stdio : File, writefln; -import std.file : exists, remove; +import std.file : exists, mkdir, remove, rmdirRecurse; import core.time : Duration, msecs; bool s_done; int s_cnt = 0; +enum testDir = "watcher_test"; enum testFilename = "test.dat"; void main() { - version (OSX) writefln("Directory watchers are not yet supported on macOS. Skipping test."); - else { + if (exists(testDir)) + rmdirRecurse(testDir); + mkdir(testDir); + scope (exit) rmdirRecurse(testDir); - if (exists(testFilename)) - remove(testFilename); - - auto id = eventDriver.watchers.watchDirectory(".", false, (id, ref change) { + auto id = eventDriver.watchers.watchDirectory(testDir, false, (id, ref change) { switch (s_cnt++) { - default: assert(false); + default: + import std.conv : to; + assert(false, "Unexpected change: "~change.to!string); case 0: assert(change.kind == FileChangeKind.added); - assert(change.baseDirectory == "."); + assert(change.baseDirectory == testDir); assert(change.directory == ""); assert(change.name == testFilename); break; case 1: assert(change.kind == FileChangeKind.modified); - assert(change.baseDirectory == "."); + assert(change.baseDirectory == testDir); assert(change.directory == ""); assert(change.name == testFilename); break; case 2: assert(change.kind == FileChangeKind.removed); - assert(change.baseDirectory == "."); + assert(change.baseDirectory == testDir); assert(change.directory == ""); assert(change.name == testFilename); 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(); - eventDriver.timers.set(tm, 100.msecs, 0.msecs); + eventDriver.timers.set(tm, 1500.msecs, 0.msecs); eventDriver.timers.wait(tm, (tm) { scope (failure) assert(false); fil.write("test"); fil.close(); - eventDriver.timers.set(tm, 100.msecs, 0.msecs); + eventDriver.timers.set(tm, 1500.msecs, 0.msecs); eventDriver.timers.wait(tm, (tm) { scope (failure) assert(false); - remove(testFilename); + remove(testDir~"/"~testFilename); }); }); @@ -69,6 +71,4 @@ void main() assert(er == ExitReason.outOfWaiters); assert(s_done); s_done = false; - - } }