std::test
This module provides test-only helpers that record test failures without aborting the process.
These helpers are intended to be used under silk test and integrate with the
language-level assert behavior in test builds (testing).
Each helper also carries a Formal Silk contract requiring BUILD_MODE == "test"
via std::test::requires_test_mode() so downstream verification can model
them as test-only APIs.
Exported API#
expect#
expect(ok: bool, message: string? = None);
Semantics:
- When
okistrue,expectdoes nothing. - When
okisfalse,expectrecords a test failure. - When
messageisSome(...), it is used as the failure message. - When
messageisNone, the default message is"expect failed".
expect_equal#
fn (X, Y) expect_equal (expected: X, actual: Y) -> bool;
Semantics:
- Returns
truewhenexpected == (actual as X)and records no failure. - Returns
falsewhenexpected != (actual as X)and records a failure.
Note: in Silk currently, equality must be supported for the concrete instantiated types used at the call site.
expect_error#
fn (E) expect_error (err: E?) -> bool;
Semantics:
- Returns
truewhenerrisSome(...). - Returns
falsewhenerrisNoneand records a failure.
Example#
import std::test;
test "parsing smoke test" {
let value = Some(42);
std::test::expect(value != None, "value should be present");
std::test::expect_equal(42, match (value) {
Some(v) => v,
None => 0,
});
std::test::expect_error(Some("boom"));
}
Source repository · Edit this page · View Markdown