Closed kcarl-adb closed 9 years ago
@o-lim: Technically, yes, you are correct. IMHO the has_error
method becomes effectively useless if you have any intervening catch/rethrow wrapper in place. This could easily change over the lifetime of the software being tested, thus rendering existing tests invalid merely due to an implementation detail. I'm not sure that's a desirable result.
@scouten there is no single way to wrap errors AFAIK. You can concatenate error messages, with or without some labels like "original error: ", you may or may not append original stacktrace, you can use a table instead of a string, etc. So IMHO it makes sense for has_error
to only handle the single "standard" error format.
On master has_error
returns the error on success, so you can use it to strip the error in the way you want:
local err = assert.has_error(f):gsub(".-:%d+: ", "")
assert.matches("original error", err)
agreed. closing request.
Doesn't Lua only throw errors with only one file/line (at the beginning of the message)? The only way to get multiple files/lines would be to catch and rethrow, right? In this case, wouldn't the extra files/lines, technically, be part of the error message being thrown?
So when you do
assert.has_error(func, msg)
, you are verifying thatmsg
is equal to what was passed toerror
, which in this case would be "myfile.lua:3: some error". So if you remove multiple occurrences of file/line, then you are no longer checking for a string passed toerror
, but a sub-string passed toerror
, in which caseerror_matches
(which checks against a Lua pattern) might be more appropriate.