mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-12-23 12:05:01 +00:00
refactor of test registry
This commit is contained in:
parent
66dcd6bbd7
commit
112364e767
7 changed files with 28 additions and 12 deletions
|
@ -21,7 +21,9 @@ local metatable = {
|
||||||
}
|
}
|
||||||
metatable.__index = metatable
|
metatable.__index = metatable
|
||||||
|
|
||||||
local normalize_test = function(test_name, def)
|
local registered_tests = {}
|
||||||
|
|
||||||
|
local register_test = function(test_name, def)
|
||||||
---
|
---
|
||||||
-- 1: Validation
|
-- 1: Validation
|
||||||
---
|
---
|
||||||
|
@ -45,8 +47,22 @@ local normalize_test = function(test_name, def)
|
||||||
-- 2: Normalisation
|
-- 2: Normalisation
|
||||||
---
|
---
|
||||||
setmetatable(def, metatable)
|
setmetatable(def, metatable)
|
||||||
|
registered_tests[test_name] = def
|
||||||
return test_name, def
|
|
||||||
end
|
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/"
|
local test_dir = wea_cmd.modpath .. "/commands/test/tests/"
|
||||||
|
|
||||||
-- Load tests with init function
|
-- 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
|
-- Helper functions
|
||||||
local set_colour = function(colour, text)
|
local set_colour = function(colour, text)
|
||||||
return minetest.colorize(colour, text)
|
return minetest.colorize(colour, text)
|
||||||
|
|
|
@ -12,7 +12,7 @@ local credits = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local Notify = worldeditadditions_core.notify
|
local Notify = worldeditadditions_core.notify
|
||||||
return worldeditadditions.normalize_test("credits", {
|
worldeditadditions.normalize_test("credits", {
|
||||||
params = "N\\A",
|
params = "N\\A",
|
||||||
description = "Sends WEA credits to player in info notification format.",
|
description = "Sends WEA credits to player in info notification format.",
|
||||||
func = function(name, params_table)
|
func = function(name, params_table)
|
||||||
|
|
|
@ -3,6 +3,7 @@ local test_id_paths = {
|
||||||
"credits.test.lua",
|
"credits.test.lua",
|
||||||
"notify.test.lua",
|
"notify.test.lua",
|
||||||
"notify_bad.test.lua",
|
"notify_bad.test.lua",
|
||||||
|
-- "notify_suppress.test.lua",
|
||||||
-- "stacktrace.test.lua",
|
-- "stacktrace.test.lua",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +12,7 @@ local update = function(a,k,v) a[k] = v end
|
||||||
|
|
||||||
-- Test loader
|
-- Test loader
|
||||||
local test_loader = function (path)
|
local test_loader = function (path)
|
||||||
local ret = {}
|
for _, v in ipairs(test_id_paths) do dofile(path .. v) end
|
||||||
for _, v in ipairs(test_id_paths) do
|
|
||||||
update(ret, dofile(path .. v))
|
|
||||||
end
|
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
local Notify = worldeditadditions_core.notify
|
local Notify = worldeditadditions_core.notify
|
||||||
return worldeditadditions.normalize_test("notify", {
|
worldeditadditions.normalize_test("notify", {
|
||||||
params = "<message>",
|
params = "<message>",
|
||||||
description = "Sends message to player in all main notification formats (error, warn, ok, info).",
|
description = "Sends message to player in all main notification formats (error, warn, ok, info).",
|
||||||
func = function(name, params_table)
|
func = function(name, params_table)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
local Notify = worldeditadditions_core.notify
|
local Notify = worldeditadditions_core.notify
|
||||||
return worldeditadditions.normalize_test("notifybad", {
|
worldeditadditions.normalize_test("notifybad", {
|
||||||
params = "N/A",
|
params = "N/A",
|
||||||
description = "Sends badly formed messages to player to test error handling.",
|
description = "Sends badly formed messages to player to test error handling.",
|
||||||
func = function(name, params_table)
|
func = function(name, params_table)
|
||||||
|
|
Loading…
Reference in a new issue