From 6a0dfa6dc17925519a2a6d61a3c959f43bbd1bfd Mon Sep 17 00:00:00 2001 From: Stan Date: Fri, 13 Jun 2025 17:44:33 +0200 Subject: [PATCH] Test whether some files are reloaded more directly Add a way to tell whether `ReloadChangedFiles` actually catched events by returning `INFO::SKIPPED` when it didn't. Unlike GUI apps, you have to explicitely tell macOS to punp events in console apps thus add a loop in the tests. --- source/ps/Filesystem.cpp | 4 ++++ source/scriptinterface/tests/test_Module.h | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/source/ps/Filesystem.cpp b/source/ps/Filesystem.cpp index 7afc210014..5352a3aea2 100644 --- a/source/ps/Filesystem.cpp +++ b/source/ps/Filesystem.cpp @@ -79,6 +79,10 @@ Status ReloadChangedFiles() std::vector notifications; RETURN_STATUS_IF_ERR(dir_watch_Poll(notifications)); + + if (notifications.empty()) + return INFO::SKIPPED; + for(size_t i = 0; i < notifications.size(); i++) { if(!CanIgnore(notifications[i])) diff --git a/source/scriptinterface/tests/test_Module.h b/source/scriptinterface/tests/test_Module.h index 4ea86cca25..800daddf4d 100644 --- a/source/scriptinterface/tests/test_Module.h +++ b/source/scriptinterface/tests/test_Module.h @@ -18,6 +18,7 @@ #include "lib/self_test.h" #include "lib/file/vfs/vfs.h" +#include "lib/status.h" #include "lib/sysdep/dir_watch.h" #include "ps/CLogger.h" #include "ps/Filesystem.h" @@ -28,6 +29,9 @@ #include "scriptinterface/ScriptContext.h" #include "scriptinterface/ScriptInterface.h" +#if OS_MAC || OS_MACOSX +#include +#endif #if OS_LINUX #include #endif @@ -63,7 +67,18 @@ void ClearFromCache(const VfsPath& path) throw std::runtime_error{"`touch` didn't work."}; #endif - ReloadChangedFiles(); + Status status{INFO::SKIPPED}; + while (status == INFO::SKIPPED) + { + status = ReloadChangedFiles(); +#if OS_MAC || OS_MACOSX + // Console apps don't have a run loop, so we need to wait + // a bit for the file watcher to catch up. + CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true); +#endif + } + + TS_ASSERT_OK(status); } bool AllowAllPredicate(const VfsPath&)