Using Gio::FileMonitor for watching style changes

This commit is contained in:
dpayne
2024-01-21 20:49:13 -08:00
parent d7ed4f1fa8
commit f7eca99496
3 changed files with 58 additions and 190 deletions

View File

@ -124,65 +124,3 @@ TEST_CASE_METHOD(CssReloadHelperTest, "parse_imports", "[util][css_reload_helper
REQUIRE(files.empty());
}
}
TEST_CASE("file_watcher", "[util][css_reload_helper]")
{
SECTION("file does not exist")
{
std::atomic<int> count;
std::string f1 = std::tmpnam(nullptr);
waybar::CssReloadHelper helper(f1, [&count](){++count;});
helper.monitorChanges();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
CHECK(count == 0);
helper.stop();
std::remove(f1.c_str());
}
SECTION("file exists")
{
std::atomic<int> count;
std::string f1 = std::tmpnam(nullptr);
std::ofstream(f1) << "body { color: red; }";
waybar::CssReloadHelper helper(f1, [&count](){++count;});
helper.monitorChanges();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
CHECK(count == 0);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::ofstream(f1) << "body { color: blue; }";
std::this_thread::sleep_for(std::chrono::milliseconds(100));
CHECK(count == 1);
helper.stop();
std::remove(f1.c_str());
}
SECTION("multiple files")
{
std::atomic<int> count;
std::string f1 = std::tmpnam(nullptr);
std::string f2 = std::tmpnam(nullptr);
std::ofstream(f1) << ("@import '" + f2 + " ';");
std::ofstream(f2) << "body { color: red; }";
waybar::CssReloadHelper helper(f1, [&count](){++count;});
helper.monitorChanges();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
CHECK(count == 0);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::ofstream(f2) << "body { color: blue; }";
std::this_thread::sleep_for(std::chrono::milliseconds(100));
CHECK(count == 1);
helper.stop();
std::remove(f1.c_str());
std::remove(f2.c_str());
}
}