Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Tools

    Test results and assertions

    Read the result of a SELF test invocation and use equality assertions to check returned values.

    Rules

    Link
    Ruletopaz.rule.test-result.completion

    Test completion and failure reporting

    topaz test checks the selected entry before execution. After a successful SELF execution, it writes {entry}: test-ok followed by a newline to standard output. A reported runtime failure writes its diagnostic and {entry}: test failed to standard error and exits unsuccessfully. A unit with compilation diagnostics does not execute.

    Success includes deferred cleanup. Deferred errors and process exit codes follow the test command.

    Why

    Checking before execution prevents invalid programs from producing effects. Separate success and failure channels let test runners distinguish completion from a failed test.

    Source evidence
    Ruletopaz.rule.test-result.assert-eq

    Equality assertions

    The operands of std.test.assertEq(actual, expected) use the ordinary equality domain.

    Equal values return () and execution continues. Unequal values raise TPZ4007 with the rendered actual and expected values.

    Known noncomparable operands produce TPZ5007 during checking.

    Argument evaluation and assertion failure follow Test comparisons.

    Why

    Using ordinary value equality keeps tests consistent with comparisons in program code. Reporting both operands makes a mismatch inspectable.

    Source evidence

    Examples

    Link

    A successful test reports completion

    Link
    test-result.tpzA successful test reports completionOpen in Playground
    1. let value = 1
    Expected outputexit 0
    test-result.tpz: test-ok
    
    $ topaz test test-result.tpz --compiler self · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. test-result.tpz: test-ok
    Source evidence

    Equality returns unit and execution continues

    Link
    assert-eq.tpzEquality returns unit and execution continuesOpen in Playground
    1. import std.io
    2. import std.test
    3. let result: () = test.assertEq([1, 2], [1, 2])
    4. io.writeLine("{result}")
    Expected outputexit 0
    ()
    
    $ topaz run assert-eq.tpz --compiler self · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. ()
    Source evidence

    Reject function equality before execution

    Link
    test-input-bad.tpzReject function equality before executionOpen in Playground
    1. import std.test
    2. function value(x: int) -> int { x }
    3. test.assertEq(value, value)
    Expected outputNonzero exit
    No stdout.
    $ topaz check test-input-bad.tpz --compiler self · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5007 test-assert-eq-non-comparable at test-input-bad.tpz:3:1
    Source evidence

    An unequal assertion fails the test

    Link
    test-failure.tpzAn unequal assertion fails the testOpen in Playground
    1. import std.test
    2. test.assertEq(1, 2)
    target product 5.21.3
    Expected result

    Expected result

    The independently intended result is a nonzero exit, TPZ4007, and the test-failed footer. The dedicated installed-CLI product test has not run in this sandbox.

    The intended runtime outcome is TPZ4007, an unsuccessful exit, and test-failure.tpz: test failed on standard error. A dedicated installed-CLI product test checks these observations for this exact fixture. Its execution awaits the public CLI integration run.

    Source evidence

    Related

    Link

    Value is not comparable or keyable

    Assertion failed

    test

    std.test.assertEq

    Menu

    Download