refactor of test registry

This commit is contained in:
VorTechnix 2024-10-15 17:32:14 -07:00
parent 66dcd6bbd7
commit 112364e767
No known key found for this signature in database
GPG Key ID: 091E91A69545D5BA
7 changed files with 28 additions and 12 deletions

@ -21,7 +21,9 @@ local metatable = {
}
metatable.__index = metatable
local normalize_test = function(test_name, def)
local registered_tests = {}
local register_test = function(test_name, def)
---
-- 1: Validation
---
@ -45,8 +47,22 @@ local normalize_test = function(test_name, def)
-- 2: Normalisation
---
setmetatable(def, metatable)
return test_name, def
registered_tests[test_name] = def
end
return normalize_test
local normalize_test = {}
normalize_test.__index = normalize_test
normalize_test.__call = function(self, test_name, def)
register_test(test_name, def)
end
normalize_test.get_registered_tests = function()
local ret = {}
for k, v in pairs(registered_tests) do
ret[k] = v
end
return ret
end
return setmetatable({}, normalize_test)

@ -10,7 +10,9 @@ local wea_cmd = worldeditadditions_commands
local test_dir = wea_cmd.modpath .. "/commands/test/tests/"
-- Load tests with init function
local tests = dofile(test_dir .. "init.lua")(test_dir)
dofile(test_dir .. "init.lua")(test_dir)
local tests = worldeditadditions.normalize_test.get_registered_tests()
-- Helper functions
local set_colour = function(colour, text)
return minetest.colorize(colour, text)

@ -12,7 +12,7 @@ local credits = {
}
local Notify = worldeditadditions_core.notify
return worldeditadditions.normalize_test("credits", {
worldeditadditions.normalize_test("credits", {
params = "N\\A",
description = "Sends WEA credits to player in info notification format.",
func = function(name, params_table)

@ -3,6 +3,7 @@ local test_id_paths = {
"credits.test.lua",
"notify.test.lua",
"notify_bad.test.lua",
-- "notify_suppress.test.lua",
-- "stacktrace.test.lua",
}
@ -11,10 +12,7 @@ local update = function(a,k,v) a[k] = v end
-- Test loader
local test_loader = function (path)
local ret = {}
for _, v in ipairs(test_id_paths) do
update(ret, dofile(path .. v))
end
for _, v in ipairs(test_id_paths) do dofile(path .. v) end
return ret
end

@ -1,5 +1,5 @@
local Notify = worldeditadditions_core.notify
return worldeditadditions.normalize_test("notify", {
worldeditadditions.normalize_test("notify", {
params = "<message>",
description = "Sends message to player in all main notification formats (error, warn, ok, info).",
func = function(name, params_table)

@ -1,5 +1,5 @@
local Notify = worldeditadditions_core.notify
return worldeditadditions.normalize_test("notifybad", {
worldeditadditions.normalize_test("notifybad", {
params = "N/A",
description = "Sends badly formed messages to player to test error handling.",
func = function(name, params_table)