Test API Reference

Built-in test framework with assertions and test discovery

Import

U std/test

Constants

NameValueDescription
TEST_PASSED0Test passed
TEST_FAILED1Test failed
TEST_SKIPPED2Test skipped
TEST_TIMEOUT3Test timed out
MAX_TESTS1024Maximum tests per suite
DEFAULT_TIMEOUT_MS30000Default timeout (30s)

Structures

TestResult

S TestResult { name: str, status: i64, message: str, duration_ns: i64, file: str, line: i64 }
MethodDescription
new(name, status, message, duration_ns)Create new result
passed(name, duration_ns)Create passed result
failed(name, message, duration_ns)Create failed result
skipped(name, reason)Create skipped result
is_passed()Check if passed
is_failed()Check if failed
is_skipped()Check if skipped
with_location(file, line)Set file/line location

TestCase

S TestCase { name: str, fn_ptr: i64, ... }
MethodDescription
new(name, fn_ptr)Create test case
with_setup(fn_ptr)Set setup function
with_teardown(fn_ptr)Set teardown function
with_timeout(ms)Set timeout
should_panic()Mark as should-panic test
skip(reason)Skip this test
tag(tag)Add tag
has_tag(tag)Check for tag
run()Run the test

TestSuite

S TestSuite { name: str, tests: i64, ... }
MethodDescription
new(name)Create test suite
add(test)Add test case
test(name, fn_ptr)Add simple test
before_all(fn_ptr)Set before_all hook
after_all(fn_ptr)Set after_all hook
before_each(fn_ptr)Set before_each hook
after_each(fn_ptr)Set after_each hook
run()Run all tests
run_filtered(filter)Run matching tests
run_tagged(tag)Run tagged tests

TestSuiteResult

MethodDescription
new(suite_name)Create result
add(result)Add test result
total()Get total test count
all_passed()Check if all passed
print_summary()Print summary

TestRunner

S TestRunner { suites: i64, ... }
MethodDescription
new()Create test runner
add_suite(suite)Add test suite
verbose()Enable verbose mode
filter(filter)Set filter
fail_fast()Enable fail-fast
run()Run all tests

Assertion Functions

FunctionSignatureDescription
assertF assert(condition: i64) -> i64Assert condition is true
assert_msgF assert_msg(condition: i64, message: str) -> i64Assert with message
assert_eqF assert_eq(actual: i64, expected: i64) -> i64Assert equality
assert_neF assert_ne(actual: i64, expected: i64) -> i64Assert not equal
assert_gtF assert_gt(actual: i64, expected: i64) -> i64Assert greater than
assert_ltF assert_lt(actual: i64, expected: i64) -> i64Assert less than
assert_geF assert_ge(actual: i64, expected: i64) -> i64Assert greater or equal
assert_leF assert_le(actual: i64, expected: i64) -> i64Assert less or equal
assert_trueF assert_true(value: i64) -> i64Assert value is true (non-zero)
assert_falseF assert_false(value: i64) -> i64Assert value is false (zero)
assert_str_eqF assert_str_eq(actual: str, expected: str) -> i64Assert strings equal
assert_in_rangeF assert_in_range(value: i64, min: i64, max: i64) -> i64Assert value in range
assert_not_nullF assert_not_null(ptr: i64) -> i64Assert pointer is not null
assert_approxF assert_approx(actual: f64, expected: f64, epsilon: f64) -> i64Assert approximate equality

Convenience Functions

FunctionSignatureDescription
suiteF suite(name: str) -> TestSuiteCreate test suite
runnerF runner() -> TestRunnerCreate test runner
testF test(name: str, fn_ptr: i64) -> TestCaseCreate test case

Usage

U std/test

F test_addition() -> TestResult {
    result := 2 + 2
    assert_eq(result, 4)
    TestResult::passed("test_addition", 0)
}