2022-05-31 21:26:41 +00:00
|
|
|
#include "IOTestHelpers.h"
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
2022-10-19 13:41:53 +00:00
|
|
|
namespace Status::Testing
|
|
|
|
{
|
2022-05-31 21:26:41 +00:00
|
|
|
|
|
|
|
fs::path createTestFolder(const std::string& testName)
|
|
|
|
{
|
|
|
|
auto t = std::time(nullptr);
|
|
|
|
auto tm = *std::localtime(&t);
|
|
|
|
std::ostringstream timeOss;
|
|
|
|
timeOss << std::put_time(&tm, "%d-%m-%Y_%H-%M-%S");
|
2022-10-19 13:41:53 +00:00
|
|
|
return fs::path(testing::TempDir()) / "StatusTests" / (testName + "-" + timeOss.str());
|
2022-05-31 21:26:41 +00:00
|
|
|
}
|
|
|
|
|
2022-10-19 13:41:53 +00:00
|
|
|
AutoCleanTempTestDir::AutoCleanTempTestDir(const std::string& testName, bool createDir)
|
2022-05-31 21:26:41 +00:00
|
|
|
: m_testFolder(createTestFolder(testName))
|
|
|
|
{
|
2022-10-19 13:41:53 +00:00
|
|
|
if(createDir) fs::create_directories(m_testFolder);
|
2022-05-31 21:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AutoCleanTempTestDir::~AutoCleanTempTestDir()
|
|
|
|
{
|
2022-07-04 21:14:13 +00:00
|
|
|
// TODO: Consider making this concurrent safe and cleanup the root folder as well if empty
|
|
|
|
fs::remove_all(m_testFolder);
|
2022-05-31 21:26:41 +00:00
|
|
|
}
|
|
|
|
|
2022-07-04 21:14:13 +00:00
|
|
|
const std::filesystem::path& AutoCleanTempTestDir::tempFolder()
|
2022-05-31 21:26:41 +00:00
|
|
|
{
|
|
|
|
return m_testFolder;
|
|
|
|
}
|
|
|
|
|
2022-10-19 13:41:53 +00:00
|
|
|
} // namespace Status::Testing
|