Insulation does not recover globals set to nil
Henkoglobin opened this issue · comments
Noticed this while testing the behaviour of my code when running in a sandbox (i.e. checking if load
/loadstring
/io
are available): busted will delete globals set in an insulated block, but it won't recover values that are set to nil in a block. I've created a minimal, reproducible example to verify this behaviour:
describe("insulation", function()
insulate("when value is set to nil", function()
it("is there in the first place", function()
assert.is_not_nil(io)
end)
it("is set to nil", function()
_G.io = nil
assert.is_nil(io)
end)
end)
it("is restoring values afterwards", function()
assert.is_not_nil(io)
end)
end)
According to the documentation,
Test environment insulation saves the global table _G and any currently loaded packages package.loaded, restoring them to their original state at the completion of the insulate block.
so I would expect io
to be reset to its original value (the io library) after the insulate
block, so that all tests should succeed. They don't, however:
$ busted mre.lua
●●◼
2 successes / 1 failure / 0 errors / 0 pending : 0.002791 seconds
Failure → mre.lua @ 13
insulation is restoring values afterwards
mre.lua:14: Expected objects to not be the same.
Passed in:
(nil)
Did not expect:
type nil
I feel that this issue is similar to #534 in nature, but still distinct.
Nice issue number ;-) The devil is in the nil!