Testing¶
Tests describe behavior you want to keep working. Mark a function with @test, use assertions to check its results, and run it with dreamer test or dream test. A failed assertion stops the test and reports the problem.
Import: import system.testing;
Mark tests with @test, then run dream test or dreamer test. A failed assertion prints a message and exits (no exceptions).
@test is for a top-level fun name(): void or async fun name(): void, never main. Test files must not declare main. Put tests in a test project (type = "test") or a package's tests/ folder; see Test a project.
@timeout(ms) sets a limit for one test. There is no default limit.
dream test builds one runner that calls Test.run for each test. You can also call it from your own main:
Test.run(name, body) prints RUN <name> before the body and PASS <name> after it. When the body leaves more live objects than it found, it prints LEAK <name> live=+N first. Test.run_with_timeout(name, ms, body) also prints the limit (RUN <name> timeout=<ms>); dream test enforces it.
| Call | Meaning |
|---|---|
Assert.eq / Assert.ne |
equal / not equal |
Assert.is_true / is_false |
bool |
Assert.approx(a, b, eps) |
floats |
Assert.eq |
strings |
Assert.fail(message) |
fail now |