mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-21 18:11:11 +00:00
Rename minetest.*
to core.*
in devtest
This commit is contained in:
parent
d849d51c2d
commit
88c7a54e08
78 changed files with 914 additions and 914 deletions
|
@ -1,31 +1,31 @@
|
|||
dofile(core.get_modpath(core.get_current_modname()) .. "/crafting_prepare.lua")
|
||||
|
||||
-- Test minetest.clear_craft function
|
||||
-- Test core.clear_craft function
|
||||
local function test_clear_craft()
|
||||
-- Clearing by output
|
||||
minetest.register_craft({
|
||||
core.register_craft({
|
||||
output = "foo",
|
||||
recipe = {{"bar"}}
|
||||
})
|
||||
minetest.register_craft({
|
||||
core.register_craft({
|
||||
output = "foo 4",
|
||||
recipe = {{"foo", "bar"}}
|
||||
})
|
||||
assert(#minetest.get_all_craft_recipes("foo") == 2)
|
||||
minetest.clear_craft({output="foo"})
|
||||
assert(minetest.get_all_craft_recipes("foo") == nil)
|
||||
assert(#core.get_all_craft_recipes("foo") == 2)
|
||||
core.clear_craft({output="foo"})
|
||||
assert(core.get_all_craft_recipes("foo") == nil)
|
||||
-- Clearing by input
|
||||
minetest.register_craft({
|
||||
core.register_craft({
|
||||
output = "foo 4",
|
||||
recipe = {{"foo", "bar"}}
|
||||
})
|
||||
assert(#minetest.get_all_craft_recipes("foo") == 1)
|
||||
minetest.clear_craft({recipe={{"foo", "bar"}}})
|
||||
assert(minetest.get_all_craft_recipes("foo") == nil)
|
||||
assert(#core.get_all_craft_recipes("foo") == 1)
|
||||
core.clear_craft({recipe={{"foo", "bar"}}})
|
||||
assert(core.get_all_craft_recipes("foo") == nil)
|
||||
end
|
||||
unittests.register("test_clear_craft", test_clear_craft)
|
||||
|
||||
-- Test minetest.get_craft_result function
|
||||
-- Test core.get_craft_result function
|
||||
local function test_get_craft_result()
|
||||
-- normal
|
||||
local input = {
|
||||
|
@ -33,12 +33,12 @@ local function test_get_craft_result()
|
|||
width = 2,
|
||||
items = {"", "unittests:coal_lump", "", "unittests:stick"}
|
||||
}
|
||||
minetest.log("info", "[unittests] torch crafting input: "..dump(input))
|
||||
local output, decremented_input = minetest.get_craft_result(input)
|
||||
minetest.log("info", "[unittests] torch crafting output: "..dump(output))
|
||||
minetest.log("info", "[unittests] torch crafting decremented input: "..dump(decremented_input))
|
||||
core.log("info", "[unittests] torch crafting input: "..dump(input))
|
||||
local output, decremented_input = core.get_craft_result(input)
|
||||
core.log("info", "[unittests] torch crafting output: "..dump(output))
|
||||
core.log("info", "[unittests] torch crafting decremented input: "..dump(decremented_input))
|
||||
assert(output.item)
|
||||
minetest.log("info", "[unittests] torch crafting output.item:to_table(): "..dump(output.item:to_table()))
|
||||
core.log("info", "[unittests] torch crafting output.item:to_table(): "..dump(output.item:to_table()))
|
||||
assert(output.item:get_name() == "unittests:torch")
|
||||
assert(output.item:get_count() == 4)
|
||||
|
||||
|
@ -48,10 +48,10 @@ local function test_get_craft_result()
|
|||
width = 1,
|
||||
items = {"unittests:coal_lump"}
|
||||
}
|
||||
minetest.log("info", "[unittests] coal fuel input: "..dump(input))
|
||||
output, decremented_input = minetest.get_craft_result(input)
|
||||
minetest.log("info", "[unittests] coal fuel output: "..dump(output))
|
||||
minetest.log("info", "[unittests] coal fuel decremented input: "..dump(decremented_input))
|
||||
core.log("info", "[unittests] coal fuel input: "..dump(input))
|
||||
output, decremented_input = core.get_craft_result(input)
|
||||
core.log("info", "[unittests] coal fuel output: "..dump(output))
|
||||
core.log("info", "[unittests] coal fuel decremented input: "..dump(decremented_input))
|
||||
assert(output.time)
|
||||
assert(output.time > 0)
|
||||
|
||||
|
@ -61,14 +61,14 @@ local function test_get_craft_result()
|
|||
width = 1,
|
||||
items = {"unittests:iron_lump"}
|
||||
}
|
||||
minetest.log("info", "[unittests] iron lump cooking input: "..dump(output))
|
||||
output, decremented_input = minetest.get_craft_result(input)
|
||||
minetest.log("info", "[unittests] iron lump cooking output: "..dump(output))
|
||||
minetest.log("info", "[unittests] iron lump cooking decremented input: "..dump(decremented_input))
|
||||
core.log("info", "[unittests] iron lump cooking input: "..dump(output))
|
||||
output, decremented_input = core.get_craft_result(input)
|
||||
core.log("info", "[unittests] iron lump cooking output: "..dump(output))
|
||||
core.log("info", "[unittests] iron lump cooking decremented input: "..dump(decremented_input))
|
||||
assert(output.time)
|
||||
assert(output.time > 0)
|
||||
assert(output.item)
|
||||
minetest.log("info", "[unittests] iron lump cooking output.item:to_table(): "..dump(output.item:to_table()))
|
||||
core.log("info", "[unittests] iron lump cooking output.item:to_table(): "..dump(output.item:to_table()))
|
||||
assert(output.item:get_name() == "unittests:steel_ingot")
|
||||
assert(output.item:get_count() == 1)
|
||||
|
||||
|
@ -79,12 +79,12 @@ local function test_get_craft_result()
|
|||
-- Using a wear of 60000
|
||||
items = {"unittests:repairable_tool 1 60000", "unittests:repairable_tool 1 60000"}
|
||||
}
|
||||
minetest.log("info", "[unittests] repairable tool crafting input: "..dump(input))
|
||||
output, decremented_input = minetest.get_craft_result(input)
|
||||
minetest.log("info", "[unittests] repairable tool crafting output: "..dump(output))
|
||||
minetest.log("info", "[unittests] repairable tool crafting decremented input: "..dump(decremented_input))
|
||||
core.log("info", "[unittests] repairable tool crafting input: "..dump(input))
|
||||
output, decremented_input = core.get_craft_result(input)
|
||||
core.log("info", "[unittests] repairable tool crafting output: "..dump(output))
|
||||
core.log("info", "[unittests] repairable tool crafting decremented input: "..dump(decremented_input))
|
||||
assert(output.item)
|
||||
minetest.log("info", "[unittests] repairable tool crafting output.item:to_table(): "..dump(output.item:to_table()))
|
||||
core.log("info", "[unittests] repairable tool crafting output.item:to_table(): "..dump(output.item:to_table()))
|
||||
assert(output.item:get_name() == "unittests:repairable_tool")
|
||||
-- Test the wear value.
|
||||
-- See src/craftdef.cpp in Luanti source code for the formula. The formula to calculate
|
||||
|
@ -100,12 +100,12 @@ local function test_get_craft_result()
|
|||
width = 2,
|
||||
items = {"unittests:unrepairable_tool 1 60000", "unittests:unrepairable_tool 1 60000"}
|
||||
}
|
||||
minetest.log("info", "[unittests] unrepairable tool crafting input: "..dump(input))
|
||||
output, decremented_input = minetest.get_craft_result(input)
|
||||
minetest.log("info", "[unittests] unrepairable tool crafting output: "..dump(output))
|
||||
minetest.log("info", "[unittests] unrepairable tool crafting decremented input: "..dump(decremented_input))
|
||||
core.log("info", "[unittests] unrepairable tool crafting input: "..dump(input))
|
||||
output, decremented_input = core.get_craft_result(input)
|
||||
core.log("info", "[unittests] unrepairable tool crafting output: "..dump(output))
|
||||
core.log("info", "[unittests] unrepairable tool crafting decremented input: "..dump(decremented_input))
|
||||
assert(output.item)
|
||||
minetest.log("info", "[unittests] unrepairable tool crafting output.item:to_table(): "..dump(output.item:to_table()))
|
||||
core.log("info", "[unittests] unrepairable tool crafting output.item:to_table(): "..dump(output.item:to_table()))
|
||||
-- unrepairable tool must not yield any output
|
||||
assert(output.item:is_empty())
|
||||
end
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
-- Registering some dummy items and recipes for the crafting tests
|
||||
|
||||
minetest.register_craftitem("unittests:torch", {
|
||||
core.register_craftitem("unittests:torch", {
|
||||
description = "Crafting Test Item: Torch",
|
||||
inventory_image = "unittests_torch.png",
|
||||
|
||||
groups = { dummy = 1 },
|
||||
})
|
||||
minetest.register_craftitem("unittests:coal_lump", {
|
||||
core.register_craftitem("unittests:coal_lump", {
|
||||
description = "Crafting Test Item: Coal Lump",
|
||||
inventory_image = "unittests_coal_lump.png",
|
||||
|
||||
groups = { dummy = 1 },
|
||||
})
|
||||
minetest.register_craftitem("unittests:stick", {
|
||||
core.register_craftitem("unittests:stick", {
|
||||
description = "Crafting Test Item: Stick",
|
||||
inventory_image = "unittests_stick.png",
|
||||
|
||||
groups = { dummy = 1 },
|
||||
})
|
||||
minetest.register_craftitem("unittests:iron_lump", {
|
||||
core.register_craftitem("unittests:iron_lump", {
|
||||
description = "Crafting Test Item: Iron Lump",
|
||||
inventory_image = "unittests_iron_lump.png",
|
||||
|
||||
groups = { dummy = 1 },
|
||||
})
|
||||
minetest.register_craftitem("unittests:steel_ingot", {
|
||||
core.register_craftitem("unittests:steel_ingot", {
|
||||
description = "Crafting Test Item: Steel Ingot",
|
||||
inventory_image = "unittests_steel_ingot.png",
|
||||
|
||||
|
@ -33,13 +33,13 @@ minetest.register_craftitem("unittests:steel_ingot", {
|
|||
|
||||
-- Use aliases in recipes for more complete testing
|
||||
|
||||
minetest.register_alias("unittests:steel_ingot_alias", "unittests:steel_ingot")
|
||||
minetest.register_alias("unittests:coal_lump_alias", "unittests:coal_lump")
|
||||
minetest.register_alias("unittests:iron_lump_alias", "unittests:iron_lump")
|
||||
core.register_alias("unittests:steel_ingot_alias", "unittests:steel_ingot")
|
||||
core.register_alias("unittests:coal_lump_alias", "unittests:coal_lump")
|
||||
core.register_alias("unittests:iron_lump_alias", "unittests:iron_lump")
|
||||
|
||||
-- Recipes for tests: Normal crafting, cooking and fuel
|
||||
|
||||
minetest.register_craft({
|
||||
core.register_craft({
|
||||
output = 'unittests:torch 4',
|
||||
recipe = {
|
||||
{'unittests:coal_lump_alias'},
|
||||
|
@ -47,26 +47,26 @@ minetest.register_craft({
|
|||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
core.register_craft({
|
||||
type = "cooking",
|
||||
output = "unittests:steel_ingot_alias",
|
||||
recipe = "unittests:iron_lump_alias",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
core.register_craft({
|
||||
type = "fuel",
|
||||
recipe = "unittests:coal_lump_alias",
|
||||
burntime = 40,
|
||||
})
|
||||
|
||||
-- Test tool repair
|
||||
minetest.register_craft({
|
||||
core.register_craft({
|
||||
type = "toolrepair",
|
||||
additional_wear = -0.05,
|
||||
})
|
||||
|
||||
-- Test the disable_repair=1 group
|
||||
minetest.register_tool("unittests:unrepairable_tool", {
|
||||
core.register_tool("unittests:unrepairable_tool", {
|
||||
description = "Crafting Test Item: Unrepairable Tool",
|
||||
inventory_image = "unittests_unrepairable_tool.png",
|
||||
tool_capabilities = {
|
||||
|
@ -79,7 +79,7 @@ minetest.register_tool("unittests:unrepairable_tool", {
|
|||
groups = { disable_repair = 1, dummy = 1 }
|
||||
})
|
||||
|
||||
minetest.register_tool("unittests:repairable_tool", {
|
||||
core.register_tool("unittests:repairable_tool", {
|
||||
description = "Crafting Test Item: Repairable Tool",
|
||||
inventory_image = "unittests_repairable_tool.png",
|
||||
tool_capabilities = {
|
||||
|
|
|
@ -193,7 +193,7 @@ dofile(modpath .. "/color.lua")
|
|||
|
||||
local function send_results(name, ok)
|
||||
core.chat_send_player(name,
|
||||
minetest.colorize(ok and "green" or "red",
|
||||
core.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."))
|
||||
|
@ -206,7 +206,7 @@ if core.settings:get_bool("devtest_unittests_autostart", false) then
|
|||
-- to write status information to the filesystem
|
||||
local old_on_finished = unittests.on_finished
|
||||
unittests.on_finished = function(ok)
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
for _, player in ipairs(core.get_connected_players()) do
|
||||
send_results(player:get_player_name(), ok)
|
||||
end
|
||||
test_results = ok
|
||||
|
@ -214,7 +214,7 @@ if core.settings:get_bool("devtest_unittests_autostart", false) then
|
|||
end
|
||||
coroutine.wrap(unittests.run_all)()
|
||||
end)
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
core.register_on_joinplayer(function(player)
|
||||
if test_results == nil then
|
||||
return -- tests haven't completed yet
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ local function compare_lists(a, b)
|
|||
end
|
||||
|
||||
local function test_inventory()
|
||||
local inv = minetest.create_detached_inventory("test")
|
||||
local inv = core.create_detached_inventory("test")
|
||||
|
||||
inv:set_lists({test = {""}})
|
||||
assert(inv:get_list("test"))
|
||||
|
@ -66,8 +66,8 @@ local function test_inventory()
|
|||
assert(compare_lists(before, after))
|
||||
|
||||
local location = inv:get_location()
|
||||
assert(minetest.remove_detached_inventory("test"))
|
||||
assert(not minetest.get_inventory(location))
|
||||
assert(core.remove_detached_inventory("test"))
|
||||
assert(not core.get_inventory(location))
|
||||
end
|
||||
|
||||
unittests.register("test_inventory", test_inventory)
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
local full_description = "Description Test Item\nFor testing item decription"
|
||||
minetest.register_tool("unittests:description_test", {
|
||||
core.register_tool("unittests:description_test", {
|
||||
description = full_description,
|
||||
inventory_image = "unittests_description_test.png",
|
||||
groups = { dummy = 1 },
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("item_description", {
|
||||
core.register_chatcommand("item_description", {
|
||||
param = "",
|
||||
description = "Show the short and full description of the wielded item.",
|
||||
func = function(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local player = core.get_player_by_name(name)
|
||||
local item = player:get_wielded_item()
|
||||
return true, string.format("short_description: %s\ndescription: %s",
|
||||
item:get_short_description(), item:get_description())
|
||||
|
@ -24,9 +24,9 @@ local function test_short_desc()
|
|||
local stack = ItemStack("unittests:description_test")
|
||||
assert(stack:get_short_description() == "Description Test Item")
|
||||
assert(get_short_description("unittests:description_test") == "Description Test Item")
|
||||
assert(minetest.registered_items["unittests:description_test"].short_description == nil)
|
||||
assert(core.registered_items["unittests:description_test"].short_description == nil)
|
||||
assert(stack:get_description() == full_description)
|
||||
assert(stack:get_description() == minetest.registered_items["unittests:description_test"].description)
|
||||
assert(stack:get_description() == core.registered_items["unittests:description_test"].description)
|
||||
|
||||
stack:get_meta():set_string("description", "Hello World")
|
||||
assert(stack:get_short_description() == "Hello World")
|
||||
|
|
|
@ -1,13 +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"})
|
||||
core.register_craftitem(":" .. itemname, {description = "foo"})
|
||||
assert(assert(core.registered_items[itemname]).description == "foo")
|
||||
core.override_item(itemname, {description = "bar"})
|
||||
assert(assert(core.registered_items[itemname]).description == "bar")
|
||||
core.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)
|
||||
assert(assert(core.registered_items[itemname]).description == "")
|
||||
core.unregister_item("unittests:test_override_item")
|
||||
assert(core.registered_items["unittests:test_override_item"] == nil)
|
||||
end
|
||||
|
|
|
@ -116,6 +116,6 @@ end
|
|||
unittests.register("test_item_metadata", test_item_metadata)
|
||||
|
||||
local function test_node_metadata(player, pos)
|
||||
test_metadata(minetest.get_meta(pos))
|
||||
test_metadata(core.get_meta(pos))
|
||||
end
|
||||
unittests.register("test_node_metadata", test_node_metadata, {map=true})
|
||||
|
|
|
@ -73,8 +73,8 @@ end
|
|||
unittests.register("test_v3f_metatable", test_v3f_metatable, {player=true})
|
||||
|
||||
local function test_v3s16_metatable(player, pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local found_pos = minetest.find_node_near(pos, 0, node.name, true)
|
||||
local node = core.get_node(pos)
|
||||
local found_pos = core.find_node_near(pos, 0, node.name, true)
|
||||
assert(vector.check(found_pos))
|
||||
end
|
||||
unittests.register("test_v3s16_metatable", test_v3s16_metatable, {map=true})
|
||||
|
@ -181,7 +181,7 @@ local function test_write_json()
|
|||
for i = 1, 1000 do
|
||||
data = {data}
|
||||
end
|
||||
local roundtripped = minetest.parse_json(minetest.write_json(data))
|
||||
local roundtripped = core.parse_json(core.write_json(data))
|
||||
for i = 1, 1000 do
|
||||
roundtripped = roundtripped[1]
|
||||
end
|
||||
|
@ -190,7 +190,7 @@ end
|
|||
unittests.register("test_write_json", test_write_json)
|
||||
|
||||
local function test_game_info()
|
||||
local info = minetest.get_game_info()
|
||||
local info = core.get_game_info()
|
||||
local game_conf = Settings(info.path .. "/game.conf")
|
||||
assert(info.id == "devtest")
|
||||
assert(info.title == game_conf:get("title"))
|
||||
|
@ -199,27 +199,27 @@ unittests.register("test_game_info", test_game_info)
|
|||
|
||||
local function test_mapgen_edges(cb)
|
||||
-- Test that the map can extend to the expected edges and no further.
|
||||
local min_edge, max_edge = minetest.get_mapgen_edges()
|
||||
local min_edge, max_edge = core.get_mapgen_edges()
|
||||
local min_finished = {}
|
||||
local max_finished = {}
|
||||
local function finish()
|
||||
if #min_finished ~= 1 then
|
||||
return cb("Expected 1 block to emerge around mapgen minimum edge")
|
||||
end
|
||||
if min_finished[1] ~= (min_edge / minetest.MAP_BLOCKSIZE):floor() then
|
||||
if min_finished[1] ~= (min_edge / core.MAP_BLOCKSIZE):floor() then
|
||||
return cb("Expected block within minimum edge to emerge")
|
||||
end
|
||||
if #max_finished ~= 1 then
|
||||
return cb("Expected 1 block to emerge around mapgen maximum edge")
|
||||
end
|
||||
if max_finished[1] ~= (max_edge / minetest.MAP_BLOCKSIZE):floor() then
|
||||
if max_finished[1] ~= (max_edge / core.MAP_BLOCKSIZE):floor() then
|
||||
return cb("Expected block within maximum edge to emerge")
|
||||
end
|
||||
return cb()
|
||||
end
|
||||
local emerges_left = 2
|
||||
local function emerge_block(blockpos, action, blocks_left, finished)
|
||||
if action ~= minetest.EMERGE_CANCELLED then
|
||||
if action ~= core.EMERGE_CANCELLED then
|
||||
table.insert(finished, blockpos)
|
||||
end
|
||||
if blocks_left == 0 then
|
||||
|
@ -229,34 +229,34 @@ local function test_mapgen_edges(cb)
|
|||
end
|
||||
end
|
||||
end
|
||||
minetest.emerge_area(min_edge:subtract(1), min_edge, emerge_block, min_finished)
|
||||
minetest.emerge_area(max_edge, max_edge:add(1), emerge_block, max_finished)
|
||||
core.emerge_area(min_edge:subtract(1), min_edge, emerge_block, min_finished)
|
||||
core.emerge_area(max_edge, max_edge:add(1), emerge_block, max_finished)
|
||||
end
|
||||
unittests.register("test_mapgen_edges", test_mapgen_edges, {map=true, async=true})
|
||||
|
||||
local finish_test_on_mapblocks_changed
|
||||
minetest.register_on_mapblocks_changed(function(modified_blocks, modified_block_count)
|
||||
core.register_on_mapblocks_changed(function(modified_blocks, modified_block_count)
|
||||
if finish_test_on_mapblocks_changed then
|
||||
finish_test_on_mapblocks_changed(modified_blocks, modified_block_count)
|
||||
finish_test_on_mapblocks_changed = nil
|
||||
end
|
||||
end)
|
||||
local function test_on_mapblocks_changed(cb, player, pos)
|
||||
local bp1 = (pos / minetest.MAP_BLOCKSIZE):floor()
|
||||
local bp1 = (pos / core.MAP_BLOCKSIZE):floor()
|
||||
local bp2 = bp1:add(1)
|
||||
for _, bp in ipairs({bp1, bp2}) do
|
||||
-- Make a modification in the block.
|
||||
local p = bp * minetest.MAP_BLOCKSIZE
|
||||
minetest.load_area(p)
|
||||
local meta = minetest.get_meta(p)
|
||||
local p = bp * core.MAP_BLOCKSIZE
|
||||
core.load_area(p)
|
||||
local meta = core.get_meta(p)
|
||||
meta:set_int("test_on_mapblocks_changed", meta:get_int("test_on_mapblocks_changed") + 1)
|
||||
end
|
||||
finish_test_on_mapblocks_changed = function(modified_blocks, modified_block_count)
|
||||
if modified_block_count < 2 then
|
||||
return cb("Expected at least two mapblocks to be recorded as modified")
|
||||
end
|
||||
if not modified_blocks[minetest.hash_node_position(bp1)] or
|
||||
not modified_blocks[minetest.hash_node_position(bp2)] then
|
||||
if not modified_blocks[core.hash_node_position(bp1)] or
|
||||
not modified_blocks[core.hash_node_position(bp2)] then
|
||||
return cb("The expected mapblocks were not recorded as modified")
|
||||
end
|
||||
cb()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue