luvit icon indicating copy to clipboard operation
luvit copied to clipboard

luvit/tap - `unexpect` function calls

Open ghost opened this issue 10 years ago • 4 comments

It would be nice to have an unexpect companion to expect - if that function is ever called, it is always an error.

It is currently possible to use function(...) assert(false, ...) end instead of unexpect, but that throws ugly "Uncaught Error"s.

ghost avatar Nov 19 '15 18:11 ghost

No need for assert(false, ...) just do error(...). I don't see how an unexpect would help, it would just internally call error() right?

creationix avatar Nov 30 '15 18:11 creationix

An unwrapped function() with an error() will kill the process, won't it? (Which would not be very nice, as it would not allow the following tests to run.) Additionally unexpected(error_message) would be a little bit more explicit, IMO.

ghost avatar Dec 01 '15 10:12 ghost

I think a simple error("this should not have happened because...") is plenty explicit. The issue about uncaught errors causing fatal exist is a problem though. I'll think about a way to solve this.

creationix avatar Dec 02 '15 03:12 creationix

Maybe the failed-test-notification logic with which expect() deals with error()s could be replicated somehow for functions that are not expected to be executed. But that would probably mean implementing something like unexpected().

ghost avatar Dec 02 '15 10:12 ghost