silk.testing.testing.
Assertions for tests, and the filter rules that the test runner uses to select tests.
When to use#
Use Testing.expect in a test function to check a condition. Use Testing.matches or
Testing.matchesQualified in a custom test runner that must select tests with the same rules
as the built-in runner.
Details#
An assertion failure is an ordinary typed failure, AssertionError. It needs no service and
holds the message of the caller. A failed expect stops the test with that failure.
The filters compare the file path exactly. They compare the test name as an ASCII substring and ignore ASCII case. They do not fold non-ASCII letters.
Examples#
Check a condition in a test function#
import silk.testing.testing { AssertionError, Testing }
fn double(value: i32) -> i32 {
return value * 2
}
test effect fn doubleAddsTheValueToItself() -> ()
! AssertionError<'static> {
run Testing.expect(double(21) == 42, "double(21) is 42")
}
pub fn main() -> i32 {
return 0
}Import as Testing with import silk.testing.testing { Testing }.
Public declarations: 2.
AssertionError#
pub struct AssertionError<'message>The failure of a Testing.expect check. It holds the message of the caller.
Details#
Read the message with Testing.assertionMessage.
Implementation Debug for AssertionError<'message>#
impl<'message> Debug for AssertionError<'message>Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the message, as AssertionError { message: "..." }.
Testing#
pub struct TestingThe owner type of the test helpers. It has no fields and is never constructed.
Implementation Testing#
impl TestingAssociated function expect#
pub effect fn expect<'message>(
condition: bool,
message: string<'message>
) -> () ! AssertionError<'message>Fails with an AssertionError that holds message if condition is false.
Details#
If condition is true, this function does nothing. Write message as the expected fact,
such as "list is empty", so that a failure report reads as the broken expectation.
Errors#
AssertionErrorifconditionisfalse.
Associated function assertionMessage#
pub fn assertionMessage<'message>(error: &'message AssertionError<'message>) -> string<'message>Returns the message of an AssertionError.
Associated function matches#
pub fn matches(
path: string,
name: string,
fileFilter: string,
nameFilter: string,
) -> boolReturns true if a test with file path and name name passes both filters.
Details#
fileFiltermust be equal topath, byte for byte. An emptyfileFilterpasses each file.nameFiltermust occur inname. The comparison ignores ASCII case. An emptynameFilterpasses each name.
Gotchas#
The name comparison folds only ASCII letters. Other letters must match exactly.
Associated function matchesQualified#
pub fn matchesQualified(
path: string,
module: string,
name: string,
fileFilter: string,
nameFilter: string,
) -> boolReturns true if a test passes both filters, where the name filter applies to the qualified
name module::name.
When to use#
Use this function in a custom runner that reports tests by qualified name, as the built-in
runner does. Use Testing.matches to match the plain name only.
Details#
fileFilter must be equal to path, byte for byte. An empty fileFilter passes each file.
nameFilter can occur anywhere in
module::name, also across the :: separator. The comparison ignores ASCII case.
Category: Testing.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.