MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/system/file_system.cpp:34–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32#include "fl/stl/int.h"
33
34FL_TEST_FILE(FL_FILEPATH) {
35#endif
36
37
38// RAII helper to ensure cleanup happens even on test failure
39class TestDirGuard {
40 fl::string mDir;
41 fl::vector<fl::string> mFiles;
42 fl::vector<fl::string> mSubdirs;
43public:
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
64private:
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
72FL_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

Callers

nothing calls this directly

Calls 15

createTextFileFunction · 0.85
setTestFileSystemRootFunction · 0.85
getTestFileSystemRootFunction · 0.85
createDirectoryFunction · 0.85
addFileMethod · 0.80
beginSdMethod · 0.80
addSubdirMethod · 0.80
readTextMethod · 0.80
stringClass · 0.50
appendMethod · 0.45
c_strMethod · 0.45
openReadMethod · 0.45

Tested by

no test coverage detected