Skip to content

Commit

Permalink
Some refactoring to make it easier to add new functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
HHHartmann committed Jan 19, 2020
1 parent e5f0299 commit a063d7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions lua_tests/gambiarra/gambiarra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ local function runpending()
if pendingtests[1] ~= nil then pendingtests[1](runpending) end
end

local function copyenv(dest, src)
dest.eq = src.eq
dest.spy = src.spy
dest.ok = src.ok
dest.nok = src.nok
end

return function(name, f, async)
if type(name) == 'function' then
gambiarrahandler = name
Expand All @@ -71,16 +78,11 @@ return function(name, f, async)

local testfn = function(next)

local prev = {
ok = env.ok,
spy = env.spy,
eq = env.eq
}
local prev = {}
copyenv(prev, env)

local restore = function()
env.ok = prev.ok
env.spy = prev.spy
env.eq = prev.eq
copyenv(env, prev)
gambiarrahandler('end', name)
table.remove(pendingtests, 1)
if next then next() end
Expand Down Expand Up @@ -113,9 +115,7 @@ return function(name, f, async)

if not async then
handler('end', name);
env.ok = prev.ok;
env.spy = prev.spy;
env.eq = prev.eq;
copyenv(env, prev)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lua_tests/gambiarra/gambiarra_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ metatest('simple assert passes', function()
end, {'2==2'}, {})

metatest('simple negative assert fails', function()
ok(2 == 2, '2==2')
nok(2 == 2, '2==2')
end, {}, {'2==2'})

metatest('simple assert fails', function()
Expand All @@ -71,7 +71,7 @@ end, {'1~=2'}, {})
metatest('ok without a message', function()
ok(1 == 1)
ok(1 == 2)
end, {'gambiarra_test.lua:64'}, {'gambiarra_test.lua:65'})
end, {'gambiarra_test.lua:72'}, {'gambiarra_test.lua:73'})

--
-- Equality tests
Expand Down

0 comments on commit a063d7d

Please sign in to comment.