lunarmodules / luassert

Assertion library for Lua
MIT License
202 stars 76 forks source link

Match._ throws error #179

Closed 0xWaleed closed 1 year ago

0xWaleed commented 2 years ago

https://github.com/Olivine-Labs/luassert/blob/36fc3af9621696a9dfcf71c0bcd25cdbc9475cf8/src/formatters/init.lua#L215

Greeting all, This is seems not right, it throws error when I use a spy like this

assert.spy(spied_function).was_called_with('text-value', match._)

it says "attempt to index a nil value (field 'arguments')"

when I comment all

- for idx = 1, arg.arguments.n do
-    table.insert(args, assert:format({ arg.arguments[idx], n = 1, })[1])
- end

+ -- for idx = 1, arg.arguments.n do
+ --    table.insert(args, assert:format({ arg.arguments[idx], n = 1, })[1])
+ -- end

and I go to luassert\match.lua and I add

- _ = setmetatable({mod=true, callback=function() return true end}, matcher_mt),
+ _ = setmetatable({mod=true, callback=function() return true end, name = 'any'}, matcher_mt),

it works fine and refer to _ as any

Expected:
(values list) ((string) 'text-value', (matcher) is.any())

just wanted to point to this issue and thanks for adding the new clear and detailed error output for each argument when using called_with function.