mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Deprecate function support in core.[de]serialize
This commit is contained in:
parent
f2ea4a4565
commit
dd2e45ee82
5 changed files with 78 additions and 22 deletions
|
@ -93,21 +93,49 @@ describe("serialize", function()
|
|||
assert_preserves(test_in)
|
||||
end)
|
||||
|
||||
it("strips functions in safe mode", function()
|
||||
local test_in = {
|
||||
func = function(a, b)
|
||||
error("test")
|
||||
end,
|
||||
foo = "bar"
|
||||
}
|
||||
setfenv(test_in.func, _G)
|
||||
describe("safe mode", function()
|
||||
setup(function()
|
||||
assert(not core.log)
|
||||
-- logging a deprecation warning will be attempted
|
||||
function core.log() end
|
||||
end)
|
||||
teardown(function()
|
||||
core.log = nil
|
||||
end)
|
||||
it("functions are stripped", function()
|
||||
local test_in = {
|
||||
func = function(a, b)
|
||||
error("test")
|
||||
end,
|
||||
foo = "bar"
|
||||
}
|
||||
setfenv(test_in.func, _G)
|
||||
|
||||
local str = core.serialize(test_in)
|
||||
assert.not_nil(str:find("loadstring"))
|
||||
local str = core.serialize(test_in)
|
||||
assert.not_nil(str:find("loadstring"))
|
||||
|
||||
local test_out = core.deserialize(str, true)
|
||||
assert.is_nil(test_out.func)
|
||||
assert.equals(test_out.foo, "bar")
|
||||
local test_out = core.deserialize(str, true)
|
||||
assert.is_nil(test_out.func)
|
||||
assert.equals(test_out.foo, "bar")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("deprecation warnings", function()
|
||||
before_each(function()
|
||||
assert(not core.log)
|
||||
core.log = spy.new(function(level)
|
||||
assert(level == "deprecated")
|
||||
end)
|
||||
end)
|
||||
after_each(function()
|
||||
core.log = nil
|
||||
end)
|
||||
it("dumping functions", function()
|
||||
local t = {f = function() end, g = function() end}
|
||||
t.t = t
|
||||
core.serialize(t)
|
||||
assert.spy(core.log).was.called(1) -- should have been called exactly *once*
|
||||
end)
|
||||
end)
|
||||
|
||||
it("vectors work", function()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue