42 lines
1020 B
C++
42 lines
1020 B
C++
#define TEST_NO_MAIN
|
|
#include "acutest.h"
|
|
#include <string.h>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <thread>
|
|
#include <chrono>
|
|
#include "../include/HotReload.h"
|
|
#include "physfs_test_utils.h"
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
void test_hotreload_directory_watch(void) {
|
|
std::filesystem::path tmpDir = std::filesystem::current_path() / "tmp_watch";
|
|
std::filesystem::create_directories(tmpDir);
|
|
|
|
std::filesystem::path f = tmpDir / "a.as";
|
|
std::ofstream ofs(f);
|
|
ofs << "// test" << std::endl;
|
|
ofs.close();
|
|
|
|
TEST_CHECK(InitPhysFSTest(tmpDir) == true);
|
|
TEST_CHECK(MountPhysFSTest(tmpDir, "tmp_watch") == true);
|
|
|
|
HotReload hr("tmp_watch");
|
|
TEST_CHECK(hr.CheckForChanges() == false);
|
|
|
|
std::this_thread::sleep_for(1s);
|
|
std::ofstream ofs2(f, std::ios::app);
|
|
ofs2 << "// changed" << std::endl;
|
|
ofs2.close();
|
|
|
|
TEST_CHECK(hr.CheckForChanges() == true);
|
|
|
|
ShutdownPhysFSTest();
|
|
|
|
std::filesystem::remove(f);
|
|
std::filesystem::remove(tmpDir);
|
|
}
|
|
|
|
|