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
+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>