Skip to content

Commit

Permalink
test/helpers.cpp: added checks to ScopeFile to indicate leftover fi…
Browse files Browse the repository at this point in the history
…les from previously aborted testrun
  • Loading branch information
firewave committed Dec 5, 2023
1 parent 60ee00f commit 02f12a7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ ScopedFile::ScopedFile(std::string name, const std::string &content, std::string
, mFullPath(Path::join(mPath, mName))
{
if (!mPath.empty() && mPath != Path::getCurrentPath()) {
if (Path::isDirectory(mPath))
throw std::runtime_error("ScopedFile(" + mFullPath + ") - directory already exists");
#ifdef _WIN32
if (!CreateDirectoryA(mPath.c_str(), nullptr))
throw std::runtime_error("ScopedFile(" + mFullPath + ") - could not create directory");
Expand All @@ -60,6 +62,9 @@ ScopedFile::ScopedFile(std::string name, const std::string &content, std::string
#endif
}

if (Path::isFile(mFullPath))
throw std::runtime_error("ScopedFile(" + mFullPath + ") - file already exists");

std::ofstream of(mFullPath);
if (!of.is_open())
throw std::runtime_error("ScopedFile(" + mFullPath + ") - could not open file");
Expand Down

0 comments on commit 02f12a7

Please sign in to comment.