Language reference · section 13
13. Tests and assertions
Feature: Tests
Scenario: A test block is left out of a normal build
Given a file with a test "doubles small numbers"
When the file is built normally
Then the test code is not in the output
Scenario: A test passes unless it throws
Given a test whose body does not throw
When pin test runs the test
Then the test prints ok
Scenario: assert throws when the condition is false
Given the code "assert double(2) is 4" where double(2) is 5
Then the program throws Error("assertion failed: double(2) is 4")
Scenario: A test block is allowed only at the top level
Given a test block inside a function
Then the compiler reports an error "a `test` block must be at the top level of the file"
Scenario: pin test exits with 1 when a test fails
Given a file with a failing test
When the author runs pin test file.pin
Then the command exits with 1
fn double(n: int): int:
return n * 2
test "doubles small numbers":
assert double(2) is 4