assert Err<T, E>(value: Result<T, E>) - > E- Module
- std.
test - Receiver
- Not applicable
- Minimum arity
- 1
- Maximum arity
- 1
Declaration and parameters
LinkAvailability
Included by default: Pending
Import 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.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1947 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 71 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 445 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1947 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 272 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1973 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
b48527d0a174· 676 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
b48527d0a174· 978 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1262
Receiver
Parameter constraints
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.
Related rule: Assert a Result constructor and return its payloadResult
The declared result type is E.
Effects
Failures
Result and effects
LinkReturn the payload of an outer Err unchanged. An outer Ok raises TPZ4007 with its value.
Related entries
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