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)
end
dfhack.with_finalize(
return dfhack.with_finalize(
function()
for _, p in ipairs(patches) do
p.table[p.key] = p.old_value
@ -44,7 +44,7 @@ function mock.patch(...)
for _, p in ipairs(patches) do
p.table[p.key] = p.new_value
end
callback()
return callback()
end
)
end

@ -90,3 +90,11 @@ function test.patch_complex_key()
end)
expect.eq(t[key], 'value')
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