mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
chore: check exact paths of test executable and provide temp dir
This commit is contained in:
51
test/Catch2Common.lua
Normal file
51
test/Catch2Common.lua
Normal file
@ -0,0 +1,51 @@
|
||||
Catch2Common = {}
|
||||
|
||||
function Catch2Common:include(includes)
|
||||
if includes:handle(self:name()) then
|
||||
includedirs {
|
||||
path.join(TestFolder(), "Catch2Common")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function Catch2Common:link(links)
|
||||
links:add(self:name())
|
||||
links:linkto(catch2)
|
||||
end
|
||||
|
||||
function Catch2Common:use()
|
||||
|
||||
end
|
||||
|
||||
function Catch2Common:name()
|
||||
return "Catch2Common"
|
||||
end
|
||||
|
||||
function Catch2Common:project()
|
||||
local folder = TestFolder()
|
||||
local includes = Includes:create()
|
||||
local links = Links:create()
|
||||
|
||||
project(self:name())
|
||||
targetdir(TargetDirectoryTest)
|
||||
location "%{wks.location}/test/%{prj.name}"
|
||||
kind "StaticLib"
|
||||
language "C++"
|
||||
|
||||
files {
|
||||
path.join(folder, "Catch2Common/**.h"),
|
||||
path.join(folder, "Catch2Common/**.cpp")
|
||||
}
|
||||
|
||||
vpaths {
|
||||
["*"] = {
|
||||
path.join(folder, "Catch2Common")
|
||||
}
|
||||
}
|
||||
|
||||
self:include(includes)
|
||||
catch2:include(includes)
|
||||
|
||||
links:linkto(catch2)
|
||||
links:linkall()
|
||||
end
|
27
test/Catch2Common/OatTestPaths.cpp
Normal file
27
test/Catch2Common/OatTestPaths.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "OatTestPaths.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace oat::paths
|
||||
{
|
||||
std::filesystem::path GetSourceDirectory()
|
||||
{
|
||||
return fs::current_path() / "src";
|
||||
}
|
||||
|
||||
std::filesystem::path GetTestDirectory()
|
||||
{
|
||||
return fs::current_path() / "test";
|
||||
}
|
||||
|
||||
std::filesystem::path GetTempDirectory()
|
||||
{
|
||||
auto result = fs::current_path() / "build" / ".tmp";
|
||||
if (!fs::is_directory(result))
|
||||
fs::create_directories(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace oat::paths
|
10
test/Catch2Common/OatTestPaths.h
Normal file
10
test/Catch2Common/OatTestPaths.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
namespace oat::paths
|
||||
{
|
||||
std::filesystem::path GetSourceDirectory();
|
||||
std::filesystem::path GetTestDirectory();
|
||||
std::filesystem::path GetTempDirectory();
|
||||
} // namespace oat::paths
|
48
test/Catch2Common/main.cpp
Normal file
48
test/Catch2Common/main.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <catch2/catch_session.hpp>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
int main(const int argc, char* argv[])
|
||||
{
|
||||
const fs::path absoluteBinDir(fs::absolute(argv[0]).parent_path());
|
||||
|
||||
const auto expectedLibDir = absoluteBinDir.parent_path().parent_path();
|
||||
const auto expectedBuildDir = expectedLibDir.parent_path();
|
||||
const auto expectedRootDir = expectedBuildDir.parent_path();
|
||||
|
||||
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";
|
||||
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";
|
||||
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";
|
||||
return 1;
|
||||
}
|
||||
|
||||
fs::current_path(expectedRootDir);
|
||||
|
||||
const auto result = Catch::Session().run(argc, argv);
|
||||
|
||||
const auto tempDir = expectedBuildDir / ".tmp";
|
||||
if (fs::is_directory(tempDir))
|
||||
fs::remove_all(tempDir);
|
||||
|
||||
return result;
|
||||
}
|
@ -44,6 +44,7 @@ function ObjCommonTests:project()
|
||||
}
|
||||
|
||||
self:include(includes)
|
||||
Catch2Common:include(includes)
|
||||
ObjCommon:include(includes)
|
||||
ObjImage:include(includes)
|
||||
catch2:include(includes)
|
||||
@ -51,5 +52,6 @@ function ObjCommonTests:project()
|
||||
links:linkto(ObjCommon)
|
||||
links:linkto(ObjImage)
|
||||
links:linkto(catch2)
|
||||
links:linkto(Catch2Common)
|
||||
links:linkall()
|
||||
end
|
||||
|
@ -43,6 +43,7 @@ function ObjCompilingTests:project()
|
||||
}
|
||||
|
||||
self:include(includes)
|
||||
Catch2Common:include(includes)
|
||||
ObjCommonTestUtils:include(includes)
|
||||
ParserTestUtils:include(includes)
|
||||
ObjLoading:include(includes)
|
||||
@ -54,5 +55,6 @@ function ObjCompilingTests:project()
|
||||
links:linkto(ObjLoading)
|
||||
links:linkto(ObjCompiling)
|
||||
links:linkto(catch2)
|
||||
links:linkto(Catch2Common)
|
||||
links:linkall()
|
||||
end
|
||||
|
@ -43,6 +43,7 @@ function ObjLoadingTests:project()
|
||||
}
|
||||
|
||||
self:include(includes)
|
||||
Catch2Common:include(includes)
|
||||
ObjCommonTestUtils:include(includes)
|
||||
ParserTestUtils:include(includes)
|
||||
ObjLoading:include(includes)
|
||||
@ -52,5 +53,6 @@ function ObjLoadingTests:project()
|
||||
links:linkto(ParserTestUtils)
|
||||
links:linkto(ObjLoading)
|
||||
links:linkto(catch2)
|
||||
links:linkto(Catch2Common)
|
||||
links:linkall()
|
||||
end
|
||||
|
@ -43,6 +43,7 @@ function ParserTests:project()
|
||||
}
|
||||
|
||||
self:include(includes)
|
||||
Catch2Common:include(includes)
|
||||
ParserTestUtils:include(includes)
|
||||
Parser:include(includes)
|
||||
catch2:include(includes)
|
||||
@ -50,5 +51,6 @@ function ParserTests:project()
|
||||
links:linkto(ParserTestUtils)
|
||||
links:linkto(Parser)
|
||||
links:linkto(catch2)
|
||||
links:linkto(Catch2Common)
|
||||
links:linkall()
|
||||
end
|
||||
|
@ -43,6 +43,7 @@ function ZoneCodeGeneratorLibTests:project()
|
||||
}
|
||||
|
||||
self:include(includes)
|
||||
Catch2Common:include(includes)
|
||||
ZoneCodeGeneratorLib:include(includes)
|
||||
ParserTestUtils:include(includes)
|
||||
catch2:include(includes)
|
||||
@ -50,5 +51,6 @@ function ZoneCodeGeneratorLibTests:project()
|
||||
links:linkto(ZoneCodeGeneratorLib)
|
||||
links:linkto(ParserTestUtils)
|
||||
links:linkto(catch2)
|
||||
links:linkto(Catch2Common)
|
||||
links:linkall()
|
||||
end
|
||||
|
@ -45,6 +45,7 @@ function ZoneCommonTests:project()
|
||||
}
|
||||
|
||||
self:include(includes)
|
||||
Catch2Common:include(includes)
|
||||
ObjCommonTestUtils:include(includes)
|
||||
ZoneCommon:include(includes)
|
||||
catch2:include(includes)
|
||||
@ -52,6 +53,7 @@ function ZoneCommonTests:project()
|
||||
links:linkto(ObjCommonTestUtils)
|
||||
links:linkto(ZoneCommon)
|
||||
links:linkto(catch2)
|
||||
links:linkto(Catch2Common)
|
||||
links:linkall()
|
||||
|
||||
ZoneCode:use()
|
||||
|
Reference in New Issue
Block a user