44#include < cstddef>
55#include < cstdint>
66#include < exception>
7+ #include < filesystem>
78#include < fstream>
89#include < memory>
910#include < stdexcept>
11+ #include < string>
12+ #include < system_error>
1013#include < thread>
14+ #include < utility>
1115#include < vector>
1216
1317#include " runners/include/runners.hpp"
1620
1721using namespace ppc ::task;
1822
23+ class ScopedFile {
24+ public:
25+ explicit ScopedFile (std::string path) : path_(std::move(path)) {}
26+ ~ScopedFile () {
27+ std::error_code ec;
28+ std::filesystem::remove (path_, ec);
29+ }
30+
31+ private:
32+ std::string path_;
33+ };
34+
1935namespace ppc ::test {
2036
2137template <typename InType, typename OutType>
@@ -132,6 +148,7 @@ TEST(TaskTest, GetStringTaskType_InvalidFileThrows) {
132148
133149TEST (TaskTest, GetStringTaskType_UnknownType_WithValidFile) {
134150 std::string path = " settings_valid.json" ;
151+ ScopedFile cleaner (path);
135152 std::ofstream file (path);
136153 file
137154 << R"( {"tasks": {"all": "enabled", "stl": "enabled", "omp": "enabled", "mpi": "enabled", "tbb": "enabled", "seq": "enabled"}})" ;
@@ -141,6 +158,7 @@ TEST(TaskTest, GetStringTaskType_UnknownType_WithValidFile) {
141158
142159TEST (TaskTest, GetStringTaskType_ThrowsOnBadJSON) {
143160 std::string path = " bad_settings.json" ;
161+ ScopedFile cleaner (path);
144162 std::ofstream file (path);
145163 file << " {" ;
146164 file.close ();
@@ -149,6 +167,7 @@ TEST(TaskTest, GetStringTaskType_ThrowsOnBadJSON) {
149167
150168TEST (TaskTest, GetStringTaskType_EachType_WithValidFile) {
151169 std::string path = " settings_valid_all.json" ;
170+ ScopedFile cleaner (path);
152171 std::ofstream file (path);
153172 file
154173 << R"( {"tasks": {"all": "enabled", "stl": "enabled", "omp": "enabled", "mpi": "enabled", "tbb": "enabled", "seq": "enabled"}})" ;
@@ -164,6 +183,7 @@ TEST(TaskTest, GetStringTaskType_EachType_WithValidFile) {
164183
165184TEST (TaskTest, GetStringTaskType_ReturnsUnknown_OnDefault) {
166185 std::string path = " settings_valid_unknown.json" ;
186+ ScopedFile cleaner (path);
167187 std::ofstream file (path);
168188 file << R"( {"tasks": {"all": "enabled"}})" ;
169189 file.close ();
@@ -174,6 +194,7 @@ TEST(TaskTest, GetStringTaskType_ReturnsUnknown_OnDefault) {
174194
175195TEST (TaskTest, GetStringTaskType_ThrowsIfKeyMissing) {
176196 std::string path = " settings_partial.json" ;
197+ ScopedFile cleaner (path);
177198 std::ofstream file (path);
178199 file << R"( {"tasks": {"all": "enabled"}})" ;
179200 file.close ();
0 commit comments