3.78. 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:

:TEST.require_from('kink/test/')
:CONTROL.require_from('kink/')

:Tests <- TEST.collect_in{
  TEST.test('10 + 20 == 30'){
    :Sum = 10 + 20
    Sum == 30 || raise('got {}'.format(Sum.repr))
  }
  TEST.group('Num.op_mul'){
    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))
    }
  }
}

Tests.each{(:T)
  CONTROL.try(
    { T.run }
    { stdout.print_line('OK! [{}]'.format(T.addr)) }
    {(:Exc)
      stdout.print_line('Failed: {} [{}]'.format(Exc.message T.addr))
    }
  )
}
# Output:
#   OK! [@all; 10 + 20 == 30]
#   OK! [@all; Num.op_mul; 10 * 20 == 200]
#   OK! [@all; Num.op_mul; 20 * 30 == 600]

3.78.1. TEST.test(Name $test_thunk)

Registers a test to the current collecting session.

3.78.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.78.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.78.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.78.5. TEST.collect_in($thunk)

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

3.78.6. type test

A test case.

Test.run

Calls the test thunk.

Test.addr_parts

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.group('FOO.bar'){
      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"]

Test.addr

Returns the addr representation of this test.

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

Test.repr

`repr` returns the str representation of the test, such as "(test @all; mod FOO; FOO.bar; returns 42)".

3.78.7. TEST.is?(Val)

TEST.is? returns whether Val is a test.