Renderingen-US

assert

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Asserts that a condition is true at runtime.

Aliases: assert

Syntax: assert <expression> [panic <expression>]

Category#

testing

Examples#

radix/corpus/adfirma/adfirma.fab (canonical · keyword)#

Asserts that a condition is true at runtime.

test "assertions validate invariants" {
    const int x ← 10
    assert x ≻ 0
    assert x ≡ 10 panic "x decem esse debet"
    const string name ← "Marcus"
    assert name ≡ "Marcus"
    assert name ≠ "" panic "nomen vacuum non sit"
    const bool viget ← true
    assert viget
    assert viget ≡ true panic "vigere debet"
}

# =============================================================================
# assert — Asserts that a condition is true at runtime.
# =============================================================================
#
# What this teaches:
#   • Runtime assertions — `assert <condition>` validates invariants during
#     program execution
#   • Custom messages — `assert <condition> panic "message"` adds descriptive
#     diagnostic text on failure
#   • Testing category — assert is the primary assertion keyword for test
#     and verification code
#
# Common mistakes:
#   • using `assert` outside `test` or `describe` (WARN006); use `panic` for invariant violations in production code or move assertions into test blocks
#
# See also: test, do, catch
# =============================================================================

# assert — runtime assertions
#
# assert <condition>
# assert <condition> panic "nuntius"
#
# GRAMMAR:
#   adfirmaStmt :← 'assert' expr ('panic' expr)?
#
# EXPECTED OUTPUT:
#   empty — assert only (adfirma.expected)

main {
    const int x ← 10

    # Simple assertion without message
    assert x ≻ 0

    # Assertion with custom message
    assert x ≡ 10 panic "x decem esse debet"

    # Multiple assertions
    const string name ← "Marcus"
    assert name ≡ "Marcus"
    assert name ≠ "" panic "nomen vacuum non sit"

    # Boolean assertions
    const bool viget ← true
    assert viget
    assert viget ≡ true panic "vigere debet"
}