added //test

This commit is contained in:
VorTechnix 2024-10-13 13:54:02 -07:00
parent f15d2e31f7
commit c218242190
No known key found for this signature in database
GPG key ID: 091E91A69545D5BA
4 changed files with 97 additions and 0 deletions

View file

@ -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 || <testname> <args> || help <testname>",
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
})

View file

@ -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

View file

@ -0,0 +1,12 @@
local Notify = worldeditadditions_core.notify
return 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)
local message = table.concat(params_table, " ")
Notify.error(name, message)
Notify.warn(name, message)
Notify.ok(name, message)
Notify.info(name, message)
end
})

View file

@ -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