--
local function TERMINAL_HANDLER(e, test, msg) if e
nil or not deepeq(v, b[k]) then return false end end for k,v in pairs(b) do if a[k]
-- Compatibility for Lua 5.1 and Lua 5.2local function args(...) return end
local function spy(f) local s = setmetatable(s,) return send
return function(handler, env)
local pendingtests =
local function runpending if pendingtests[1] ~= nil then pendingtests[1](runpending) end end
local function test(name, f, async) local testfn = function(next)
local prev =
local restore = function env.ok = prev.ok env.spy = prev.spy env.eq = prev.eq env.gambiarrahandler('end', name) table.remove(pendingtests, 1) if next then next end end
local handler = env.gambiarrahandler
env.eq = deepeq env.spy = spy env.ok = function(cond, msg) if cond then handler('pass', name, msg) else handler('fail', name, msg) end end
handler('begin', name); local ok, err = pcall(f, restore) if not ok then handler('except', name, err) end
if not async then handler('end', name); env.ok = prev.ok; env.spy = prev.spy; env.eq = prev.eq; end end
if not async then testfn else table.insert(pendingtests, testfn) if #pendingtests
env = env or _G env.gambiarrahandler = handler or TERMINAL_HANDLER
env.test = testend