mock.patch(): propagate return values

develop
lethosor 2021-04-09 00:41:39 -04:00
parent f25b8a0d14
commit 5424392273
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
2 changed files with 10 additions and 2 deletions

@ -34,7 +34,7 @@ function mock.patch(...)
table.insert(patches, p) table.insert(patches, p)
end end
dfhack.with_finalize( return dfhack.with_finalize(
function() function()
for _, p in ipairs(patches) do for _, p in ipairs(patches) do
p.table[p.key] = p.old_value p.table[p.key] = p.old_value
@ -44,7 +44,7 @@ function mock.patch(...)
for _, p in ipairs(patches) do for _, p in ipairs(patches) do
p.table[p.key] = p.new_value p.table[p.key] = p.new_value
end end
callback() return callback()
end end
) )
end end

@ -90,3 +90,11 @@ function test.patch_complex_key()
end) end)
expect.eq(t[key], 'value') expect.eq(t[key], 'value')
end end
function test.patch_callback_return_value()
local a, b = mock.patch({}, 'k', 'v', function()
return 3, 4
end)
expect.eq(a, 3)
expect.eq(b, 4)
end