Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Test

Source: lib/test.x

Guide: Testing Your Project

Registered tests and assertions for user programs.

Include it with #include "test.x".

It defines the $test, $test.main, $expect, $expect_eq, and $expect_raises macros; Testing your project describes them.

Primary API

FunctionSummary
Test.checkRecords a failed condition with its source text and location.
Test.compareCompares boxed values and records their representations on failure.
Test.mainRuns registered tests, returning 1 on failure or 2 for an unmatched filter.
Test.registerRegisters a function, its name, and the location of its decoration.
Test.skipMarks the running test skipped and stops its body.

Test

Test.check

void Test.check(int condition, String expression, String file, int line)

Records a failed condition with its source text and location.

Source: lib/test.x

Test.compare

void Test.compare(Var actual, Var expected, String file, int line)

Compares boxed values and records their representations on failure. Two differing multiline Strings also produce a unified difference.

Source: lib/test.x

Test.main

int Test.main(int argc, char **argv)

Runs registered tests, returning 1 on failure or 2 for an unmatched filter. --filter TEXT is repeatable and selects names containing any filter; --list prints selected names; --quiet omits passing lines. Unmatched filters print a zero-test summary, including with --list.

Source: lib/test.x

Test.register

void Test.register(const char *name, TestFunction function, const char *file, int line)

Registers a function, its name, and the location of its decoration. $test calls this before main, preserving declaration order.

Source: lib/test.x

Test.skip

void Test.skip(String reason)

Marks the running test skipped and stops its body.

Source: lib/test.x

Public types

TypeKindSummary
TestaliasThe receiverless owner of registered tests and their assertions.
TestFunctioncallbackA registered test has no arguments and returns no value.

Test

typedef Symbol Test

The receiverless owner of registered tests and their assertions.

Source: lib/test.x

TestFunction

typedef void (*TestFunction)(void)

A registered test has no arguments and returns no value.

Source: lib/test.x