Skip to content
CryoCryo home
StdlibTesting

test

Cryo's built-in unit-test framework. Tests live in files under a project's tests/ directory, with each file's namespace declaration carrying ![config(testing)]. Inside such a file, every ![test] function is auto-discovered by the compiler and run by cryo test.

public module test::error;
public module test::descriptor;
public module test::assert;
public module test::fixture;
public module test::table;
public module test::runner;

std::test is deliberately not in the prelude — test files import what they need explicitly, and the synthesized test main does the same. The module re-exports each sub-module, so import std::test::*; brings in the whole surface.

![config(testing)]
namespace MyApp::Tests::Math;

import std::test::*;

![test]
function add_works() -> Result<(), TestError> {
    expect_eq(2 + 2, 4)?;
    return Result::Ok(());
}
FileWhat it holdsImport
assertexpect, expect_eq, bail, ...import std::test::assert;
errorTestErrorimport std::test::error;
descriptorTestDescriptor, the record the compiler synthesises per testimport std::test::descriptor;
fixtureFixtureimport std::test::fixture;
tableprefix_case, prefix_named_caseimport std::test::table;
runnerrun_all, RunOptions, TestOutcomeimport std::test::runner;

Annotations

AnnotationEffect
![test]Marks a function for discovery.
![ignore]Skipped unless cryo test --ignored is passed.
![should_panic]Passes only if the body panics or returns Err.
![test]
![should_panic]
function out_of_range() -> Result<(), TestError> {
    core::panic("expected", FILE, LINE);
    return Result::Ok(());
}

Isolation

Each test runs in its own forked child. A panic or an Err return in one test cannot affect any other.

This is intentionally heavier than running everything in-process. Cryo has no in-process panic catch under the default abort strategy, so isolation by fork is the simplest correct option.

Compile-fail tests

Code that must be rejected with a specific error is not a ![test] function. Those live as standalone files under tests/negative/, each carrying ![config(negative, <code>)]. cryo test compiles each on its own and checks the diagnostic matches.