1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

Fix broken unit test

Also makes devtest unit test results a bit more prominent
This commit is contained in:
Lars Mueller 2024-05-21 16:27:38 +02:00
parent 5009259473
commit 567f85752d
3 changed files with 37 additions and 16 deletions

View file

@ -160,7 +160,7 @@ function unittests.run_all()
-- Print stats
assert(#unittests.list == counters.total)
print(string.rep("+", 80))
print(string.format("Unit Test Results: %s",
print(string.format("Devtest Unit Test Results: %s",
counters.total == counters.passed and "PASSED" or "FAILED"))
print(string.format(" %d / %d failed tests.",
counters.total - counters.passed, counters.total))
@ -185,22 +185,42 @@ dofile(modpath .. "/content_ids.lua")
dofile(modpath .. "/metadata.lua")
dofile(modpath .. "/raycast.lua")
dofile(modpath .. "/inventory.lua")
dofile(modpath .. "/load_time.lua")
--------------
local function send_results(name, ok)
core.chat_send_player(name,
minetest.colorize(ok and "green" or "red",
(ok and "All devtest unit tests passed." or
"There were devtest unit test failures.") ..
" Check the console for detailed output."))
end
if core.settings:get_bool("devtest_unittests_autostart", false) then
local test_results = nil
core.after(0, function()
unittests.on_finished = function(ok)
for _, player in ipairs(minetest.get_connected_players()) do
send_results(player:get_player_name(), ok)
end
test_results = ok
end
coroutine.wrap(unittests.run_all)()
end)
minetest.register_on_joinplayer(function(player)
if test_results == nil then
return -- tests haven't completed yet
end
send_results(player:get_player_name(), test_results)
end)
else
core.register_chatcommand("unittests", {
privs = {basic_privs=true},
description = "Runs devtest unittests (may modify player or map state)",
func = function(name, param)
unittests.on_finished = function(ok)
core.chat_send_player(name,
(ok and "All tests passed." or "There were test failures.") ..
" Check the console for detailed output.")
send_results(name, ok)
end
coroutine.wrap(unittests.run_all)()
return true, ""