aboutsummaryrefslogtreecommitdiff
path: root/unit_tests
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-03-06 09:32:02 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2025-03-06 09:32:02 +0100
commitfc160438406458a11921566a4644c7f15d49c244 (patch)
treeca484f902d836626a45d973235a78cc85bae6e80 /unit_tests
parentdacdd54a805aac286e07582706d8a0e85d1f69a4 (diff)
downloadlanes-fc160438406458a11921566a4644c7f15d49c244.tar.gz
lanes-fc160438406458a11921566a4644c7f15d49c244.tar.bz2
lanes-fc160438406458a11921566a4644c7f15d49c244.zip
Makefile and code fixes to build the unit tests
Diffstat (limited to 'unit_tests')
-rw-r--r--unit_tests/Makefile31
-rw-r--r--unit_tests/UnitTests.vcxproj1
-rw-r--r--unit_tests/UnitTests.vcxproj.filters6
-rw-r--r--unit_tests/_pch.hpp2
-rw-r--r--unit_tests/embedded_tests.cpp8
-rw-r--r--unit_tests/init_and_shutdown.cpp5
-rw-r--r--unit_tests/shared.cpp4
7 files changed, 43 insertions, 14 deletions
diff --git a/unit_tests/Makefile b/unit_tests/Makefile
new file mode 100644
index 0000000..9cc192b
--- /dev/null
+++ b/unit_tests/Makefile
@@ -0,0 +1,31 @@
1#
2# Lanes/unit_tests/Makefile
3#
4
5include ../Shared.mk
6
7SRC=$(wildcard *.cpp) ../src/deep.cpp ../src/compat.cpp
8
9OBJ=$(SRC:.cpp=.o)
10
11
12_UNITTEST_TARGET=UnitTests$(_LUAEXT)
13
14#---
15all: $(_UNITTEST_TARGET)
16
17_pch.hpp.gch: _pch.hpp
18 $(CC) -I "../.." $(CFLAGS) -x c++-header _pch.hpp -o _pch.hpp.gch
19
20%.o: %.cpp _pch.hpp.gch *.h *.hpp Makefile
21 $(CC) -I "../.." $(CFLAGS) -c $<
22
23# Note: Don't put $(LUA_LIBS) ahead of $^; MSYS will not like that (I think)
24#
25$(_UNITTEST_TARGET): $(OBJ)
26 $(CC) $(LIBFLAG) $^ $(LIBS) $(LUA_LIBS) -o $@
27
28clean:
29 -rm -rf $(_UNITTEST_TARGET) *.o *.map
30
31.PROXY: all clean
diff --git a/unit_tests/UnitTests.vcxproj b/unit_tests/UnitTests.vcxproj
index 5cc3b2f..7cdbafe 100644
--- a/unit_tests/UnitTests.vcxproj
+++ b/unit_tests/UnitTests.vcxproj
@@ -345,6 +345,7 @@
345 </ItemGroup> 345 </ItemGroup>
346 <ItemGroup> 346 <ItemGroup>
347 <None Include="Catch2.runsettings" /> 347 <None Include="Catch2.runsettings" />
348 <None Include="Makefile" />
348 <None Include="scripts\coro\basics.lua" /> 349 <None Include="scripts\coro\basics.lua" />
349 <None Include="scripts\coro\error_handling.lua" /> 350 <None Include="scripts\coro\error_handling.lua" />
350 <None Include="scripts\lane\cooperative_shutdown.lua" /> 351 <None Include="scripts\lane\cooperative_shutdown.lua" />
diff --git a/unit_tests/UnitTests.vcxproj.filters b/unit_tests/UnitTests.vcxproj.filters
index 45ae229..c4e85c5 100644
--- a/unit_tests/UnitTests.vcxproj.filters
+++ b/unit_tests/UnitTests.vcxproj.filters
@@ -51,6 +51,9 @@
51 <Filter Include="Catch2"> 51 <Filter Include="Catch2">
52 <UniqueIdentifier>{2e1bf85c-7722-42ba-86f8-ac0f5a494ac5}</UniqueIdentifier> 52 <UniqueIdentifier>{2e1bf85c-7722-42ba-86f8-ac0f5a494ac5}</UniqueIdentifier>
53 </Filter> 53 </Filter>
54 <Filter Include="Make">
55 <UniqueIdentifier>{c62af5d9-9161-4ca1-9b58-6837e2907e35}</UniqueIdentifier>
56 </Filter>
54 </ItemGroup> 57 </ItemGroup>
55 <ItemGroup> 58 <ItemGroup>
56 <None Include="scripts\linda\send_receive.lua"> 59 <None Include="scripts\linda\send_receive.lua">
@@ -107,5 +110,8 @@
107 <None Include="Catch2.runsettings"> 110 <None Include="Catch2.runsettings">
108 <Filter>Catch2</Filter> 111 <Filter>Catch2</Filter>
109 </None> 112 </None>
113 <None Include="Makefile">
114 <Filter>Make</Filter>
115 </None>
110 </ItemGroup> 116 </ItemGroup>
111</Project> \ No newline at end of file 117</Project> \ No newline at end of file
diff --git a/unit_tests/_pch.hpp b/unit_tests/_pch.hpp
index 7fa18a2..1e98c5a 100644
--- a/unit_tests/_pch.hpp
+++ b/unit_tests/_pch.hpp
@@ -1,9 +1,11 @@
1#pragma once 1#pragma once
2 2
3#include <atomic>
3#include <cassert> 4#include <cassert>
4#include <filesystem> 5#include <filesystem>
5#include <source_location> 6#include <source_location>
6#include <mutex> 7#include <mutex>
8#include <thread>
7#include <variant> 9#include <variant>
8 10
9#include "catch_amalgamated.hpp" 11#include "catch_amalgamated.hpp"
diff --git a/unit_tests/embedded_tests.cpp b/unit_tests/embedded_tests.cpp
index bf2dd6e..1a63721 100644
--- a/unit_tests/embedded_tests.cpp
+++ b/unit_tests/embedded_tests.cpp
@@ -60,14 +60,6 @@ TEST_CASE("lanes.embedding")
60 lua_pop(S, 1); 60 lua_pop(S, 1);
61 S.stackCheck(0); 61 S.stackCheck(0);
62 62
63 auto load_lanes_lua = +[](lua_State* const L_) {
64 if (0 == luaL_dofile(L_, "lanes.lua")) {
65 return 1;
66 } else {
67 return 0;
68 }
69 };
70
71 _p_luaopen_lanes_embedded(S, local::load_lanes_lua); // S: lanes 63 _p_luaopen_lanes_embedded(S, local::load_lanes_lua); // S: lanes
72 lua_pop(S, 1); 64 lua_pop(S, 1);
73 S.stackCheck(0); 65 S.stackCheck(0);
diff --git a/unit_tests/init_and_shutdown.cpp b/unit_tests/init_and_shutdown.cpp
index 78c472f..147a742 100644
--- a/unit_tests/init_and_shutdown.cpp
+++ b/unit_tests/init_and_shutdown.cpp
@@ -756,11 +756,6 @@ TEST_CASE("lanes.on_state_create setting")
756 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; 756 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } };
757 757
758 local::OnStateCreateCallsCount.store(0, std::memory_order_relaxed); 758 local::OnStateCreateCallsCount.store(0, std::memory_order_relaxed);
759 auto on_state_create = +[](lua_State* const L_) {
760 local::OnStateCreateCallsCount.fetch_add(1, std::memory_order_relaxed);
761 return 0;
762 };
763
764 759
765 SECTION("on_state_create called in Keeper states") 760 SECTION("on_state_create called in Keeper states")
766 { 761 {
diff --git a/unit_tests/shared.cpp b/unit_tests/shared.cpp
index 73aeadd..023e917 100644
--- a/unit_tests/shared.cpp
+++ b/unit_tests/shared.cpp
@@ -101,7 +101,9 @@ namespace
101TEST_CASE("lanes.stack checker") 101TEST_CASE("lanes.stack checker")
102{ 102{
103 LuaState _L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; 103 LuaState _L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } };
104#if HAVE_LUA_ASSERT()
104 StackChecker::CallsCassert = false; 105 StackChecker::CallsCassert = false;
106#endif // HAVE_LUA_ASSERT()
105 107
106 auto _doStackCheckerTest = [&_L](lua_CFunction const _f, LuaError const _expected) { 108 auto _doStackCheckerTest = [&_L](lua_CFunction const _f, LuaError const _expected) {
107 lua_pushcfunction(_L, _f); 109 lua_pushcfunction(_L, _f);
@@ -223,7 +225,7 @@ std::string_view LuaState::doStringAndRet(std::string_view const& str_) const
223 STACK_CHECK(L, 1); // the error message is on the stack 225 STACK_CHECK(L, 1); // the error message is on the stack
224 return ""; 226 return "";
225 } 227 }
226 LuaError const _callErr{ lua_pcall(L, 0, 1, 0) }; // L: "<msg>"?|retstring 228 [[maybe_unused]] LuaError const _callErr{ lua_pcall(L, 0, 1, 0) }; // L: "<msg>"?|retstring
227 STACK_CHECK(L, 1); 229 STACK_CHECK(L, 1);
228 return luaG_tostring(L, kIdxTop); 230 return luaG_tostring(L, kIdxTop);
229} 231}