Module
LinkSuccessful assertions return unit or the requested payload without printing. Failed conditions raise TPZ4007 at the call and stop the current test. Golden assertions compare existing text without updating it. Use the language for loop to repeat assertions.
Why
LinkAssertions use the same comparisons and constructors as ordinary programs. A test failure identifies the expectation without changing the data used to judge it.
Availability
LinkImport std.test in language mode 5.21. The current compiler selects std/test.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Public API
LinkPending contracts
LinkRepeat assertions with for
LinkRepeat assertions with for
Test programs iterate supplied values with the ordinary for statement. The same statement applies to integers, booleans, strings, and other iterable element types.
std.test does not export forAllInt or forAllBool. Assertions inside a for body retain the same assertion behavior as a direct call.
Why
The removed helpers repeated an existing loop and added no test meaning. Ordinary iteration works for every element type and keeps loop control and assertion order visible.
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
271329b482bc· 449 - compiler/crates/topaz_resolve/src/codes.rs at
271329b482bc· 46 -
topaz.stdlib.contract.test-for-allatworking-tree - topaz.decision.test-for-all.1 at
topaz.decisi
Use one loop for every element type
Linkimport std.testimport std.iolet mut sum = 0for value in ([2, 3, 5]) {sum += value}let mut trueCount = 0for value in ([true, false, true]) {if (value) { trueCount += 1 }}let mut labels = ""for value in (["A", "B", "C"]) {labels = labels + value}test.assertEq(sum, 10)test.assertEq(trueCount, 2)test.assertEq(labels, "ABC")io.writeLine("all values checked")
all values checked
Expected result
Expected result
Execution completes. Exit code 0.
all values checked
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
271329b482bc· 449 - compiler/crates/topaz_resolve/src/codes.rs at
271329b482bc· 46 -
topaz.stdlib.contract.test-for-allatworking-tree - topaz.decision.test-for-all.1 at
topaz.decisi
Reject the removed forAllInt helper
Linkimport std.test { forAllInt }
No stdout.
Expected result
Expected result
Rejection during resolve. Nonzero exit.
TPZ3009selected-name-not-exported atmain.tpz:1:19
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
271329b482bc· 449 - compiler/crates/topaz_resolve/src/codes.rs at
271329b482bc· 46 -
topaz.stdlib.contract.test-for-allatworking-tree - topaz.decision.test-for-all.1 at
topaz.decisi
Reject the removed forAllBool helper
Linkimport std.test { forAllBool }
No stdout.
Expected result
Expected result
Rejection during resolve. Nonzero exit.
TPZ3009selected-name-not-exported atmain.tpz:1:19
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
271329b482bc· 449 - compiler/crates/topaz_resolve/src/codes.rs at
271329b482bc· 46 -
topaz.stdlib.contract.test-for-allatworking-tree - topaz.decision.test-for-all.1 at
topaz.decisi
Diagnostics
LinkAssert inequality and text containment
LinkAssert inequality and text containment
assert returns unit when ordinary value equality says the operands differ. It performs no string conversion before comparison.
The operands must have a common comparable type under the ordinary equality rules. Known noncomparable values produce TPZ5007 during checking. A comparison fault propagates with its own diagnostic.
assert returns unit when the exact needle occurs as a contiguous substring. Matching is case sensitive and preserves Unicode spelling. An empty needle succeeds even when the text is empty.
Arguments are evaluated once from left to right before testing the condition. Successful calls have no further side effects and print nothing.
A false assertion raises TPZ4007 at the assertion call. It returns no value and stops the current test before the next statement. Earlier argument side effects remain visible. Test runner handling of later test cases follows the test execution contract.
The inequality failure message uses the ordinary rendering of the shared value in this form.
```text assertNe failed: both values are {value} ```
The containment failure message includes the original text and needle in this form.
```text assertContains failed: {text} does not contain {needle} ```
These assertions add test failure reporting to ordinary equality and string containment. They do not define a separate comparison relation.
Why
Tests should disagree with a program value only when the same ordinary comparison disagrees. Silent success keeps output useful, and immediate failure prevents a false premise from affecting later assertions.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 36 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 51 - compiler/crates/topaz_value/src/value/compare.rs at
912a5e86e1f9· 18 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
912a5e86e1f9· 1274 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 157 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-comparisonsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Compare values and exact substrings
Linkimport std.testimport std.iotest.assertNe([1, 2], [1, 3])let present: Option<int> = Some(1)let absent: Option<int> = None()test.assertNe(present, absent)test.assertContains("Topaz", "opa")test.assertContains("é", "é")test.assertContains("text", "")test.assertContains("", "")io.writeLine("comparisons passed")
comparisons passed
Expected result
Expected result
Execution completes. Exit code 0.
comparisons passed
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 36 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 51 - compiler/crates/topaz_value/src/value/compare.rs at
912a5e86e1f9· 18 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
912a5e86e1f9· 1274 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 157 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-comparisonsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Evaluate each operand once in source order
Linkimport std.testimport std.iofunction operand(label: string, value: int) -> int {io.writeLine(label)return value}let result: () = test.assertNe(operand("actual", 3), operand("expected", 4))io.writeLine("{result}")
actual expected ()
Expected result
Expected result
Execution completes. Exit code 0.
actualexpected()
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 36 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 51 - compiler/crates/topaz_value/src/value/compare.rs at
912a5e86e1f9· 18 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
912a5e86e1f9· 1274 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 157 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-comparisonsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Stop after equal operands fail assertNe
Linkimport std.testimport std.iofunction operand(label: string, value: int) -> int {io.writeLine(label)return value}test.assertNe(operand("actual", 7), operand("expected", 7))io.writeLine("after")
actual expected
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-ne-equal atmain.tpz:9:1
actualexpected
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 36 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 51 - compiler/crates/topaz_value/src/value/compare.rs at
912a5e86e1f9· 18 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
912a5e86e1f9· 1274 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 157 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-comparisonsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Keep substring matching case sensitive
Linkimport std.testimport std.ioio.writeLine("before")test.assertContains("Topaz", "topaz")io.writeLine("after")
before
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-contains-case atmain.tpz:5:1
before
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 36 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 51 - compiler/crates/topaz_value/src/value/compare.rs at
912a5e86e1f9· 18 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
912a5e86e1f9· 1274 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 157 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-comparisonsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Keep composed and decomposed spellings distinct
Linkimport std.testimport std.ioio.writeLine("before")test.assertContains("é", "é")io.writeLine("after")
before
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-contains-spelling atmain.tpz:5:1
before
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 36 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 51 - compiler/crates/topaz_value/src/value/compare.rs at
912a5e86e1f9· 18 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
912a5e86e1f9· 1274 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 157 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-comparisonsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Reject values that ordinary equality cannot compare
Linkimport std.testlet value = () => 1test.assertNe(value, value)
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5007stdlib-assert-ne-non-comparable atmain.tpz:4:1
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 36 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 51 - compiler/crates/topaz_value/src/value/compare.rs at
912a5e86e1f9· 18 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
912a5e86e1f9· 1274 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 157 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-comparisonsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Accept exact substrings and an empty needle
Linkimport std.testimport std.iotest.assertContains("Topaz", "opa")test.assertContains("é", "é")test.assertContains("text", "")test.assertContains("", "")io.writeLine("text contained")
text contained
Expected result
Expected result
Execution completes. Exit code 0.
text contained
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 36 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 51 - compiler/crates/topaz_value/src/value/compare.rs at
912a5e86e1f9· 18 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
912a5e86e1f9· 1274 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 157 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-comparisonsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Diagnostics
LinkAssert a Result constructor and return its payload
LinkAssert a Result constructor and return its payload
assert accepts a Result<T, E>. It returns the T payload of Ok(value). An Err(error) raises TPZ4007.
assert accepts a Result<T, E>. It returns the E payload of Err(error). An Ok(value) raises TPZ4007.
The returned payload is unchanged. No conversion, recursive unwrapping, or equality comparison occurs. A nested Err inside an outer Ok still satisfies assertOk.
The argument is evaluated once before its outer constructor is inspected. Success prints nothing. Failure reports the assertion call and stops the current test without running its next statement. Earlier effects remain visible.
The failure messages identify the unexpected constructor and its ordinarily rendered payload.
```text assertOk failed: got Err({error}) assertErr failed: got Ok({value}) ```
These helpers express a test expectation. Match the Result in ordinary code when either constructor is part of normal control flow.
Why
Inspecting the outer constructor preserves the distinction between an expected failure value and a failed test. Returning the payload lets later assertions examine its contents without repeating the match.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 68 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 83 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 159 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 -
topaz.stdlib.contract.test-result-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Extract both Result payloads and preserve a nested Err
Linkimport std.testimport std.iolet okValue: Result<int, string> = Ok(7)let errValue: Result<int, string> = Err("bad")let nested: Result<Result<int, string>, string> = Ok(Err("inner"))let value = test.assertOk(okValue)let error = test.assertErr(errValue)let inner: Result<int, string> = test.assertOk(nested)let nestedError = test.assertErr(inner)io.writeLine("{value}/{error}/{nestedError}")
7/bad/inner
Expected result
Expected result
Execution completes. Exit code 0.
7/bad/inner
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 68 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 83 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 159 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 -
topaz.stdlib.contract.test-result-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Fail assertOk with the rendered error
Linkimport std.testimport std.iolet value: Result<int, string> = Err("bad")io.writeLine("before")test.assertOk(value)io.writeLine("after")
before
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-ok-err atmain.tpz:6:1
before
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 68 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 83 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 159 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 -
topaz.stdlib.contract.test-result-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Fail assertErr with the rendered value
Linkimport std.testimport std.iolet value: Result<int, string> = Ok(7)io.writeLine("before")test.assertErr(value)io.writeLine("after")
before
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-err-ok atmain.tpz:6:1
before
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 68 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 83 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 159 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 -
topaz.stdlib.contract.test-result-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Assert presence or absence
LinkAssert presence or absence
assert accepts an Option<T> and returns the T payload of Some(value). Passing None() raises TPZ4007.
assert accepts an Option<T> and returns unit for None(). Passing Some(value) raises TPZ4007.
Presence depends on the outer constructor. Some(None()), Some(false), and Some(0) are present values. assertSome returns their payloads unchanged.
Each argument is evaluated once. A successful assertion prints nothing and performs no additional effects. Failure reports the assertion call and stops the current test before its next statement.
The failure messages identify the unexpected constructor. A present payload uses ordinary value rendering.
```text assertSome failed: got None assertNone failed: got Some({value}) ```
Use a match to handle absence as normal program behavior. These assertions report a failed test when the chosen presence expectation is false.
Why
Outer constructor checks keep absence separate from a stored false, zero, or absent nested value. They give tests the same Option meaning as ordinary pattern matching.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 101 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 116 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 161 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-option-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Distinguish nested absence from an absent outer value
Linkimport std.testimport std.iolet present: Option<int> = Some(7)let absent: Option<int> = None()let nested: Option<Option<int>> = Some(None())let value = test.assertSome(present)let result: () = test.assertNone(absent)test.assertNone(test.assertSome(nested))io.writeLine("{value}/{result}")
7/()
Expected result
Expected result
Execution completes. Exit code 0.
7/()
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 101 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 116 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 161 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-option-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Fail assertSome on an absent value
Linkimport std.testimport std.iolet value: Option<int> = None()io.writeLine("before")test.assertSome(value)io.writeLine("after")
before
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-some-none atmain.tpz:6:1
before
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 101 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 116 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 161 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-option-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Fail assertNone with the present payload
Linkimport std.testimport std.iolet value: Option<int> = Some(7)io.writeLine("before")test.assertNone(value)io.writeLine("after")
before
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-none-some atmain.tpz:6:1
before
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 101 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 116 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 161 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-option-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Compare existing golden text without updating it
LinkCompare existing golden text without updating it
assert accepts two strings. Read the existing file as UTF-8 and compare the entire decoded text with actual. UTF-8 validity and text preservation follow UTF-8 decoding. Equal text returns unit without printing.
Resolve the path using the same host path and read permission rules as filesystem text reads. For an ordinary installed CLI program, a relative path starts at the process working directory. The source file directory does not replace that directory.
Comparison preserves every scalar and line ending. CRLF and LF differ. A final newline, a byte order mark, Unicode spelling, and an empty file remain significant. Invalid UTF-8 is a read failure.
Evaluate the path expression and then the actual expression, once each, before reading the file. Open and read the expected text once. Release any opened resource before returning or reporting a read or comparison failure.
The assertion needs read access. It never creates a missing golden file, replaces its contents, or enables an update mode. Write a chosen expected result explicitly through the filesystem API.
Missing files, directories that cannot be read as text, permission denial, and invalid UTF-8 raise TPZ4007 at the assertion call. File failures identify the path and whether opening or reading failed. The host detail explains the cause and may vary by platform.
The file failure messages have these forms.
```text assertGolden failed: could not open {path}: {detail} assertGolden failed: could not read {path}: {detail} ```
Unequal text raises TPZ4007 and stops the current test before its next statement. The message has this form.
```text assertGolden failed: {path} did not match actual output ```
Earlier argument effects remain visible after failure. Reading does not promise a snapshot across concurrent host writes. Keep the expected file unchanged while the assertion reads it.
Why
An existing expected file gives the test an independent reference. Exact comparison preserves document bytes that matter to generated text, and explicit writes keep failed tests from replacing their own expectations.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 134 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 98 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 192 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 214 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 238 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 163 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 -
topaz.stdlib.contract.test-golden-textatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Match exact line endings and an empty golden file
Linkimport std.testimport std.iotest.assertGolden("expected.txt", "alpha\r\nβ\n")test.assertGolden("empty.txt", "")io.writeLine("golden text matched")
golden text matched
alphaβ
Expected result
Expected result
Execution completes. Exit code 0.
golden text matched
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 134 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 98 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 192 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 214 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 238 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 163 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 -
topaz.stdlib.contract.test-golden-textatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Resolve a golden path from the working directory
Linkimport std.testimport std.iotest.assertGolden("expected.txt", "working directory\n")io.writeLine("working directory matched")
working directory matched
working directory
source directory
Expected result
Expected result
Execution completes. Exit code 0.
working directory matched
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 134 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 98 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 192 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 214 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 238 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 163 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 -
topaz.stdlib.contract.test-golden-textatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Fail when the final newline is missing from actual text
Linkimport std.testimport std.ioio.writeLine("before")test.assertGolden("expected.txt", "line")io.writeLine("after")
before
line
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-golden-mismatch atmain.tpz:5:1
before
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 134 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 98 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 192 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 214 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 238 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 163 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 -
topaz.stdlib.contract.test-golden-textatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Fail instead of creating a missing golden file
Linkimport std.testimport std.ioio.writeLine("before")test.assertGolden("missing.txt", "new text")io.writeLine("after")
before
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-golden-missing atmain.tpz:5:1
before
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 134 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 98 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 192 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 214 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 238 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 163 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 -
topaz.stdlib.contract.test-golden-textatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Fail instead of replacing invalid UTF-8 with a character
Linkimport std.bytes { Bytes }import std.fsimport std.testimport std.iolet bytes = test.assertOk(Bytes.fromArray([255]))test.assertOk(fs.writeBytes("invalid.txt", bytes))io.writeLine("before")test.assertGolden("invalid.txt", "�")io.writeLine("after")
before
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-golden-invalid-utf8 atmain.tpz:9:1
before
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 134 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 98 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 192 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 214 - compiler/crates/topaz_host_native/src/lib.rs at
912a5e86e1f9· 238 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 163 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 -
topaz.stdlib.contract.test-golden-textatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi