diff --git a/worldeditadditions/lib/normalize_test.lua b/worldeditadditions/lib/normalize_test.lua index 9fa3a1e..99a167c 100644 --- a/worldeditadditions/lib/normalize_test.lua +++ b/worldeditadditions/lib/normalize_test.lua @@ -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 \ No newline at end of file +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) \ No newline at end of file diff --git a/worldeditadditions_commands/commands/test/test.lua b/worldeditadditions_commands/commands/test/test.lua index 8d6f059..13092cc 100644 --- a/worldeditadditions_commands/commands/test/test.lua +++ b/worldeditadditions_commands/commands/test/test.lua @@ -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) diff --git a/worldeditadditions_commands/commands/test/tests/credits.test.lua b/worldeditadditions_commands/commands/test/tests/credits.test.lua index 618e9df..1b0f79d 100644 --- a/worldeditadditions_commands/commands/test/tests/credits.test.lua +++ b/worldeditadditions_commands/commands/test/tests/credits.test.lua @@ -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) diff --git a/worldeditadditions_commands/commands/test/tests/init.lua b/worldeditadditions_commands/commands/test/tests/init.lua index 7577afb..d2efccc 100644 --- a/worldeditadditions_commands/commands/test/tests/init.lua +++ b/worldeditadditions_commands/commands/test/tests/init.lua @@ -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 diff --git a/worldeditadditions_commands/commands/test/tests/notify.test.lua b/worldeditadditions_commands/commands/test/tests/notify.test.lua index eca6ed1..b0d433d 100644 --- a/worldeditadditions_commands/commands/test/tests/notify.test.lua +++ b/worldeditadditions_commands/commands/test/tests/notify.test.lua @@ -1,5 +1,5 @@ local Notify = worldeditadditions_core.notify -return worldeditadditions.normalize_test("notify", { +worldeditadditions.normalize_test("notify", { params = "", description = "Sends message to player in all main notification formats (error, warn, ok, info).", func = function(name, params_table) diff --git a/worldeditadditions_commands/commands/test/tests/notify_bad.test.lua b/worldeditadditions_commands/commands/test/tests/notify_bad.test.lua index 16afeb6..8e9c374 100644 --- a/worldeditadditions_commands/commands/test/tests/notify_bad.test.lua +++ b/worldeditadditions_commands/commands/test/tests/notify_bad.test.lua @@ -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) diff --git a/worldeditadditions_commands/commands/test/tests/notify_suppress.test.lua b/worldeditadditions_commands/commands/test/tests/notify_suppress.test.lua new file mode 100644 index 0000000..e69de29