Unbreak ReaderFooter test

Tests: Update the ffi.metatype wrapper

(Better idea: move to busted master).
This commit is contained in:
NiLuJe
2021-05-18 05:46:05 +02:00
parent 189035cafc
commit 6dc1c1efca
3 changed files with 173 additions and 75 deletions

View File

@@ -1,12 +1,37 @@
-- don't try to overwrite metatables so we can use --auto-insulate-tests
-- shamelessly copied from https://github.com/Olivine-Labs/busted/commit/db6d8b4be8fd099ab387efeb8232cfd905912abb
local ffi = require "ffi"
local old_metatype = ffi.metatype
local exists = {}
ffi.metatype = function(def, mttable)
if exists[def] then return exists[def] end
exists[def] = old_metatype(def, mttable)
return exists[def]
-- Check if we're running a busted version recent enough that we don't need to deal with the LuaJIT hacks...
-- That currently means > 2.0.0 (i.e., scm-2, which isn't on LuaRocks...).
local busted_ok = false
for name, _ in pairs(package.loaded) do
if name == "busted.luajit" then
busted_ok = true
break
end
end
-- Don't try to overwrite metatables so we can use --auto-insulate-tests
-- Shamelessly copied from https://github.com/Olivine-Labs/busted/commit/2dfff99bda01fd3da56fd23415aba5a2a4cc0ffd
if not busted_ok then
local ffi = require "ffi"
local original_metatype = ffi.metatype
local original_store = {}
ffi.metatype = function (primary, ...)
if original_store[primary] then
return original_store[primary]
end
local success, result, err = pcall(original_metatype, primary, ...)
if not success then
-- hard error was thrown
error(result, 2)
end
if not result then
-- soft error was returned
return result, err
end
-- it worked, store and return
original_store[primary] = result
return result
end
end
require "defaults"