diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-09 17:35:32 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-09 17:35:32 +0100 |
| commit | d5f78a4c2e7b626a492643efd62ddeb394276722 (patch) | |
| tree | cdf38c3d64f6bf417975ce396572fc425d6f8910 /src/tests/test_file_watcher.cc | |
| parent | 802e97ee695de1bc8657c5cbca653bb2f13b90a8 (diff) | |
feat: Add debug-only file change detection for rapid iteration
Enables --hot-reload flag to watch config files and notify on changes.
Detects modifications to assets/sequences/music for rebuild workflow.
Completely stripped from release builds (0 bytes overhead).
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/tests/test_file_watcher.cc')
| -rw-r--r-- | src/tests/test_file_watcher.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/tests/test_file_watcher.cc b/src/tests/test_file_watcher.cc new file mode 100644 index 0000000..ac13afd --- /dev/null +++ b/src/tests/test_file_watcher.cc @@ -0,0 +1,63 @@ +// test_file_watcher.cc - Unit tests for file change detection + +#include "util/file_watcher.h" +#include <cstdio> +#include <fstream> +#include <unistd.h> + +#if !defined(STRIP_ALL) + +int main() { + // Create a temporary test file + const char* test_file = "/tmp/test_watcher_file.txt"; + { + std::ofstream f(test_file); + f << "initial content\n"; + } + + FileWatcher watcher; + watcher.add_file(test_file); + + // Initial check - no changes yet + bool changed = watcher.check_changes(); + if (changed) { + fprintf(stderr, "FAIL: Expected no changes on first check\n"); + return 1; + } + + // Sleep to ensure mtime changes (some filesystems have 1s granularity) + sleep(1); + + // Modify the file + { + std::ofstream f(test_file, std::ios::app); + f << "modified\n"; + } + + // Check for changes + changed = watcher.check_changes(); + if (!changed) { + fprintf(stderr, "FAIL: Expected changes after file modification\n"); + return 1; + } + + // Reset and check again - should be no changes + watcher.reset(); + changed = watcher.check_changes(); + if (changed) { + fprintf(stderr, "FAIL: Expected no changes after reset\n"); + return 1; + } + + printf("PASS: FileWatcher tests\n"); + return 0; +} + +#else + +int main() { + printf("SKIP: FileWatcher tests (STRIP_ALL build)\n"); + return 0; +} + +#endif |
