fix(testing): ensure mod validity in get_test_registrator

Check if the provided mod name is valid by iterating through the registered mod names before allowing test registration.
This commit is contained in:
Yves-Marie Haussonne 2024-10-02 08:07:56 +02:00
parent b40bbafd4c
commit 14860ab625

View File

@ -44,6 +44,15 @@ local register_test = function(mod, name, func, opts)
end end
test_harness.get_test_registrator = function(mod) test_harness.get_test_registrator = function(mod)
local modnames = minetest.get_modnames()
local is_mod = false
for i=1,#modnames do
if modnames[i]==mod then
is_mod=true
break
end
end
if not is_mod then error("get_test_registrator given mod "..mod.." is not a mod.") end
return function(name, func, opts) return function(name, func, opts)
register_test(mod, name, func, opts) register_test(mod, name, func, opts)
end end