diff --git a/tests/testutils.cpp b/tests/testutils.cpp index e187495..2343d79 100644 --- a/tests/testutils.cpp +++ b/tests/testutils.cpp @@ -1,6 +1,7 @@ #include "./testutils.h" #include "../application/failure.h" +#include "../conversion/stringconversion.h" #include #include @@ -11,6 +12,7 @@ using namespace std; using namespace ApplicationUtilities; +using namespace ConversionUtilities; namespace TestUtilities { @@ -158,6 +160,25 @@ string TestApplication::workingCopyPath(const string &name) const } } + // ensure subdirectory exists + const auto parts = splitString >(name, string("/"), EmptyPartsTreat::Omit); + if(!parts.empty()) { + string currentLevel = m_workingDir; + for(auto i = parts.cbegin(), end = parts.end() - 1; i != end; ++i) { + if(stat((currentLevel += *i).c_str(), ¤tStat) || !S_ISDIR(currentStat.st_mode)) { + + if(mkdir(currentLevel.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { + cerr << "Unable to create working copy for \"" << name << "\": can't create working directory." << endl; + return string(); + } + if(currentLevel.back() != '/') { + currentLevel += '/'; + } + currentLevel += *i; + } + } + } + // copy file try { origFile.open(testFilePath(name), ios_base::in | ios_base::binary);