test(plugins): check unwinding and version (#6586)

This commit is contained in:
nerix
2025-11-17 17:29:07 +01:00
committed by GitHub
parent 1ca855f9db
commit 115428d7f4
3 changed files with 55 additions and 0 deletions
+1
View File
@@ -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,
+1
View File
@@ -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
+53
View File
@@ -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<QString>