From 115428d7f475c75c0ae6c211f0db4c81004ce49b Mon Sep 17 00:00:00 2001 From: nerix Date: Mon, 17 Nov 2025 17:29:07 +0100 Subject: [PATCH] test(plugins): check unwinding and version (#6586) --- .clang-tidy | 1 + CHANGELOG.md | 1 + tests/src/Plugins.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index f06e4e79..cc7014b8 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -14,6 +14,7 @@ Checks: "-*, cert-*, cppcoreguidelines-*, -cppcoreguidelines-pro-type-cstyle-cast, + -cppcoreguidelines-pro-type-vararg, -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-owning-memory, diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f489f28..62c0d8d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ - Dev: Refactored split container nodes to use shared pointers. (#6435) - Dev: Mock headers are now added as a header set if supported by CMake. (#6561) - Dev: Set settings directory to temporary one used in tests. (#6584) +- Dev: Check Lua unwinding and version in tests. (#6586) ## 2.5.4 diff --git a/tests/src/Plugins.cpp b/tests/src/Plugins.cpp index 0eae2d6d..f4d579eb 100644 --- a/tests/src/Plugins.cpp +++ b/tests/src/Plugins.cpp @@ -973,6 +973,59 @@ TEST_F(PluginTest, ChannelAddMessage) ASSERT_EQ(added[5].first, logged[2]); } +/// Test that both C++ exceptions and luaL_error properly unwind the stack. +TEST_F(PluginTest, LuaUnwind) +{ + configure(); + + size_t i = 0; + lua->set_function( + "do_something", + [&](sol::this_state state, bool should_error, bool use_lua_error) { + auto g = qScopeGuard([&] { + ++i; + }); + if (should_error) + { + if (use_lua_error) + { + luaL_error(state.lua_state(), "My message"); + } + else + { + throw std::runtime_error("My message"); + } + } + }); + + ASSERT_EQ(i, 0); + + ASSERT_TRUE(lua->do_string("do_something(false, false)").valid()); + ASSERT_EQ(i, 1); + + ASSERT_TRUE(lua->do_string("do_something(false, true)").valid()); + ASSERT_EQ(i, 2); + + ASSERT_FALSE(lua->do_string("do_something(true, false)").valid()); + ASSERT_EQ(i, 3); + + ASSERT_FALSE(lua->do_string("do_something(true, true)").valid()); + ASSERT_EQ(i, 4); +} + +/// Test that we're running with the Lua version we're compiled against. +TEST_F(PluginTest, LuaVersion) +{ + configure(); + + lua->set_function("check_it", [](sol::this_state state) { + luaL_checkversion(state.lua_state()); + }); + ASSERT_TRUE(lua->script("check_it()").valid()); + + static_assert(LUA_VERSION_NUM >= 504); +} + class PluginMessageConstructionTest : public PluginTest, public ::testing::WithParamInterface