Testing

Stof tests.

Stof has a thin testing layer built in, just like "run". Test functions are given the attribute #[test], and are always run as a separate asynchronous process.

#[test]
fn passes() {
    assert(true);
    assert_eq("hi", "hi");
    assert_not(false);
    assert_neq("hi", 42);
}

Assert functions are a part of the Standard Library (Std).

If you expect the test to throw an error, add a #[errors] attribute as well.

#[test]
#[errors]
fn passes() {
    throw("this is an expected error");
}

Running Tests

With the CLI, use stof test instead of stof run. You'll see some nice-looking output for each test that ran, and then any failures that occurred at the bottom of the output. Errors will include a small stack trace so you can get a good idea of where things went wrong.

Errors and debug information are a big area of improvement - please consider helping out if you love Stof.

Last updated

Was this helpful?