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.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 |
|---|---|
|
Check |
|
Check |
|
Check condition is truthy; non-fatal |
|
Always fails; non-fatal |
|
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/
See also
Full source: tutorials/language/27_testing.das
Next tutorial: LINQ — Language-Integrated Query