-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE: Assert equal for tables #7
Comments
I think it's better to integrate the assert lib: it would solve more problems with asserts in u-test |
I like this feature and actually implemented something similar in my own version of u-test, but on the other hand I like the simplicity of this library. How about allowing library users to override how assertion parameters are displayed? Then it would be easy to use inspect or any other custom display code while keeping u-test simple and sane. |
You can use recently added "Custom assertions" and craft something like. local function tables_equal(tbl1, tbl2)
if not (inspect(tbl1) == inspect(tbl2)) then
local failure_msg = inspect(tbl1) .. " ~= " .. inspect(tbl2)
return false, msg
end
end
test.register_assert("tables_equal", tables_equal) P.S.
Implementation assumes |
As far as I remeber lua does not have metamethod for 'not equal' operation. So '~=' becomes 'not __eq' as you expected. |
An assertion for tables the does a deep comparison.
Also, if the error messages could serialize tables that would be nice too.
Right now it just shows
table: 0x7fac41603780 ~= table: 0x7fac41700130
.The inspect library is good for this.
The text was updated successfully, but these errors were encountered: