Modules and tests
sub init makes a small project:
main.sublib/text.subneeds [ clock ]
use "./lib/text.sub"
let started = now()print(greet("world"))print(shout("subtype"))print("took", now() - started >= 0)
test "greet says hello" { assert_eq(greet("sub"), "hello, sub")}fn greet(name: String) -> String { "hello, {name}"}
fn shout(text: String) -> String { upper(text) + "!"}
test "shout makes it loud" { assert_eq(shout("hi"), "HI!")}The subtype rule across files
Section titled “The subtype rule across files”A library function that touches the outside says so with its own needs. The script that calls it must allow that. A call that needs more than the script holds is an error, with the file and the line:
fn load(p: Path) needs [read [p]] -> String { read(p) or "" }sub test main.sub --yesok greet says hellook shout makes it loud2 passed, 0 failedTest blocks live next to the code they test, in the script or a library. sub test runs on the interpreter, not on Wasmtime.