stdlib.test¶
Test Framework (Contract-Aware)
Generated from
v0.60.1. 3 source files, 70 documented symbols.
assert.xi¶
fn assert(cond: Bool, msg: Str)¶
Fail the test unless
condis true. Complexity: O(1).
fn assert_eq[T](a: T, b: T, msg: Str)¶
Fail unless
aequalsb. Complexity: O(1) for scalars; O(len) for content types.
fn assert_ne[T](a: T, b: T, msg: Str)¶
Fail unless
adiffers fromb. Complexity: O(1) for scalars; O(len) for content types.
fn assert_lt[T](a: T, b: T, msg: Str)¶
Fail unless
ais less thanb. Complexity: O(1).
fn assert_le[T](a: T, b: T, msg: Str)¶
Fail unless
ais less than or equal tob. Complexity: O(1).
fn assert_gt[T](a: T, b: T, msg: Str)¶
Fail unless
ais greater thanb. Complexity: O(1).
fn assert_ge[T](a: T, b: T, msg: Str)¶
Fail unless
ais greater than or equal tob. Complexity: O(1).
fn assert_true(cond: Bool, msg: Str)¶
Fail unless
condis true. Complexity: O(1).
fn assert_false(cond: Bool, msg: Str)¶
Fail unless
condis false. Complexity: O(1).
fn assert_near(a: Float64, b: Float64, eps: Float64, msg: Str)¶
Fail unless
aandbare withinepsof each other. Complexity: O(1).
fn assert_contains(haystack: Str, needle: Str, msg: Str)¶
Fail unless
haystackcontainsneedle. Complexity: O(len(haystack) * len(needle)).
fn assert_matches(s: Str, pattern: Str, msg: Str)¶
Fail unless
smatches the regexpattern(search semantics, via xiom.regex.engine). Complexity: O(len(s) * len(pattern)) worst case.
fn assert_ok[T](r: Result[T, Str], msg: Str) -> T¶
Fail on Err and return the Ok value. Complexity: O(1).
fn assert_err[T](r: Result[T, Str], msg: Str)¶
Fail unless
ris an Err. Complexity: O(1).
fn assert_some[T](o: Option[T], msg: Str) -> T¶
Fail on None and return the value. Complexity: O(1).
fn assert_none[T](o: Option[T], msg: Str)¶
Fail unless
ois None. Complexity: O(1).
fn assert_panics(f: fn() -> Unit, msg: Str)¶
Fail unless calling
fpanics. Panics terminate the process in this build, so a panic cannot be observed:fis invoked and, if it returns normally, this assertion panics withmsg. Complexity: O(cost of f).
fn assert_throws(f: fn() -> Unit, msg: Str)¶
Fail unless calling
fraises an error. Same observable behaviour asassert_panicsin this build (no unwind support). Complexity: O(cost of f).
fn assert_empty[T](v: &Vec[T], msg: Str)¶
Fail unless
vhas no elements. Complexity: O(1).
fn assert_len[T](v: &Vec[T], n: Int, msg: Str)¶
Fail unless
vhas exactlynelements. Complexity: O(1).
harness.xi¶
type Harness¶
A test runner holding registered tests by name.
| Field | Type |
|---|---|
names |
Vec[Str] |
tests |
Vec[fn() -> Result[Unit, Str]] |
skipped |
Vec[Str] |
type TestReport¶
The result of a run: passed, failed and skipped counts plus total run time.
| Field | Type |
|---|---|
passed |
Int |
failed |
Int |
skipped |
Int |
duration_ms |
Int |
Derives: Clone
type GlobalTests¶
Process-wide registered test names (fixed 8-slot registry; see header).
| Field | Type |
|---|---|
names |
Vec[Str] |
n |
Int |
fn test_harness_new() -> Harness¶
Create an empty test runner. Complexity: O(1).
fn harness_add_test(h: &mut Harness, name: Str, f: fn() -> Result[Unit, Str])¶
Register a named test. Complexity: O(1) amortized.
fn harness_run(h: &Harness) -> TestReport¶
Run all tests sequentially, respecting skipped names. Complexity: O(tests).
fn harness_run_filtered(h: &Harness, filter: Str) -> TestReport¶
Run only tests whose name matches
filter(substring, case-sensitive). Complexity: O(tests).
fn harness_parallel(h: &Harness, workers: Int) -> TestReport¶
Run tests with up to
workersthreads. This single-threaded build runs them sequentially (documented). Complexity: O(tests).
fn harness_skip(h: &mut Harness, name: Str)¶
Mark a named test as skipped. Complexity: O(skipped).
fn harness_benchmark(h: &mut Harness, name: Str, f: fn() -> Unit, iterations: Int) -> Int¶
Time
foveriterationscalls and register the result undername. Returns the total elapsed time in milliseconds. Complexity: O(iterations * cost of f).
fn report_passed(r: &TestReport) -> Int¶
The number of passed tests. Complexity: O(1).
fn report_failed(r: &TestReport) -> Int¶
The number of failed tests. Complexity: O(1).
fn report_skipped(r: &TestReport) -> Int¶
The number of skipped tests. Complexity: O(1).
fn report_duration_ms(r: &TestReport) -> Int¶
The total run time in milliseconds. Complexity: O(1).
fn report_print(r: &TestReport)¶
Print a human-readable summary. Complexity: O(1).
fn report_json(r: &TestReport) -> Str¶
The report serialized as JSON. Complexity: O(1).
fn test_main() -> Int¶
Run all registered global tests and return the exit code. LIMITED: the registered tests cannot be executed in this build (module-scope function pointers are read-only after initialization), so this returns 0 when at least one test has been registered and 1 otherwise. Complexity: O(1).
fn test_register(name: Str, f: fn() -> Result[Unit, Str]) -> Bool¶
Register a test in the global harness. Returns true when the test was recorded, false when the 8-slot registry is full. LIMITED: only the test name is recorded -- the function pointer cannot be retained in this build (see header). Complexity: O(1).
test.xi¶
type TestResult¶
Test result with contract details
| Field | Type |
|---|---|
passed |
Bool |
name |
Str |
message |
Str |
contract_failures |
Vec[ContractFailure] |
duration_ms |
Int |
Derives: Clone
type ContractFailure¶
Recorded contract failure inside a test.
| Field | Type |
|---|---|
clause |
Str |
expression |
Str |
values |
Str |
location |
Str |
Derives: Clone
fn assert(condition: Bool, name: Str) -> TestResult¶
Pass when
conditionholds, else fail withname.
- Precondition:
name.len() > 0
fn assert_eq[T](expected: T, actual: T, name: Str) -> TestResult¶
Pass when the values are equal, else fail with
name.
- Precondition:
name.len() > 0
fn assert_ne[T](expected: T, actual: T, name: Str) -> TestResult¶
Pass when the values differ.
fn assert_lt[T](left: T, right: T, name: Str) -> TestResult¶
Pass when left < right.
fn assert_gt[T](left: T, right: T, name: Str) -> TestResult¶
Pass when left > right.
fn assert_contains(haystack: Str, needle: Str, name: Str) -> TestResult¶
Pass when
haystackcontainsneedle.
fn assert_ok[T, E](result: Result[T, E], name: Str) -> TestResult¶
Pass when the Result is Ok.
fn assert_err[T, E](result: Result[T, E], name: Str) -> TestResult¶
Pass when the Result is Err.
fn assert_some[T](option: Option[T], name: Str) -> TestResult¶
Pass when the Option is Some.
fn assert_none[T](option: Option[T], name: Str) -> TestResult¶
Pass when the Option is None.
fn assert_contract[T](value: T, predicate: fn(&T) -> Bool, name: Str) -> TestResult¶
Pass when
predicateholds for the value.
fn run(test: fn() -> TestResult) -> Int¶
Run one test and print the result; returns the exit code (0 = pass).
fn run_all(tests: Vec[fn() -> TestResult]) -> Int¶
Run every test and print a summary; returns the exit code.
fn run_filtered(tests: Vec[fn() -> TestResult], filter: Str) -> Int¶
Run tests whose name contains
filter; returns the exit code.
fn format_results(results: Vec[TestResult]) -> Str¶
Human-readable summary of the results.
fn format_results_json(results: Vec[TestResult]) -> Str¶
JSON summary of the results.
fn bench(name: Str, f: fn() -> Unit) -> TestResult¶
Time
fonce and report it as a benchmark result.
fn assert_false(cond: Bool, name: Str) -> TestResult¶
Asserts that
condis false. Complexity: O(1). Pure in test context.
fn assert_eq_int(expected: Int, actual: Int, name: Str) -> TestResult¶
Asserts that two
Intvalues are equal. Complexity: O(1). Pure in test context.
fn assert_ne_int(expected: Int, actual: Int, name: Str) -> TestResult¶
Asserts that two
Intvalues are not equal. Complexity: O(1).
fn assert_gt_int(left: Int, right: Int, name: Str) -> TestResult¶
Asserts that
leftis strictly greater thanright. Complexity: O(1).
fn assert_lt_int(left: Int, right: Int, name: Str) -> TestResult¶
Asserts that
leftis strictly less thanright. Complexity: O(1).
fn assert_ge_int(left: Int, right: Int, name: Str) -> TestResult¶
Asserts that
leftis greater than or equal toright. Complexity: O(1).
fn assert_le_int(left: Int, right: Int, name: Str) -> TestResult¶
Asserts that
leftis less than or equal toright. Complexity: O(1).
fn assert_in_range(value: Int, lo: Int, hi: Int, name: Str) -> TestResult¶
Asserts that
valueis within the inclusive range [lo,hi]. Complexity: O(1).
fn test_count_failures(results: Vec[TestResult]) -> Int¶
Counts the number of failing test results in the vector. Complexity: O(n). Consumes the vector.
fn test_pass_count(results: Vec[TestResult]) -> Int¶
Counts the number of passing test results in the vector. Complexity: O(n). Consumes the vector.
fn test_fail_count(results: Vec[TestResult]) -> Int¶
Counts the number of failing test results. Alias for
test_count_failures. Complexity: O(n). Consumes the vector.
fn test_summary(results: Vec[TestResult]) -> Str¶
Returns a one-line summary string:
"P passed, F failed, T total". Complexity: O(n). Consumes the vector.
fn test_report(results: Vec[TestResult]) -> Str¶
Generates a multi-line test report using
xiom.string.str_concat. Includes per-test results followed by a summary footer. Complexity: O(n). Consumes the vector.