mirror of
https://github.com/minetest/minetest.git
synced 2024-12-23 06:32:23 +01:00
Fix node callbacks unit test
This commit is contained in:
parent
9b97147637
commit
91ea47fddf
@ -5966,6 +5966,7 @@ Environment access
|
||||
returns `{name="ignore", param1=0, param2=0}` for unloaded areas.
|
||||
* `minetest.get_node_or_nil(pos)`
|
||||
* Same as `get_node` but returns `nil` for unloaded areas.
|
||||
* Note that areas may still contain "ignore" despite being loaded.
|
||||
* `minetest.get_node_light(pos[, timeofday])`
|
||||
* Gets the light value at the given position. Note that the light value
|
||||
"inside" the node at the given position is returned, so you usually want
|
||||
|
@ -108,9 +108,9 @@ local function wait_for_player(callback)
|
||||
end)
|
||||
end
|
||||
|
||||
local function wait_for_map(player, callback)
|
||||
local function wait_for_map(pos, callback)
|
||||
local function check()
|
||||
if core.get_node_or_nil(player:get_pos()) ~= nil then
|
||||
if core.get_node(pos).name ~= "ignore" then
|
||||
callback()
|
||||
else
|
||||
core.after(0, check)
|
||||
@ -119,8 +119,8 @@ local function wait_for_map(player, callback)
|
||||
check()
|
||||
end
|
||||
|
||||
-- This runs in a coroutine so it uses await()
|
||||
function unittests.run_all()
|
||||
-- This runs in a coroutine so it uses await().
|
||||
local counters = { time = 0, total = 0, passed = 0 }
|
||||
|
||||
-- Run standalone tests first
|
||||
@ -143,10 +143,11 @@ function unittests.run_all()
|
||||
end
|
||||
|
||||
-- Wait for the world to generate/load, run tests that require map access
|
||||
local pos = player:get_pos():round():offset(0, 5, 0)
|
||||
core.forceload_block(pos, true, -1)
|
||||
await(function(cb)
|
||||
wait_for_map(player, cb)
|
||||
wait_for_map(pos, cb)
|
||||
end)
|
||||
local pos = vector.round(player:get_pos())
|
||||
for idx = 1, #unittests.list do
|
||||
local def = unittests.list[idx]
|
||||
if not def.done then
|
||||
|
@ -99,17 +99,24 @@ local function test_clear_meta(_, pos)
|
||||
end
|
||||
unittests.register("test_clear_meta", test_clear_meta, {map=true})
|
||||
|
||||
local on_punch_called
|
||||
minetest.register_on_punchnode(function()
|
||||
local on_punch_called, on_place_called
|
||||
core.register_on_placenode(function()
|
||||
on_place_called = true
|
||||
end)
|
||||
core.register_on_punchnode(function()
|
||||
on_punch_called = true
|
||||
end)
|
||||
unittests.register("test_punch_node", function(_, pos)
|
||||
minetest.place_node(pos, {name="basenodes:dirt"})
|
||||
local function test_node_callbacks(_, pos)
|
||||
on_place_called = false
|
||||
on_punch_called = false
|
||||
minetest.punch_node(pos)
|
||||
minetest.remove_node(pos)
|
||||
-- currently failing: assert(on_punch_called)
|
||||
end, {map=true})
|
||||
|
||||
core.place_node(pos, {name="basenodes:dirt"})
|
||||
assert(on_place_called, "on_place not called")
|
||||
core.punch_node(pos)
|
||||
assert(on_punch_called, "on_punch not called")
|
||||
core.remove_node(pos)
|
||||
end
|
||||
unittests.register("test_node_callbacks", test_node_callbacks, {map=true})
|
||||
|
||||
local function test_hashing()
|
||||
local input = "hello\000world"
|
||||
|
Loading…
Reference in New Issue
Block a user