Skip to content

Lightweight Lua library providing additional assert functions for common patterns.

License

Notifications You must be signed in to change notification settings

KwirkyJ/assertive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

assertive

Lightweight Lua library providing assert functions for common patterns. Requires the 'moretables' library.

API Reference

Module API

assertive:getDelta()

Returns the number that is the default allowed difference (delta) between two values when using assertAlmostEquals. Module loads with delta of 1e-12.

assertive:setDelta([d])

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.

assertive:getExpectedActual()

Returns a boolean whether assertEquals and assertNotEquals will use provided parameters as expected-actual rather than the default actual-expected.

assertive:setExpectedActual([bool])

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.

Assert Routines

assertive.assertError([[msg,] expmsg,] f, ...)

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.

assertive.assertEquals(actual, expected[, msg])

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).

assertive.assertAlmostEquals(actual, expected[, delta][, msg])

Tests that the difference between two numbers is not greater than a margin. If delta is nil, it defaults to assertive:getDelta().

assertive.assertNotEquals(a, b[, msg])

Tests that two values are not equivalent.

assertive.assert<Type>(a[, msg])

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.

assertive.assertNot<Type>(a[, msg])

Tests that the parameter a is not of a certain type.

About

Lightweight Lua library providing additional assert functions for common patterns.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages