| 32 | #include "fl/stl/int.h" |
| 33 | |
| 34 | FL_TEST_FILE(FL_FILEPATH) { |
| 35 | #endif |
| 36 | |
| 37 | |
| 38 | // RAII helper to ensure cleanup happens even on test failure |
| 39 | class TestDirGuard { |
| 40 | fl::string mDir; |
| 41 | fl::vector<fl::string> mFiles; |
| 42 | fl::vector<fl::string> mSubdirs; |
| 43 | public: |
| 44 | explicit TestDirGuard(const fl::string& dir) : mDir(dir) { |
| 45 | // Clean up any leftover state from previous failed runs |
| 46 | cleanup(); |
| 47 | // Create fresh directory |
| 48 | fl::StubFileSystem::createDirectory(mDir.c_str()); |
| 49 | } |
| 50 | |
| 51 | ~TestDirGuard() { |
| 52 | cleanup(); |
| 53 | fl::setTestFileSystemRoot(""); // Clear global state |
| 54 | } |
| 55 | |
| 56 | void addFile(const fl::string& path) { |
| 57 | mFiles.push_back(path); |
| 58 | } |
| 59 | |
| 60 | void addSubdir(const fl::string& path) { |
| 61 | mSubdirs.push_back(path); |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | void cleanup() { |
| 66 | // Force remove entire directory tree to handle any leftover state |
| 67 | // This ensures cleanup even if subdirectories/files exist from failed runs |
| 68 | fl::StubFileSystem::forceRemoveDirectory(mDir.c_str()); |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | FL_TEST_CASE("FileSystem test with real hard drive") { |
| 73 | // Create a temporary test directory and file |
| 74 | fl::string test_dir = "test_filesystem_temp"; |
| 75 | fl::string test_file = "test_data.txt"; |
| 76 | fl::string test_content = "Hello, FastLED filesystem test!"; |
| 77 | |
| 78 | // RAII guard ensures cleanup even on test failure |
| 79 | TestDirGuard guard(test_dir); |
| 80 | |
| 81 | // Create test file |
| 82 | fl::string full_path = test_dir; |
| 83 | full_path.append("/"); |
| 84 | full_path.append(test_file); |
| 85 | guard.addFile(full_path); |
| 86 | FL_REQUIRE(fl::StubFileSystem::createTextFile(full_path.c_str(), test_content.c_str())); |
| 87 | |
| 88 | // Set the test filesystem root |
| 89 | fl::setTestFileSystemRoot(test_dir.c_str()); |
| 90 | |
| 91 | // Verify the root was set |
nothing calls this directly
no test coverage detected