assert Ne<T>(actual: T, expected: T) - > ()- Module
- std.
test - Receiver
- Not applicable
- Minimum arity
- 2
- 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· 1932 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 71 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 442 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1932 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 263 - 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· 1259
Receiver
Parameter constraints
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.
Related rule: Assert inequality and text containmentResult
The declared result type is ().
Effects
Failures
Result and effects
LinkReturn unit when ordinary equality says the values differ. Equal values raise TPZ4007 with their rendered value.
Related entries
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