From 14860ab6254e3a5205841fb897418a2ecb383841 Mon Sep 17 00:00:00 2001 From: Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com> Date: Wed, 2 Oct 2024 08:07:56 +0200 Subject: [PATCH] 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. --- base.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/base.lua b/base.lua index 3cd8623..b65ad68 100644 --- a/base.lua +++ b/base.lua @@ -44,6 +44,15 @@ local register_test = function(mod, name, func, opts) end 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) register_test(mod, name, func, opts) end