Module unittest

Author: Zahary Karadjov

This module implements boilerplate to make testing easy.

Example:

suite "description for this stuff":
  test "essential truths":
    # give up and stop if this fails
    require(true)
  
  test "slightly less obvious stuff":
    # print a nasty message and move on, skipping
    # the remainder of this block
    check(1 != 1)
    check("asd"[2] == 'd')
  
  test "out of bounds error is thrown on bad access":
    let v = @[1, 2, 3]  # you can do initialization here
    expect(IndexError):
      discard v[4]
Reading settings

Types

TestStatus = enum 
  OK, FAILED
  Source
OutputLevel = enum 
  PRINT_ALL, PRINT_FAILURES, PRINT_NONE
  Source

Vars

abortOnError: bool
  Source
outputLevel: OutputLevel
  Source
colorOutput: bool
  Source

Procs

proc checkpoint(msg: string) {.raises: [], tags: [].}
  Source

Macros

macro check(conditions: stmt): stmt {.immediate.}
  Source
macro expect(exceptions: varargs[expr]; body: stmt): stmt {.immediate.}
  Source

Templates

template testSetupIMPL(): stmt {.immediate, dirty.}
  Source
template testTeardownIMPL(): stmt {.immediate, dirty.}
  Source
template suite(name: expr; body: stmt): stmt {.immediate, dirty.}
  Source
template test(name: expr; body: stmt): stmt {.immediate, dirty.}
  Source
template fail()
  Source
template require(conditions: stmt): stmt {.immediate, dirty.}
  Source