Skip to content
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

Add custom assertions #97

Closed
icamys opened this issue Jul 17, 2017 · 4 comments
Closed

Add custom assertions #97

icamys opened this issue Jul 17, 2017 · 4 comments

Comments

@icamys
Copy link

icamys commented Jul 17, 2017

It would be very nice to create custom assertions like this:

local luaunit = require('luaunit')

local msg = "Failed assertion on data set #%s"
local data = { ... }

for k, v in pairs(data) do
    -- the fourth parameter is custom assertion message
    luaunit.assertEquals(v.actual, v.expected, true, string.format(msg, k))
end
@bluebird75
Copy link
Owner

I need to give it some thought. I find the default assertion messages quite good already, not sure we need to have custom messages.

But for assertions inside a loop, you do have a point.

@icamys
Copy link
Author

icamys commented Aug 9, 2017

@bluebird75 The point is that if we have a fixture data set of 100 entries and we use a loop to run a test with those fixture entries and the test fails on 85th entry, it would be great to add to message at least the number of the entry.
At the moment we need to eliminate each of 100 entries to find the one that causes test failure

@bluebird75
Copy link
Owner

I am working on my own patch for this, with small changes to what you provided. I want to review this deeply because it affects a big number of functions.

@bluebird75
Copy link
Owner

Done with luaunit v3.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants