Skip to main content

assertions

Builtin assertion library designed for more convenient unit testing

Status

Experimental: Functionality may change for any reason, without semantic versioning guarantees

Availability

This module is preloaded. You can simply require it:

local assertions = require("assertions")

Functions

assertCallsFunction

Raises an error if the function passed doesn't call the target function. The function has to be executed in order to determine this fact.

assertDoesNotThrow

Raises an error if the function passed throws (raises an error) itself. The purpose of this is to generate standardized error messages.

assertEquals

Raises an error if the two passed values are not identical. This is a catch-all handler that uses the more specialized assertions internally.

assertEqualBooleans

Raises an error if the two passed values do not represent the same boolean value.

assertEqualBytes

Raises an error if the two passed values do not represent the same cdata bytes. Use assertEqualPointers to compare only the pointer.

assertEqualFunctions

Raises an error if the two passed values do not represent the same function value.

assertEqualNumbers

Raises an error if the two passed values do not represent the same number value. The optional delta allows for float comparisons.

assertEqualPointers

Raises an error if the two passed values do not represent the same cdata pointer. Use assertEqualBytes to compare them by value.

assertEqualStrings

Raises an error if the two passed values do not represent the same string value. Supports LuaJIT string buffers and cdata strings.

assertEqualTables

Raises an error if the two passed values do not represent the same table value. Supports deep table comparisons.

assertFailure

Raises an error if the function passed does not return a "failure" type (nil and an error message).

assertFalse

Raises an error if the value passed is not exactly false.

assertNil

Raises an error if the value passed is not exactly nil.

assertThrows

Raises an error if the function passed does not itself raise an error (with the expected error message).

assertTrue

Raises an error if the value passed is not exactly true.

export

Exports all of the assertions in this module to the global Lua environment. Use this if you don't want to require them in every test.

Changelog

VersionWhat happened?
v0.0.1Initial release