nupp.test

Assertions shared by Nupp's bundled test runner and project test suites.

Every failure names the values that differed. The functions return their successful input where that is useful, so an assertion may narrow or validate a value without forcing the caller to spell it twice.

Module contents

Functions

FunctionKindDescription
assertfunctionRequires a truthy value and returns its complete input pack.
equalfunctionRequires two values to be equal and returns the actual value.
isSkipfunctionAnswers whether a caught error is a skip raised by this module.
matchesfunctionRequires a string value containing a Lua pattern and returns the string.
notEqualfunctionRequires two values to differ and returns the actual value.
raisesfunctionRequires a callback to raise and returns its error value.
skipfunctionSkips the current test case with a reason.
skipReasonfunctionReturns the reason carried by a skip error.

Functions#

assertfunction#

function assert(value: any, ...: any): any

Requires a truthy value and returns its complete input pack.

Arguments

NameTypeDescription
valueany
...any

Returns

TypeDescription
any

Raises

  • when value is false or nil

equalfunction#

function equal(actual: any, expected: any, message: string?): any

Requires two values to be equal and returns the actual value.

Arguments

NameTypeDescription
actualany
expectedany
messagestring?

Returns

TypeDescription
any

Raises

  • when actual and expected differ

isSkipfunction#

function isSkip(value: any): boolean

Answers whether a caught error is a skip raised by this module.

Arguments

NameTypeDescription
valueany

Returns

TypeDescription
boolean

matchesfunction#

function matches(value: any, pattern: string, message: string?): string

Requires a string value containing a Lua pattern and returns the string.

Arguments

NameTypeDescription
valueany
patternstring
messagestring?

Returns

TypeDescription
string

Raises

  • when value is not a string or does not contain pattern

notEqualfunction#

function notEqual(actual: any, unwanted: any, message: string?): any

Requires two values to differ and returns the actual value.

Arguments

NameTypeDescription
actualany
unwantedany
messagestring?

Returns

TypeDescription
any

Raises

  • when actual and unwanted are equal

raisesfunction#

function raises(fn: function(...: any): any, pattern: string?): any

Requires a callback to raise and returns its error value.

Arguments

NameTypeDescription
fnfunction(...: any): any
patternstring?

Returns

TypeDescription
any

Raises

  • when the callback returns, or its error does not match pattern

skipfunction#

function skip(reason: string): never

Skips the current test case with a reason.

Arguments

NameTypeDescription
reasonstring

Returns

TypeDescription
never

skipReasonfunction#

function skipReason(value: any): string?

Returns the reason carried by a skip error.

Arguments

NameTypeDescription
valueany

Returns

TypeDescription
string?