5.1.27. Testing with dastest

This tutorial covers the daslang testing framework: writing tests with [test], assertion functions, sub-tests, and running tests.

5.1.27.1. Setup

Import the testing framework:

require dastest/testing_boost public

5.1.27.2. Writing tests

Annotate functions with [test]. Each test receives a T? context:

[test]
def test_arithmetic(t : T?) {
    t |> equal(2 + 2, 4)
    t |> equal(3 * 3, 9, "multiplication")
}

5.1.27.3. Assertions

Function

Behavior

t |> equal(a, b)

Check a == b; non-fatal on failure

t |> strictEqual(a, b)

Check a == b; fatal on failure (stops test)

t |> success(cond)

Check condition is truthy; non-fatal

t |> failure("msg")

Always fails; non-fatal

t |> accept(value)

Suppress unused warnings (no assertion)

All assertion functions accept an optional message string as the last argument.

5.1.27.4. Sub-tests

Group related checks with run:

[test]
def test_strings(t : T?) {
    t |> run("concat") @@(t : T?) {
        t |> equal("ab" + "cd", "abcd")
    }
    t |> run("length") @@(t : T?) {
        t |> equal(length("hello"), 5)
    }
}

Use @@(t : T?) { ... } (no-capture lambda) for the callback.

5.1.27.5. Running tests

From the command line:

daslang.exe dastest/dastest.das -- --test path/to/test.das

To test an entire directory:

daslang.exe dastest/dastest.das -- --test path/to/tests/