Lightweight Lua library providing assert functions for common patterns. Requires the 'moretables' library.
Returns the number that is the default allowed difference (delta) between two values when using assertAlmostEquals
. Module loads with delta of 1e-12.
Sets the module's default delta. If d
is nil, resets to the built-in default of 1e-12. Raises an error if d
is neither a number nor nil.
Returns a boolean whether assertEquals
and assertNotEquals
will use provided parameters as expected-actual rather than the default actual-expected.
Sets the module's expectations for assertEquals
and assertNotEquals
as described above. If no parameter is given, defaults to false. An error is raised if bool
is neither true, false, nor nil.
This assert routine expects that the function f
will raise an error with the provided arguments ...
. msg
and expmsg
are so placed as to not be mistaken as arguments for the provided function.
In the case of assertError(f, ...)
, will pass if f(...)
raises an error.
In the case of assertError(expmsg, f, ...)
, will pass only if the error message generated by f(...)
matches that of expmsg
(must be a string).
In the case of assertError(msg, expmsg, f, ...)
, in event of failure as either of the above patterns, will use provided msg
as error message; expmsg
can be either nil (as in the first case, accepts any error message) or a string (as in second cast, messages must match).
Any other call pattern will raise an error.
Tests that two values are equivalent. If assertive:getExpectedActual()
is true, first two parameters are reversed. If msg
is a string literal, it will be the failure message in event that expected and actual are not equivalent (this msg
parameter behavior is shared with all following assert routines).
Tests that the difference between two numbers is not greater than a margin. If delta
is nil, it defaults to assertive:getDelta()
.
Tests that two values are not equivalent.
Tests that the parameter a
is of a certain type, e.g. assertFunction(assertive.assertNotEquals)
. Available types are: Nil, Boolean, Number, String, Table, Function, Thread, and Userdata.
Tests that the parameter a
is not of a certain type.