std.assert
The assertion module. The most commonly used tool in tests and examples.
yaoxiang
use std.assertFunction Overview
| Function | Signature |
|---|---|
assert | (cond: Bool, ?msg: String) -> Void |
Functions
assert
yaoxiang
assert: (cond: Bool, ?msg: String) -> VoidAsserts that cond is true.
cond— Boolean expression to be evaluatedmsg— Optional message,?indicates it can be omitted; output together with the diagnostic when the condition does not hold
Returns: returns Void when the condition holds, without interrupting execution. Errors: throws E6005 (assertion failure) when the condition is false, and the program exits with a non-zero code.
yaoxiang
use std.assert
main: () -> Void = {
assert(1 > 0)
assert(1 > 0, "this literal assertion must hold")
}Assertions are the primary means of judgment for test corpora — both src/std/tests/*.yx and tests/yaoxiang/** work in a way that an assert failure causes the process to report an error:
yaoxiang
use std.assert
use std.list
main: () -> Void = {
list.len([1, 2, 3]) == 3
assert(list.len([1, 2, 3]) == 3, "len == 3")
}Related
- Test Specification — Corpus organization and judgment conventions
- Error Code Reference —
E6005assertion failure
