assert(condition: bool, message: string = "assertion failed") - > ()- Module
- std.
test - Receiver
- Not applicable
- Minimum arity
- 1
- Maximum arity
- 2
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· 1927 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 71 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 440 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1927 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 259 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1973 - compiler/crates/topaz_value/src/value/builtin_catalog.rs at
b48527d0a174· 1107 - 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· 1257
Receiver
Parameter constraints
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.
Related rule: Repeat assertions with forResult
The declared result type is ().
Effects
Failures
Result and effects
LinkChecks a boolean condition with a failure message.
Related entries
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