From 02f12a721b67484d74d5ddc338b3a7f37a02194e Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 5 Dec 2023 19:50:21 +0100 Subject: [PATCH] test/helpers.cpp: added checks to `ScopeFile` to indicate leftover files from previously aborted testrun --- test/helpers.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/helpers.cpp b/test/helpers.cpp index b4c46a90d2c..e363c1266dd 100644 --- a/test/helpers.cpp +++ b/test/helpers.cpp @@ -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"); @@ -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");