Tests

Writing tests

test blocks can go anywhere (but not nested inside of something else).

test 1 + 1 is 2 test 2 * 2 is 5 # fails

Running tests

When running or building a program normally, tests are ignored.

The following commands run tests:

  • keen test foo.keen runs all tests in a file.
  • keen test foo.keen --line 123 runs the test at a specific line number.
  • keen test dir-name runs all tests in all files in a directory and subdirectories.
  • keen test foo.keen bar.keen dir1 dir2 runs all tests in selected files and directories.

Test modifiers

Tests can be marked global or unsafe if necessary.

test global, unsafe x is 0 # Make sure to reset global state at the end of the test finally x := 0 x +:= 1 x is 1 x global(nat)

A java or js test will only run on that target.

import keen/js keen/js/util java/util/ArrayList test java, global, unsafe log "Running Java test" a ArrayList = () a.size is 0 test js, global, unsafe log "Running JS test" a js-any = x: 1 a["x"].to::nat is 1

keen test foo.keen won't run js tests, and keen test foo.keen --node-js won't run java tests.