mirror of
https://github.com/minetest/minetest.git
synced 2024-11-22 23:53:44 +01:00
Fix broken unit test
Also makes devtest unit test results a bit more prominent
This commit is contained in:
parent
5009259473
commit
567f85752d
@ -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, ""
|
||||
|
13
games/devtest/mods/unittests/load_time.lua
Normal file
13
games/devtest/mods/unittests/load_time.lua
Normal file
@ -0,0 +1,13 @@
|
||||
-- Test item (un)registration and overriding
|
||||
do
|
||||
local itemname = "unittests:test_override_item"
|
||||
minetest.register_craftitem(":" .. itemname, {description = "foo"})
|
||||
assert(assert(minetest.registered_items[itemname]).description == "foo")
|
||||
minetest.override_item(itemname, {description = "bar"})
|
||||
assert(assert(minetest.registered_items[itemname]).description == "bar")
|
||||
minetest.override_item(itemname, {}, {"description"})
|
||||
-- description has the empty string as a default
|
||||
assert(assert(minetest.registered_items[itemname]).description == "")
|
||||
minetest.unregister_item("unittests:test_override_item")
|
||||
assert(minetest.registered_items["unittests:test_override_item"] == nil)
|
||||
end
|
@ -254,15 +254,3 @@ local function test_gennotify_api()
|
||||
assert(#custom == 0, "custom ids not empty")
|
||||
end
|
||||
unittests.register("test_gennotify_api", test_gennotify_api)
|
||||
|
||||
unittests.register("test_item_registration", function()
|
||||
local itemname = "unittests:test_override_item"
|
||||
minetest.register_item(itemname, {description = "foo"})
|
||||
assert(assert(minetest.registered_items[itemname]).description == "foo")
|
||||
minetest.override_item(itemname, {description = "bar"})
|
||||
assert(assert(minetest.registered_items[itemname]).description == "bar")
|
||||
minetest.override_item(itemname, {}, {"description"})
|
||||
assert(assert(minetest.registered_items[itemname]).description == nil)
|
||||
minetest.unregister_item("unittests:test_override_item")
|
||||
assert(minetest.registered_items["unittests:test_override_item"] == nil)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user