make a (shallow) copy of table params

this improves introspection capabilities since the table is snapshotted
at the time of the mock call
develop
myk002 2022-02-18 11:02:55 -08:00 committed by Myk
parent 9f86ed03df
commit e531346968
1 changed files with 10 additions and 1 deletions

@ -91,7 +91,16 @@ function mock.func(...)
setmetatable(f, {
__call = function(self, ...)
self.call_count = self.call_count + 1
table.insert(self.call_args, {...})
local args = {...}
for i,v in ipairs(args) do
if type(v) == 'table' then
-- just a shallow copy, but it offers some ability to
-- inspect original values in tables that were altered after
-- the call
args[i] = copyall(v)
end
end
table.insert(self.call_args, args)
return table.unpack(self.return_values)
end,
})