From 8438c509e9a5159f516fc0498998238f9de5d394 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 18 Jan 2023 14:01:37 -0500 Subject: [PATCH] LibCore: Make the FileWatcher test resilient against outside events The test currently watches /tmp, which the OS can create/modify files under at any time outside of our control. So just ignore events that we aren't interested in. Also test removing an item from the FileWatcher. --- Tests/LibCore/TestLibCoreFileWatcher.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Tests/LibCore/TestLibCoreFileWatcher.cpp b/Tests/LibCore/TestLibCoreFileWatcher.cpp index 2d384f1cb8..39c9163083 100644 --- a/Tests/LibCore/TestLibCoreFileWatcher.cpp +++ b/Tests/LibCore/TestLibCoreFileWatcher.cpp @@ -26,12 +26,16 @@ TEST_CASE(file_watcher_child_events) int event_count = 0; file_watcher->on_change = [&](Core::FileWatcherEvent const& event) { + // Ignore path events under /tmp that can occur for anything else the OS is + // doing to create/delete files there. + if (event.event_path != "/tmp/testfile"sv) + return; + if (event_count == 0) { - EXPECT_EQ(event.event_path, "/tmp/testfile"); EXPECT(has_flag(event.type, Core::FileWatcherEvent::Type::ChildCreated)); } else if (event_count == 1) { - EXPECT_EQ(event.event_path, "/tmp/testfile"); EXPECT(has_flag(event.type, Core::FileWatcherEvent::Type::ChildDeleted)); + EXPECT(MUST(file_watcher->remove_watch("/tmp/"sv))); event_loop.quit(0); }