Skip to content

test

Utilities for writing and running test suites.

Types

TypeDescription
Skip Exception thrown to skip a test case.

Functions

fixture wrap

Defines a test fixture. wrap should be a function which accepts a block and invokes it with surrounding setup and teardown logic.

Returns

A function suitable for use as a decorator on a test function.

Example
#[fixture]
def example_fixture block
  setup()
  try
    block()
  finally
    teardown()

#[test]
#[example_fixture]
def example_test()
  do_something()

test :name? func?

Register a test case that runs func with no arguments. name, if unspecified, defaults to the Str coercion of func, which for defs is simply the function name. This function is suitable for use as a decorator:

#[test]
def the_test()
  do_something()

#[test name: "alternate_name"]
def overriden_name()
  do_something_else()
Returns

If func is not specified, returns a function that takes the test case function instead (for use as a decorator). Otherwise, returns func

skip msg?

Skip the current test with an optional message.

assert cond msg?

Assert that cond is truthy, throwing an error with optional msg on failure.

assert_not cond msg?

Assert that cond is falsy, throwing an error with optional msg on failure.

assert_eq left right msg?

Assert that left == right, throwing an error with optional msg on failure.

assert_ne left right msg?

Assert that left != right, throwing an error with optional msg on failure.

assert_throws type :msg? block

Assert that block throws an error of type, throwing an error with optional msg otherwise. The caught error is returned for further inspection if desired.

assert_type expected value msg?

Assert that value is of type expected (including a subtype), throwing an error with optional msg otherwise.

run :jobs? :module_jobs? :filter? :timeout? ...paths

Runs tests discovered under the trailing file and directory paths.