3.55. kink/test/TEST

Mod for tests.

Tests are collected in the invocation of TEST.collect_in. TEST.collect_in returns a list of the tests collected in the invocation. This invocation is called a collecting session.

A test is registered to the current collecting session by calling TEST.test.

TEST.group can be used to group tests in the collecting session. Groups can be nested. There is a group named "@all" on the root of the collectiong session.

Each test can be run individually.

Usage example:

:Tests = TEST.collect_in{
  TEST.test('10 + 20 == 30'){
    :Sum = 10 + 20
    Sum == 30 || raise('got {}'.format(Sum.repr))
    TEST.test('10 * 20 == 200'){
      :Prod = 10 * 20
      Prod == 200 || raise('got {}'.format(Prod.repr))
    TEST.test('20 * 30 == 600'){
      :Prod = 20 * 30
      Prod == 600 || raise('got {}'.format(Prod.repr))
:Succ_tests = []
:Failed_tests = []
  { T.run }.try(
    { Succ_tests.push_back(T.addr) }
    { Failed_tests.push_back(T.addr) }

3.55.1. TEST.test(Name $test_thunk)

Registers a test to the current collecting session.

3.55.2. TEST.ignore_test(Name $test_thunk)

Registers a test to the current collecting session, under a group named "@ignore".

Invocation of this fun is invoking TEST.group('@ignore'){ TEST.test(Name $test_thunk) }.

3.55.3. TEST.group(Group_name $thunk)

Collects tests and subgroups within the invocation of $thunk.

It must be called in an invocation of TEST.collect_in.

3.55.4. TEST.ignore_group(Name $thunk)

Collects tests and subgroups within the invocation of $thunk, under a group named "@ignore".

Invocation of this fun is equivalent to invoke TEST.group('@ignore'){ TEST.group(Group_name $thunk) }.

3.55.5. TEST.collect_in($thunk)

Opens a collecting session within the $thunk, then returns the registered tests.

3.55.6. Type test

A test case.


Calls the test thunk.


Vec of the names of the groups and the test.

The group names appear from shallower ones to deeper ones. The test name appears as the last part.

In the next program, the test named “returns 42” is in the group “FOO.bar”, which is in the super group “mod FOO”. Adding to that, all the tests are contained in a group "@all". Therefore, Test.addr_parts returns ["@all" "mod FOO" "FOO.bar" "returns 42"].

:Tests = TEST.collect_in{
  TEST.group('mod FOO'){
      TEST.test('returns 42'){
        :Result = FOO.bar
        Result == 42 || raise('got {}'.format(Result.repr))
:Test = Tests.front
stdout.print_line(Test.addr_parts.repr) # => ["@all" "mod FOO" "FOO.bar" "returns 42"]


Returns the addr representation of this test.

It concatenates the groups and the name, such as "@all; mod FOO; FOO.bar; returns 42".


Returns the str representation of the test, such as "Test(mod FOO; FOO.bar; returns 42)".