@@ -17,22 +17,48 @@ uint64_t TestFile::nextId = 0;
17
17
TestFile::TestFile (const fs::path& path, const fs::path& tmpPath)
18
18
: testPath(path) {
19
19
20
- setInsPath (tmpPath / std::to_string (nextId) / " test.ins" );
21
- setOutPath (tmpPath / std::to_string (nextId) / " test.ins" );
22
-
23
- std::cout << " Use tmp path: " << tmpPath << std::endl;
24
- std::cout << " Out path: " << outPath << std::endl;
25
- std::cout << " In path: " << insPath << std::endl;
20
+ fs::path testDir = tmpPath / std::to_string (nextId);
21
+ setInsPath (testDir / " test.ins" );
22
+ setOutPath (testDir / " test.out" );
26
23
24
+ try {
25
+ // Create tmp directory if it doesn't exist
26
+ std::cout << " Attempting to create directory: " << testDir << std::endl;
27
+ if (!fs::exists (testDir)) {
28
+ if (!fs::create_directories (testDir)) {
29
+ throw std::runtime_error (" Failed to create directory: " + testDir.string ());
30
+ }
31
+ }
32
+ // Create the temporary input and ouput files
33
+ std::ofstream createInsFile (insPath);
34
+ std::ofstream createOutFile (outPath);
35
+ if (!createInsFile) {
36
+ throw std::runtime_error (" Failed to create input file: " + insPath.string ());
37
+ }
38
+ if (!createOutFile) {
39
+ throw std::runtime_error (" Failed to create output file: " + outPath.string ());
40
+ }
41
+ createInsFile.close ();
42
+ createOutFile.close ();
43
+
44
+ } catch (const fs::filesystem_error& e) {
45
+ throw std::runtime_error (" Filesystem error: " + std::string (e.what ()));
46
+ } catch (const std::exception& e) {
47
+ throw std::runtime_error (" Error in TestFile constructor: " + std::string (e.what ()));
48
+ }
27
49
nextId++;
28
50
}
29
51
30
52
TestFile::~TestFile () {
31
53
if (fs::exists (insPath)) {
54
+ // Remove temporary input stream file
32
55
fs::remove (insPath);
33
56
}
34
57
if (fs::exists (outPath)) {
58
+ // Remove the tenmporary testfile directory and the expected out
59
+ fs::path testfileDir = outPath.parent_path ();
35
60
fs::remove (outPath);
61
+ fs::remove (testfileDir);
36
62
}
37
63
}
38
64
0 commit comments