From 709d186b8d40512dcacff0fc78566c5bb5182fa8 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Tue, 24 May 2022 22:31:29 +0200 Subject: [PATCH] Put tests output files to a separate dir --- apps/openmw_test_suite/CMakeLists.txt | 2 ++ apps/openmw_test_suite/files/hash.cpp | 8 +++-- apps/openmw_test_suite/fx/technique.cpp | 14 ++++---- .../lua/test_configuration.cpp | 2 +- apps/openmw_test_suite/lua/test_l10n.cpp | 23 ++++++++----- apps/openmw_test_suite/lua/test_lua.cpp | 10 +++--- .../lua/test_scriptscontainer.cpp | 21 ++++++------ .../lua/test_serialization.cpp | 2 +- .../lua/test_utilpackage.cpp | 8 ++++- .../misc/test_resourcehelpers.cpp | 10 +++--- apps/openmw_test_suite/mwworld/test_store.cpp | 20 ++++-------- apps/openmw_test_suite/settings/parser.cpp | 8 +++-- .../settings/shadermanager.cpp | 6 +++- .../shader/shadermanager.cpp | 8 +++-- .../{lua => }/testing_util.hpp | 32 +++++++++++-------- 15 files changed, 100 insertions(+), 74 deletions(-) rename apps/openmw_test_suite/{lua => }/testing_util.hpp (61%) diff --git a/apps/openmw_test_suite/CMakeLists.txt b/apps/openmw_test_suite/CMakeLists.txt index b17e49207d..2695b64c05 100644 --- a/apps/openmw_test_suite/CMakeLists.txt +++ b/apps/openmw_test_suite/CMakeLists.txt @@ -6,6 +6,8 @@ if (GTEST_FOUND AND GMOCK_FOUND) include_directories(SYSTEM ${GMOCK_INCLUDE_DIRS}) file(GLOB UNITTEST_SRC_FILES + testing_util.hpp + ../openmw/mwworld/store.cpp ../openmw/mwworld/esmstore.cpp mwworld/test_store.cpp diff --git a/apps/openmw_test_suite/files/hash.cpp b/apps/openmw_test_suite/files/hash.cpp index 645258f60e..f8303ac1f3 100644 --- a/apps/openmw_test_suite/files/hash.cpp +++ b/apps/openmw_test_suite/files/hash.cpp @@ -9,9 +9,12 @@ #include #include +#include "../testing_util.hpp" + namespace { using namespace testing; + using namespace TestingOpenMW; using namespace Files; struct Params @@ -24,7 +27,7 @@ namespace TEST(FilesGetHash, shouldClearErrors) { - const std::string fileName = "fileName"; + const std::string fileName = temporaryFilePath("fileName"); std::string content; std::fill_n(std::back_inserter(content), 1, 'a'); std::istringstream stream(content); @@ -34,7 +37,7 @@ namespace TEST_P(FilesGetHash, shouldReturnHashForStringStream) { - const std::string fileName = "fileName"; + const std::string fileName = temporaryFilePath("fileName"); std::string content; std::fill_n(std::back_inserter(content), GetParam().mSize, 'a'); std::istringstream stream(content); @@ -47,6 +50,7 @@ namespace std::replace(fileName.begin(), fileName.end(), '/', '_'); std::string content; std::fill_n(std::back_inserter(content), GetParam().mSize, 'a'); + fileName = outputFilePath(fileName); std::fstream(fileName, std::ios_base::out | std::ios_base::binary) .write(content.data(), static_cast(content.size())); const auto stream = Files::openConstrainedFileStream(fileName, 0, content.size()); diff --git a/apps/openmw_test_suite/fx/technique.cpp b/apps/openmw_test_suite/fx/technique.cpp index 9a382ad8ea..d4b5bb0f8c 100644 --- a/apps/openmw_test_suite/fx/technique.cpp +++ b/apps/openmw_test_suite/fx/technique.cpp @@ -6,12 +6,12 @@ #include #include -#include "../lua/testing_util.hpp" +#include "../testing_util.hpp" namespace { -TestFile technique_properties(R"( +TestingOpenMW::VFSTestFile technique_properties(R"( fragment main {} vertex main {} technique { @@ -27,7 +27,7 @@ TestFile technique_properties(R"( } )"); -TestFile rendertarget_properties{R"( +TestingOpenMW::VFSTestFile rendertarget_properties{R"( render_target rendertarget { width_ratio = 0.5; height_ratio = 0.5; @@ -54,7 +54,7 @@ TestFile rendertarget_properties{R"( )"}; -TestFile uniform_properties{R"( +TestingOpenMW::VFSTestFile uniform_properties{R"( uniform_vec4 uVec4 { default = vec4(0,0,0,0); min = vec4(0,1,0,0); @@ -69,13 +69,13 @@ TestFile uniform_properties{R"( )"}; -TestFile missing_sampler_source{R"( +TestingOpenMW::VFSTestFile missing_sampler_source{R"( sampler_1d mysampler1d { } fragment main { } technique { passes = main; } )"}; -TestFile repeated_shared_block{R"( +TestingOpenMW::VFSTestFile repeated_shared_block{R"( shared { float myfloat = 1.0; } @@ -95,7 +95,7 @@ TestFile repeated_shared_block{R"( std::unique_ptr mTechnique; TechniqueTest() - : mVFS(createTestVFS({ + : mVFS(TestingOpenMW::createTestVFS({ {"shaders/technique_properties.omwfx", &technique_properties}, {"shaders/rendertarget_properties.omwfx", &rendertarget_properties}, {"shaders/uniform_properties.omwfx", &uniform_properties}, diff --git a/apps/openmw_test_suite/lua/test_configuration.cpp b/apps/openmw_test_suite/lua/test_configuration.cpp index 054ea8cbda..4869d42284 100644 --- a/apps/openmw_test_suite/lua/test_configuration.cpp +++ b/apps/openmw_test_suite/lua/test_configuration.cpp @@ -3,7 +3,7 @@ #include -#include "testing_util.hpp" +#include "../testing_util.hpp" namespace { diff --git a/apps/openmw_test_suite/lua/test_l10n.cpp b/apps/openmw_test_suite/lua/test_l10n.cpp index c989d56e72..6204a8022a 100644 --- a/apps/openmw_test_suite/lua/test_l10n.cpp +++ b/apps/openmw_test_suite/lua/test_l10n.cpp @@ -6,17 +6,24 @@ #include #include -#include "testing_util.hpp" +#include "../testing_util.hpp" namespace { using namespace testing; + using namespace TestingOpenMW; - TestFile invalidScript("not a script"); - TestFile incorrectScript("return { incorrectSection = {}, engineHandlers = { incorrectHandler = function() end } }"); - TestFile emptyScript(""); + template + T get(sol::state& lua, const std::string& luaCode) + { + return lua.safe_script("return " + luaCode).get(); + } + + VFSTestFile invalidScript("not a script"); + VFSTestFile incorrectScript("return { incorrectSection = {}, engineHandlers = { incorrectHandler = function() end } }"); + VFSTestFile emptyScript(""); - TestFile test1En(R"X( + VFSTestFile test1En(R"X( good_morning: "Good morning." you_have_arrows: |- {count, plural, @@ -38,7 +45,7 @@ numbers: "{int} and {double, number, integer} are integers, but {double} is a do rounding: "{value, number, :: .00}" )X"); - TestFile test1De(R"X( + VFSTestFile test1De(R"X( good_morning: "Guten Morgen." you_have_arrows: |- {count, plural, @@ -48,11 +55,11 @@ you_have_arrows: |- "Hello {name}!": "Hallo {name}!" )X"); - TestFile test1EnUS(R"X( + VFSTestFile test1EnUS(R"X( currency: "You have {money, number, currency}" )X"); -TestFile test2En(R"X( +VFSTestFile test2En(R"X( good_morning: "Morning!" you_have_arrows: "Arrows count: {count}" )X"); diff --git a/apps/openmw_test_suite/lua/test_lua.cpp b/apps/openmw_test_suite/lua/test_lua.cpp index 539390f2af..566fefa726 100644 --- a/apps/openmw_test_suite/lua/test_lua.cpp +++ b/apps/openmw_test_suite/lua/test_lua.cpp @@ -3,13 +3,13 @@ #include -#include "testing_util.hpp" +#include "../testing_util.hpp" namespace { using namespace testing; - TestFile counterFile(R"X( + TestingOpenMW::VFSTestFile counterFile(R"X( x = 42 return { get = function() return x end, @@ -17,9 +17,9 @@ return { } )X"); - TestFile invalidScriptFile("Invalid script"); + TestingOpenMW::VFSTestFile invalidScriptFile("Invalid script"); - TestFile testsFile(R"X( + TestingOpenMW::VFSTestFile testsFile(R"X( return { -- should work sin = function(x) return math.sin(x) end, @@ -53,7 +53,7 @@ return { struct LuaStateTest : Test { - std::unique_ptr mVFS = createTestVFS({ + std::unique_ptr mVFS = TestingOpenMW::createTestVFS({ {"aaa/counter.lua", &counterFile}, {"bbb/tests.lua", &testsFile}, {"invalid.lua", &invalidScriptFile} diff --git a/apps/openmw_test_suite/lua/test_scriptscontainer.cpp b/apps/openmw_test_suite/lua/test_scriptscontainer.cpp index 900888929d..18aeffbbf2 100644 --- a/apps/openmw_test_suite/lua/test_scriptscontainer.cpp +++ b/apps/openmw_test_suite/lua/test_scriptscontainer.cpp @@ -6,17 +6,18 @@ #include #include -#include "testing_util.hpp" +#include "../testing_util.hpp" namespace { using namespace testing; + using namespace TestingOpenMW; - TestFile invalidScript("not a script"); - TestFile incorrectScript("return { incorrectSection = {}, engineHandlers = { incorrectHandler = function() end } }"); - TestFile emptyScript(""); + VFSTestFile invalidScript("not a script"); + VFSTestFile incorrectScript("return { incorrectSection = {}, engineHandlers = { incorrectHandler = function() end } }"); + VFSTestFile emptyScript(""); - TestFile testScript(R"X( + VFSTestFile testScript(R"X( return { engineHandlers = { onUpdate = function(dt) print(' update ' .. tostring(dt)) end, @@ -30,7 +31,7 @@ return { } )X"); - TestFile stopEventScript(R"X( + VFSTestFile stopEventScript(R"X( return { eventHandlers = { Event1 = function(eventData) @@ -41,7 +42,7 @@ return { } )X"); - TestFile loadSaveScript(R"X( + VFSTestFile loadSaveScript(R"X( x = 0 y = 0 return { @@ -67,7 +68,7 @@ return { } )X"); - TestFile interfaceScript(R"X( + VFSTestFile interfaceScript(R"X( return { interfaceName = "TestInterface", interface = { @@ -77,7 +78,7 @@ return { } )X"); - TestFile overrideInterfaceScript(R"X( + VFSTestFile overrideInterfaceScript(R"X( local old = nil local interface = { fn = function(x) @@ -101,7 +102,7 @@ return { } )X"); - TestFile useInterfaceScript(R"X( + VFSTestFile useInterfaceScript(R"X( local interfaces = require('openmw.interfaces') return { engineHandlers = { diff --git a/apps/openmw_test_suite/lua/test_serialization.cpp b/apps/openmw_test_suite/lua/test_serialization.cpp index 5a6d5b7e51..610d5b43c1 100644 --- a/apps/openmw_test_suite/lua/test_serialization.cpp +++ b/apps/openmw_test_suite/lua/test_serialization.cpp @@ -13,7 +13,7 @@ #include #include -#include "testing_util.hpp" +#include "../testing_util.hpp" namespace { diff --git a/apps/openmw_test_suite/lua/test_utilpackage.cpp b/apps/openmw_test_suite/lua/test_utilpackage.cpp index 5e27b36916..b7aa534c1d 100644 --- a/apps/openmw_test_suite/lua/test_utilpackage.cpp +++ b/apps/openmw_test_suite/lua/test_utilpackage.cpp @@ -4,12 +4,18 @@ #include #include -#include "testing_util.hpp" +#include "../testing_util.hpp" namespace { using namespace testing; + template + T get(sol::state& lua, const std::string& luaCode) + { + return lua.safe_script("return " + luaCode).get(); + } + std::string getAsString(sol::state& lua, std::string luaCode) { return LuaUtil::toString(lua.safe_script("return " + luaCode)); diff --git a/apps/openmw_test_suite/misc/test_resourcehelpers.cpp b/apps/openmw_test_suite/misc/test_resourcehelpers.cpp index ee062c6da8..c4130b9cca 100644 --- a/apps/openmw_test_suite/misc/test_resourcehelpers.cpp +++ b/apps/openmw_test_suite/misc/test_resourcehelpers.cpp @@ -1,13 +1,13 @@ #include #include "components/misc/resourcehelpers.hpp" -#include "../lua/testing_util.hpp" +#include "../testing_util.hpp" namespace { using namespace Misc::ResourceHelpers; TEST(CorrectSoundPath, wav_files_not_overridden_with_mp3_in_vfs_are_not_corrected) { - std::unique_ptr mVFS = createTestVFS({ + std::unique_ptr mVFS = TestingOpenMW::createTestVFS({ {"sound/bar.wav", nullptr} }); EXPECT_EQ(correctSoundPath("sound/bar.wav", mVFS.get()), "sound/bar.wav"); @@ -15,7 +15,7 @@ namespace TEST(CorrectSoundPath, wav_files_overridden_with_mp3_in_vfs_are_corrected) { - std::unique_ptr mVFS = createTestVFS({ + std::unique_ptr mVFS = TestingOpenMW::createTestVFS({ {"sound/foo.mp3", nullptr} }); EXPECT_EQ(correctSoundPath("sound/foo.wav", mVFS.get()), "sound/foo.mp3"); @@ -23,14 +23,14 @@ namespace TEST(CorrectSoundPath, corrected_path_does_not_check_existence_in_vfs) { - std::unique_ptr mVFS = createTestVFS({ + std::unique_ptr mVFS = TestingOpenMW::createTestVFS({ }); EXPECT_EQ(correctSoundPath("sound/foo.wav", mVFS.get()), "sound/foo.mp3"); } TEST(CorrectSoundPath, correct_path_normalize_paths) { - std::unique_ptr mVFS = createTestVFS({ + std::unique_ptr mVFS = TestingOpenMW::createTestVFS({ }); EXPECT_EQ(correctSoundPath("sound\\foo.wav", mVFS.get()), "sound/foo.mp3"); EXPECT_EQ(correctSoundPath("SOUND\\foo.WAV", mVFS.get()), "SOUND/foo.mp3"); diff --git a/apps/openmw_test_suite/mwworld/test_store.cpp b/apps/openmw_test_suite/mwworld/test_store.cpp index c656064a96..7df5940596 100644 --- a/apps/openmw_test_suite/mwworld/test_store.cpp +++ b/apps/openmw_test_suite/mwworld/test_store.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include @@ -12,6 +11,8 @@ #include "apps/openmw/mwworld/esmstore.hpp" #include "apps/openmw/mwmechanics/spelllist.hpp" +#include "../testing_util.hpp" + namespace MWMechanics { SpellList::SpellList(const std::string& id, int type) : mId(id), mType(type) {} @@ -62,8 +63,6 @@ struct ContentFileTest : public ::testing::Test ("data-local", boost::program_options::value()->default_value(Files::MaybeQuotedPathContainer::value_type(), "")); Files::ConfigurationManager::addCommonOptions(desc); - boost::program_options::notify(variables); - mConfigurationManager.readConfiguration(variables, desc, true); Files::PathContainer dataDirs, dataLocal; @@ -73,10 +72,7 @@ struct ContentFileTest : public ::testing::Test Files::PathContainer::value_type local(variables["data-local"].as()); if (!local.empty()) - { - boost::filesystem::create_directories(local); dataLocal.push_back(local); - } mConfigurationManager.filterOutNonExistingPaths(dataDirs); mConfigurationManager.filterOutNonExistingPaths(dataLocal); @@ -109,10 +105,8 @@ TEST_F(ContentFileTest, dialogue_merging_test) return; } - const std::string file = "test_dialogue_merging.txt"; - - std::ofstream stream; - stream.open(file); + const std::string file = TestingOpenMW::outputFilePath("test_dialogue_merging.txt"); + std::ofstream stream(file); const MWWorld::Store& dialStore = mEsmStore.get(); for (const auto & dial : dialStore) @@ -191,10 +185,8 @@ TEST_F(ContentFileTest, content_diagnostics_test) return; } - const std::string file = "test_content_diagnostics.txt"; - - std::ofstream stream; - stream.open(file); + const std::string file = TestingOpenMW::outputFilePath("test_content_diagnostics.txt"); + std::ofstream stream(file); RUN_TEST_FOR_TYPES(printRecords, mEsmStore, stream); diff --git a/apps/openmw_test_suite/settings/parser.cpp b/apps/openmw_test_suite/settings/parser.cpp index abaa700730..7e250b43aa 100644 --- a/apps/openmw_test_suite/settings/parser.cpp +++ b/apps/openmw_test_suite/settings/parser.cpp @@ -4,6 +4,8 @@ #include +#include "../testing_util.hpp" + namespace { using namespace testing; @@ -17,11 +19,11 @@ namespace template void withSettingsFile( const std::string& content, F&& f) { - const auto path = std::string(UnitTest::GetInstance()->current_test_info()->name()) + ".cfg"; + std::string path = TestingOpenMW::outputFilePath( + std::string(UnitTest::GetInstance()->current_test_info()->name()) + ".cfg"); { - std::ofstream stream; - stream.open(path); + std::ofstream stream(path); stream << content; stream.close(); } diff --git a/apps/openmw_test_suite/settings/shadermanager.cpp b/apps/openmw_test_suite/settings/shadermanager.cpp index 7f6e73c4c1..e4f40aaa03 100644 --- a/apps/openmw_test_suite/settings/shadermanager.cpp +++ b/apps/openmw_test_suite/settings/shadermanager.cpp @@ -1,9 +1,12 @@ #include +#include #include #include +#include "../testing_util.hpp" + namespace { using namespace testing; @@ -14,7 +17,8 @@ namespace template void withSettingsFile( const std::string& content, F&& f) { - const auto path = std::string(UnitTest::GetInstance()->current_test_info()->name()) + ".yaml"; + std::string path = TestingOpenMW::outputFilePath( + std::string(UnitTest::GetInstance()->current_test_info()->name()) + ".yaml"); { std::ofstream stream; diff --git a/apps/openmw_test_suite/shader/shadermanager.cpp b/apps/openmw_test_suite/shader/shadermanager.cpp index 1b0cd7c741..58ca3b6f3f 100644 --- a/apps/openmw_test_suite/shader/shadermanager.cpp +++ b/apps/openmw_test_suite/shader/shadermanager.cpp @@ -4,6 +4,8 @@ #include +#include "../testing_util.hpp" + namespace { using namespace testing; @@ -28,11 +30,11 @@ namespace template void withShaderFile(const std::string& suffix, const std::string& content, F&& f) { - const auto path = UnitTest::GetInstance()->current_test_info()->name() + suffix + ".glsl"; + std::string path = TestingOpenMW::outputFilePath( + std::string(UnitTest::GetInstance()->current_test_info()->name()) + suffix + ".glsl"); { - std::ofstream stream; - stream.open(path); + std::ofstream stream(path); stream << content; stream.close(); } diff --git a/apps/openmw_test_suite/lua/testing_util.hpp b/apps/openmw_test_suite/testing_util.hpp similarity index 61% rename from apps/openmw_test_suite/lua/testing_util.hpp rename to apps/openmw_test_suite/testing_util.hpp index 217c8ae5d5..e583552a21 100644 --- a/apps/openmw_test_suite/lua/testing_util.hpp +++ b/apps/openmw_test_suite/testing_util.hpp @@ -1,25 +1,31 @@ -#ifndef LUA_TESTING_UTIL_H -#define LUA_TESTING_UTIL_H +#ifndef TESTING_UTIL_H +#define TESTING_UTIL_H +#include #include -#include #include #include -namespace +namespace TestingOpenMW { - template - T get(sol::state& lua, const std::string& luaCode) + inline std::string outputFilePath(const std::string name) { - return lua.safe_script("return " + luaCode).get(); + std::filesystem::path dir("tests_output"); + std::filesystem::create_directory(dir); + return (dir / name).string(); } - class TestFile : public VFS::File + inline std::string temporaryFilePath(const std::string name) + { + return (std::filesystem::temp_directory_path() / name).string(); + } + + class VFSTestFile : public VFS::File { public: - explicit TestFile(std::string content) : mContent(std::move(content)) {} + explicit VFSTestFile(std::string content) : mContent(std::move(content)) {} Files::IStreamPtr open() override { @@ -35,11 +41,11 @@ namespace const std::string mContent; }; - struct TestData : public VFS::Archive + struct VFSTestData : public VFS::Archive { std::map mFiles; - TestData(std::map files) : mFiles(std::move(files)) {} + VFSTestData(std::map files) : mFiles(std::move(files)) {} void listResources(std::map& out, char (*normalize_function) (char)) override { @@ -58,7 +64,7 @@ namespace inline std::unique_ptr createTestVFS(std::map files) { auto vfs = std::make_unique(true); - vfs->addArchive(new TestData(std::move(files))); + vfs->addArchive(new VFSTestData(std::move(files))); vfs->buildIndex(); return vfs; } @@ -68,4 +74,4 @@ namespace } -#endif // LUA_TESTING_UTIL_H +#endif // TESTING_UTIL_H