1
0
forked from mirrors/0ad

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.
This commit is contained in:
Stan
2025-06-13 17:44:33 +02:00
committed by phosit
parent 2a47bbf096
commit 6a0dfa6dc1
2 changed files with 20 additions and 1 deletions
+4
View File
@@ -79,6 +79,10 @@ Status ReloadChangedFiles()
std::vector<DirWatchNotification> 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]))
+16 -1
View File
@@ -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 <CoreFoundation/CoreFoundation.h>
#endif
#if OS_LINUX
#include <cstdlib>
#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&)