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.

Available since: v0.0.1

assertDoesNotThrow

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

Available since: v0.0.1

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.

Available since: v0.0.1

assertEqualBooleans

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

Available since: v0.0.1

assertEqualBytes

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

Available since: v0.0.1

assertEqualFunctions

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

Available since: v0.0.1

assertEqualNumbers

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

Available since: v0.0.1

assertEqualPointers

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

Available since: v0.0.1

assertEqualStrings

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

Available since: v0.0.1

assertEqualTables

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

Available since: v0.0.1

assertFailure

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

Available since: v0.0.1

assertFalse

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

Available since: v0.0.1

assertNil

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

Available since: v0.0.1

assertThrows

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

Available since: v0.0.1

assertTrue

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

Available since: v0.0.1

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