12. test blocks and dawn fmt

  • chapter 12 of 20
  • 1 min read

test "name" { ... } holds assertions written with assert; dawn test runs them, and dawn build strips them out. A test for a pure function needs no mocks at all:

fn add(a: Int, b: Int) -> Int = a + b

test "addition commutes" {
  assert add(2, 3) == add(3, 2)
  assert add(0, 5) == 5
}

pub fn main() -> Unit !io = println("ok")
ok

And finally: dawn fmt settles the code style (2-space indent, regular spacing), and dawn fmt --check is the form CI wants. Get into the habit of running dawn fmt before you commit, and code review never has to argue about whitespace again.

See also: spec.en.md §3.4, §1.8