Add & use modlib.assertdump

This commit is contained in:
Lars Mueller 2021-03-24 20:27:02 +01:00
parent 02f24dd59f
commit 2c051cc026
2 changed files with 10 additions and 4 deletions

@ -43,7 +43,12 @@ modlib = {
__newindex = function(_, index, value) __newindex = function(_, index, value)
return rawset(_G, index, value) return rawset(_G, index, value)
end end
}) }),
assertdump = function(v, value)
if not v then
error(dump(value))
end
end
} }
local function get_resource(modname, resource, ...) local function get_resource(modname, resource, ...)

@ -1,3 +1,5 @@
local assertdump = modlib.assertdump
-- string -- string
assert(modlib.string.escape_magic_chars"%" == "%%") assert(modlib.string.escape_magic_chars"%" == "%%")
@ -97,7 +99,7 @@ end
-- colorspec -- colorspec
local colorspec = modlib.minetest.colorspec.from_number(0xDDCCBBAA) local colorspec = modlib.minetest.colorspec.from_number(0xDDCCBBAA)
assert(modlib.table.equals(colorspec, {a = 0xAA, b = 0xBB, g = 0xCC, r = 0xDD,}), dump(colorspec)) assertdump(modlib.table.equals(colorspec, {a = 0xAA, b = 0xBB, g = 0xCC, r = 0xDD,}), colorspec)
-- k-d-tree -- k-d-tree
local vectors = {} local vectors = {}
@ -137,8 +139,7 @@ do
local remaining = input:read(1000) local remaining = input:read(1000)
assert(not remaining) assert(not remaining)
end) end)
-- TODO assertdump assertdump(modlib.table.equals_references(object, read) and not err, {
assert(modlib.table.equals_references(object, read) and not err, dump{
object = object, object = object,
read = read, read = read,
written = written and modlib.text.hexdump(written), written = written and modlib.text.hexdump(written),