Use temporary directory for tests output

This commit is contained in:
elsid 2025-03-22 14:36:55 +01:00
parent 87a2f776b7
commit 7112217adc
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
6 changed files with 42 additions and 15 deletions

View file

@ -30,7 +30,7 @@ namespace
TEST(FilesGetHash, shouldClearErrors) TEST(FilesGetHash, shouldClearErrors)
{ {
const auto fileName = temporaryFilePath("fileName"); const auto fileName = outputFilePath("fileName");
std::string content; std::string content;
std::fill_n(std::back_inserter(content), 1, 'a'); std::fill_n(std::back_inserter(content), 1, 'a');
std::istringstream stream(content); std::istringstream stream(content);
@ -41,7 +41,7 @@ namespace
TEST_P(FilesGetHash, shouldReturnHashForStringStream) TEST_P(FilesGetHash, shouldReturnHashForStringStream)
{ {
const auto fileName = temporaryFilePath("fileName"); const auto fileName = outputFilePath("fileName");
std::string content; std::string content;
std::fill_n(std::back_inserter(content), GetParam().mSize, 'a'); std::fill_n(std::back_inserter(content), GetParam().mSize, 'a');
std::istringstream stream(content); std::istringstream stream(content);

View file

@ -2,6 +2,7 @@
#include <components/misc/strings/conversion.hpp> #include <components/misc/strings/conversion.hpp>
#include <components/settings/parser.hpp> #include <components/settings/parser.hpp>
#include <components/settings/values.hpp> #include <components/settings/values.hpp>
#include <components/testing/util.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>
@ -24,5 +25,9 @@ int main(int argc, char** argv)
Settings::StaticValues::init(); Settings::StaticValues::init();
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
const int result = RUN_ALL_TESTS();
if (result == 0)
std::filesystem::remove_all(TestingOpenMW::outputDir());
return result;
} }

View file

@ -16,7 +16,7 @@ namespace
ShaderManager mManager; ShaderManager mManager;
ShaderManager::DefineMap mDefines; ShaderManager::DefineMap mDefines;
ShaderManagerTest() { mManager.setShaderPath("tests_output"); } ShaderManagerTest() { mManager.setShaderPath(TestingOpenMW::outputDir()); }
template <class F> template <class F>
void withShaderFile(const std::string& content, F&& f) void withShaderFile(const std::string& content, F&& f)

View file

@ -1,4 +1,5 @@
#include <components/debug/debugging.hpp> #include <components/debug/debugging.hpp>
#include <components/testing/util.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>
@ -7,5 +8,9 @@ int main(int argc, char* argv[])
Log::sMinDebugLevel = Debug::getDebugLevel(); Log::sMinDebugLevel = Debug::getDebugLevel();
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
const int result = RUN_ALL_TESTS();
if (result == 0)
std::filesystem::remove_all(TestingOpenMW::outputDir());
return result;
} }

View file

@ -2,6 +2,7 @@
#include <components/misc/strings/conversion.hpp> #include <components/misc/strings/conversion.hpp>
#include <components/settings/parser.hpp> #include <components/settings/parser.hpp>
#include <components/settings/values.hpp> #include <components/settings/values.hpp>
#include <components/testing/util.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>
@ -24,5 +25,9 @@ int main(int argc, char* argv[])
Settings::StaticValues::init(); Settings::StaticValues::init();
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
const int result = RUN_ALL_TESTS();
if (result == 0)
std::filesystem::remove_all(TestingOpenMW::outputDir());
return result;
} }

View file

@ -1,6 +1,7 @@
#ifndef OPENMW_COMPONENTS_TESTING_UTIL_H #ifndef OPENMW_COMPONENTS_TESTING_UTIL_H
#define OPENMW_COMPONENTS_TESTING_UTIL_H #define OPENMW_COMPONENTS_TESTING_UTIL_H
#include <chrono>
#include <filesystem> #include <filesystem>
#include <initializer_list> #include <initializer_list>
#include <memory> #include <memory>
@ -14,26 +15,37 @@
namespace TestingOpenMW namespace TestingOpenMW
{ {
inline std::filesystem::path outputFilePath(const std::string name) inline std::filesystem::path outputDir()
{ {
std::filesystem::path dir("tests_output"); static const std::string run
std::filesystem::create_directory(dir); = std::to_string(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
std::filesystem::path dir = std::filesystem::temp_directory_path() / "openmw" / "tests" / run;
std::filesystem::create_directories(dir);
return dir;
}
inline std::filesystem::path outputFilePath(std::string_view name)
{
std::filesystem::path dir = outputDir();
return dir / Misc::StringUtils::stringToU8String(name); return dir / Misc::StringUtils::stringToU8String(name);
} }
inline std::filesystem::path outputDirPath(const std::filesystem::path& subpath)
{
std::filesystem::path path = outputDir();
path /= subpath;
std::filesystem::create_directories(path);
return path;
}
inline std::filesystem::path outputFilePathWithSubDir(const std::filesystem::path& subpath) inline std::filesystem::path outputFilePathWithSubDir(const std::filesystem::path& subpath)
{ {
std::filesystem::path path("tests_output"); std::filesystem::path path = outputDir();
path /= subpath; path /= subpath;
std::filesystem::create_directories(path.parent_path()); std::filesystem::create_directories(path.parent_path());
return path; return path;
} }
inline std::filesystem::path temporaryFilePath(const std::string name)
{
return std::filesystem::temp_directory_path() / name;
}
class VFSTestFile : public VFS::File class VFSTestFile : public VFS::File
{ {
public: public: