From c218242190afae379d115789af4d81206385f310 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 13 Oct 2024 13:54:02 -0700 Subject: [PATCH] added //test --- .../commands/test/test.lua | 63 +++++++++++++++++++ .../commands/test/tests/init.lua | 19 ++++++ .../commands/test/tests/notify.test.lua | 12 ++++ worldeditadditions_commands/init.lua | 3 + 4 files changed, 97 insertions(+) create mode 100644 worldeditadditions_commands/commands/test/test.lua create mode 100644 worldeditadditions_commands/commands/test/tests/init.lua create mode 100644 worldeditadditions_commands/commands/test/tests/notify.test.lua diff --git a/worldeditadditions_commands/commands/test/test.lua b/worldeditadditions_commands/commands/test/test.lua new file mode 100644 index 0000000..6be5f6e --- /dev/null +++ b/worldeditadditions_commands/commands/test/test.lua @@ -0,0 +1,63 @@ +-- ████████ ███████ ███████ ████████ +-- ██ ██ ██ ██ +-- ██ █████ ███████ ██ +-- ██ ██ ██ ██ +-- ██ ███████ ███████ ██ + +local wea_c = worldeditadditions_core +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) +-- Helper functions +local set_colour = function(colour, text) + return minetest.colorize(colour, text) +end + +wea_c.register_command("test", { + params = "list || || help ", + description = "Run a test or list all tests", + privs = {worldedit = true}, + parse = function(params_text) + local ret = wea_c.split(params_text) + if #ret < 1 then + return false, "Error: No params found!" + elseif ret[1] ~= "list" and #ret < 2 then + if ret[1] == "help" then + return false, "Error: No test found!" + else return false, "Error: No arguments found!" end + end + if not tests[ ret[1] == "help" and ret[2] or ret[1] ] then + return false, "Error: Test '"..ret[1].."' not found!" + end + return true, table.remove(ret, 1), ret + end, + func = function(name, subcommand, params_text) + if subcommand == "list" then + local ret = "" + -- List in rows of 7 + local count = 0 + for k, _ in pairs(tests) do + ret = ret .. k + count = count + 1 + if count % 7 == 0 then ret = ret .. "\n" + else ret = ret .. ", "end + end + return true, ret + elseif subcommand == "help" then + if not params_text[1] then + return false, "Error: No test found!" + elseif not tests[params_text[1]] then + return false, "Error: Test '"..params_text[1].."' not found!" + else + return true, table.concat({ + set_colour("#55FF55", "//test"), + set_colour("#55B9FF", params_text[1]), + tests[params_text[1]]:help()}, " ") + end + end + return tests[subcommand](name, params_text) + end +}) \ No newline at end of file diff --git a/worldeditadditions_commands/commands/test/tests/init.lua b/worldeditadditions_commands/commands/test/tests/init.lua new file mode 100644 index 0000000..e94603f --- /dev/null +++ b/worldeditadditions_commands/commands/test/tests/init.lua @@ -0,0 +1,19 @@ +-- Test registry +local test_id_paths = { + "notify.test.lua", + -- "stacktrace.test.lua", +} + +-- Helper functions +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 + return ret +end + +return test_loader \ No newline at end of file diff --git a/worldeditadditions_commands/commands/test/tests/notify.test.lua b/worldeditadditions_commands/commands/test/tests/notify.test.lua new file mode 100644 index 0000000..e8c9a9f --- /dev/null +++ b/worldeditadditions_commands/commands/test/tests/notify.test.lua @@ -0,0 +1,12 @@ +local Notify = worldeditadditions_core.notify +return worldeditadditions.normalize_test("notify", { + params = "", + description = "Sends message to player in all main notification formats (error, warn, ok, info).", + func = function(name, params_table) + local message = table.concat(params_table, " ") + Notify.error(name, message) + Notify.warn(name, message) + Notify.ok(name, message) + Notify.info(name, message) + end +}) \ No newline at end of file diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index d0a9273..ebeca6e 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -63,6 +63,9 @@ dofile(wea_cmd.modpath.."/commands/extra/basename.lua") dofile(wea_cmd.modpath.."/commands/extra/sculptlist.lua") dofile(wea_cmd.modpath.."/commands/extra/speed.lua") +-- Test command +dofile(wea_cmd.modpath.."/commands/test/test.lua") + -- Don't register the //bonemeal command if the bonemeal mod isn't present if minetest.global_exists("bonemeal") then