diff --git a/modules/task/tests/task_tests.cpp b/modules/task/tests/task_tests.cpp index daedf15a0..0dfaafd6e 100644 --- a/modules/task/tests/task_tests.cpp +++ b/modules/task/tests/task_tests.cpp @@ -4,10 +4,14 @@ #include #include #include +#include #include #include #include +#include +#include #include +#include #include #include "runners/include/runners.hpp" @@ -16,6 +20,18 @@ using namespace ppc::task; +class ScopedFile { + public: + explicit ScopedFile(std::string path) : path_(std::move(path)) {} + ~ScopedFile() { + std::error_code ec; + std::filesystem::remove(path_, ec); + } + + private: + std::string path_; +}; + namespace ppc::test { template @@ -132,6 +148,7 @@ TEST(TaskTest, GetStringTaskType_InvalidFileThrows) { TEST(TaskTest, GetStringTaskType_UnknownType_WithValidFile) { std::string path = "settings_valid.json"; + ScopedFile cleaner(path); std::ofstream file(path); file << R"({"tasks": {"all": "enabled", "stl": "enabled", "omp": "enabled", "mpi": "enabled", "tbb": "enabled", "seq": "enabled"}})"; @@ -141,6 +158,7 @@ TEST(TaskTest, GetStringTaskType_UnknownType_WithValidFile) { TEST(TaskTest, GetStringTaskType_ThrowsOnBadJSON) { std::string path = "bad_settings.json"; + ScopedFile cleaner(path); std::ofstream file(path); file << "{"; file.close(); @@ -149,6 +167,7 @@ TEST(TaskTest, GetStringTaskType_ThrowsOnBadJSON) { TEST(TaskTest, GetStringTaskType_EachType_WithValidFile) { std::string path = "settings_valid_all.json"; + ScopedFile cleaner(path); std::ofstream file(path); file << R"({"tasks": {"all": "enabled", "stl": "enabled", "omp": "enabled", "mpi": "enabled", "tbb": "enabled", "seq": "enabled"}})"; @@ -164,6 +183,7 @@ TEST(TaskTest, GetStringTaskType_EachType_WithValidFile) { TEST(TaskTest, GetStringTaskType_ReturnsUnknown_OnDefault) { std::string path = "settings_valid_unknown.json"; + ScopedFile cleaner(path); std::ofstream file(path); file << R"({"tasks": {"all": "enabled"}})"; file.close(); @@ -174,6 +194,7 @@ TEST(TaskTest, GetStringTaskType_ReturnsUnknown_OnDefault) { TEST(TaskTest, GetStringTaskType_ThrowsIfKeyMissing) { std::string path = "settings_partial.json"; + ScopedFile cleaner(path); std::ofstream file(path); file << R"({"tasks": {"all": "enabled"}})"; file.close();