From 5f04decaccb433fd0216fc65e9a63cd6c2a9b63c Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Tue, 23 Dec 2025 12:49:49 +0100 Subject: [PATCH] chore: add simple iw3 system test --- test/Catch2Common.lua | 3 ++ test/Catch2Common/OatTestPaths.cpp | 9 ++++ test/Catch2Common/OatTestPaths.h | 2 + test/Catch2Common/main.cpp | 17 ++++--- test/SystemTests.lua | 4 ++ test/SystemTests/.gitkeep | 0 test/SystemTests/Game/IW3/SimpleZoneIW3.cpp | 45 +++++++++++++++++++ .../Game/IW3/simple/SimpleZone.txt | 1 + .../Game/IW3/simple/SimpleZoneIW3.zone | 4 ++ test/SystemTests/SystemTestsPaths.cpp | 15 +++++++ test/SystemTests/SystemTestsPaths.h | 8 ++++ 11 files changed, 102 insertions(+), 6 deletions(-) delete mode 100644 test/SystemTests/.gitkeep create mode 100644 test/SystemTests/Game/IW3/SimpleZoneIW3.cpp create mode 100644 test/SystemTests/Game/IW3/simple/SimpleZone.txt create mode 100644 test/SystemTests/Game/IW3/simple/SimpleZoneIW3.zone create mode 100644 test/SystemTests/SystemTestsPaths.cpp create mode 100644 test/SystemTests/SystemTestsPaths.h diff --git a/test/Catch2Common.lua b/test/Catch2Common.lua index 514a4ca6..63d03a10 100644 --- a/test/Catch2Common.lua +++ b/test/Catch2Common.lua @@ -11,6 +11,7 @@ end function Catch2Common:link(links) links:add(self:name()) links:linkto(catch2) + links:linkto(Utils) end function Catch2Common:use() @@ -45,7 +46,9 @@ function Catch2Common:project() self:include(includes) catch2:include(includes) + Utils:include(includes) links:linkto(catch2) + links:linkto(Utils) links:linkall() end diff --git a/test/Catch2Common/OatTestPaths.cpp b/test/Catch2Common/OatTestPaths.cpp index 0370a1ba..faf0dd8b 100644 --- a/test/Catch2Common/OatTestPaths.cpp +++ b/test/Catch2Common/OatTestPaths.cpp @@ -24,4 +24,13 @@ namespace oat::paths return result; } + + std::filesystem::path GetTempDirectory(const std::string& subDir) + { + auto result = fs::current_path() / "build" / ".tmp" / subDir; + if (!fs::is_directory(result)) + fs::create_directories(result); + + return result; + } } // namespace oat::paths diff --git a/test/Catch2Common/OatTestPaths.h b/test/Catch2Common/OatTestPaths.h index c63783cf..12cad65c 100644 --- a/test/Catch2Common/OatTestPaths.h +++ b/test/Catch2Common/OatTestPaths.h @@ -1,10 +1,12 @@ #pragma once #include +#include namespace oat::paths { std::filesystem::path GetSourceDirectory(); std::filesystem::path GetTestDirectory(); std::filesystem::path GetTempDirectory(); + std::filesystem::path GetTempDirectory(const std::string& subDir); } // namespace oat::paths diff --git a/test/Catch2Common/main.cpp b/test/Catch2Common/main.cpp index b00818dc..26dbe0bd 100644 --- a/test/Catch2Common/main.cpp +++ b/test/Catch2Common/main.cpp @@ -1,3 +1,5 @@ +#include "Utils/Logging/Log.h" + #include #include #include @@ -7,6 +9,9 @@ namespace fs = std::filesystem; int main(const int argc, char* argv[]) { + con::init(); + con::set_log_level(con::LogLevel::DEBUG); + const fs::path absoluteBinDir(fs::canonical(argv[0]).parent_path()); const auto expectedLibDir = absoluteBinDir.parent_path().parent_path(); @@ -15,24 +20,24 @@ int main(const int argc, char* argv[]) if (absoluteBinDir.filename() != "tests" || expectedLibDir.filename() != "lib" || expectedBuildDir.filename() != "build") { - std::cerr << std::format("Expected test binary to be in the folder it was compiled into (build/lib/?/tests) but was {}\n", absoluteBinDir.string()); - std::cerr << "Please do not move test executable out of compilation folder\n"; + con::error("Expected test binary to be in the folder it was compiled into (build/lib/?/tests) but was {}", absoluteBinDir.string()); + con::error("Please do not move test executable out of compilation folder"); return 1; } const auto expectedSrcDir = expectedRootDir / "src"; if (!fs::is_directory(expectedSrcDir)) { - std::cerr << std::format("Expected source directory to exist in {}, but it did not\n", expectedSrcDir.string()); - std::cerr << "Please do not move test executable out of compilation folder\n"; + con::error("Expected source directory to exist in {}, but it did not", expectedSrcDir.string()); + con::error("Please do not move test executable out of compilation folder"); return 1; } const auto expectedTestDir = expectedRootDir / "test"; if (!fs::is_directory(expectedTestDir)) { - std::cerr << std::format("Expected test directory to exist in {}, but it did not\n", expectedTestDir.string()); - std::cerr << "Please do not move test executable out of compilation folder\n"; + con::error("Expected test directory to exist in {}, but it did not", expectedTestDir.string()); + con::error("Please do not move test executable out of compilation folder"); return 1; } diff --git a/test/SystemTests.lua b/test/SystemTests.lua index 440a419b..991ce0e3 100644 --- a/test/SystemTests.lua +++ b/test/SystemTests.lua @@ -44,6 +44,8 @@ function SystemTests:project() ObjLoading:include(includes) ObjCompiling:include(includes) ObjWriting:include(includes) + Linking:include(includes) + Unlinking:include(includes) catch2:include(includes) Raw:use() @@ -56,5 +58,7 @@ function SystemTests:project() links:linkto(ObjWriting) links:linkto(catch2) links:linkto(Catch2Common) + links:linkto(Linking) + links:linkto(Unlinking) links:linkall() end diff --git a/test/SystemTests/.gitkeep b/test/SystemTests/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/SystemTests/Game/IW3/SimpleZoneIW3.cpp b/test/SystemTests/Game/IW3/SimpleZoneIW3.cpp new file mode 100644 index 00000000..f5a206fd --- /dev/null +++ b/test/SystemTests/Game/IW3/SimpleZoneIW3.cpp @@ -0,0 +1,45 @@ +#include "Linker.h" +#include "OatTestPaths.h" +#include "SystemTestsPaths.h" + +#include +#include +#include +#include + +using namespace std::literals; + +namespace +{ + TEST_CASE("Simple Zone(IW3)", "[iw3][system][simple]") + { + const auto assetSearchPath = oat::paths::GetSystemTestsDirectory() / "Game/IW3/simple"; + const auto sourceSearchPath = oat::paths::GetSystemTestsDirectory() / "Game/IW3/simple"; + const auto outputPath = oat::paths::GetTempDirectory("iw3_simple"); + + const char* argStrings[]{ + "SystemTests", // bin + "--verbose", + "--asset-search-path", + assetSearchPath.c_str(), + "--source-search-path", + sourceSearchPath.c_str(), + "--output-folder", + outputPath.c_str(), + "SimpleZoneIW3", + }; + + LinkerArgs args; + + bool shouldContinue = true; + const auto couldParseArgs = args.ParseArgs(std::extent_v, argStrings, shouldContinue); + + REQUIRE(couldParseArgs); + REQUIRE(shouldContinue); + + const auto linker = Linker::Create(std::move(args)); + const auto linkerResult = linker->Start(); + + REQUIRE(linkerResult); + } +} // namespace diff --git a/test/SystemTests/Game/IW3/simple/SimpleZone.txt b/test/SystemTests/Game/IW3/simple/SimpleZone.txt new file mode 100644 index 00000000..aea46cd0 --- /dev/null +++ b/test/SystemTests/Game/IW3/simple/SimpleZone.txt @@ -0,0 +1 @@ +This is a simple zone. diff --git a/test/SystemTests/Game/IW3/simple/SimpleZoneIW3.zone b/test/SystemTests/Game/IW3/simple/SimpleZoneIW3.zone new file mode 100644 index 00000000..0b645a8f --- /dev/null +++ b/test/SystemTests/Game/IW3/simple/SimpleZoneIW3.zone @@ -0,0 +1,4 @@ +>game,IW3 + +rawfile,SimpleZone.txt + diff --git a/test/SystemTests/SystemTestsPaths.cpp b/test/SystemTests/SystemTestsPaths.cpp new file mode 100644 index 00000000..9267e46d --- /dev/null +++ b/test/SystemTests/SystemTestsPaths.cpp @@ -0,0 +1,15 @@ +#include "SystemTestsPaths.h" + +#include "OatTestPaths.h" + +#include + +namespace fs = std::filesystem; + +namespace oat::paths +{ + std::filesystem::path GetSystemTestsDirectory() + { + return GetTestDirectory() / "SystemTests"; + } +} // namespace oat::paths diff --git a/test/SystemTests/SystemTestsPaths.h b/test/SystemTests/SystemTestsPaths.h new file mode 100644 index 00000000..70073caf --- /dev/null +++ b/test/SystemTests/SystemTestsPaths.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace oat::paths +{ + std::filesystem::path GetSystemTestsDirectory(); +} // namespace oat::paths