Slide 35 of 37

Testing

type Item {
	name:  Str
	price: Int
}

func total(items: Item[]): Int {
	mut sum := 0
	for each item in items {
		sum = sum + item.price
	}
	return sum
}

test "an empty cart costs nothing" {
	Item[0] empty = []
	assert total(empty) == 0
}

test "two items add up" {
	assert total([Item("wax", 5), Item("comb", 3)]) == 8
}
A test is a top-level declaration, named in prose because the name is documentation rather than something anything calls. `hive test entrypoint.hive` runs every test the entrypoint reaches, with no framework and no assertion vocabulary beyond the assert the language already has — and reports coverage, including which declarations were never exercised, on every run without a separate flag. This file has no main at all — a file holding only tests needs none — so it runs with `hive test`, not `hive run`.