Tests.Assert

Module tests.assert

import tests.assert

Assertions are values, not control flow.

An assertion here returns a prelude.Result rather than aborting. A test returns one, and that is its outcome — so a failure is an ordinary value you can pass around, and all combines several into one.

Because they are values, nothing stops after the first failure unless you make it. Return a single assertion for a single check, or gather several with all to report every one.

@Test()
fn testSplitsOnEverySeparator() {
	assert.all([
		assert.equal(["a", "b"], strings.split("a,b", ",")),
		assert.equal([""], strings.split("", ",")),
	])
}

See tests for where a test module goes and how zirric test finds it.

Dependencies


Contents


Functions

all

`tests/assert/basic.zirr:8`
fn all(res: [@AnyResult]) -> Result

Combines several assertions into one: an Ok when every one of them is, and otherwise an Err naming every failure.
Nothing short-circuits, so a test written with all reports every check that failed rather than only the first.


equal

`tests/assert/basic.zirr:14`
fn equal(expect, got) -> Result

An Ok when the two values are equal, and otherwise an Err naming both.
Equality is the language’s own ==, so a data value is compared field by field.


fail

`tests/assert/basic.zirr:81`
fn fail(reason) -> Result

Always an Err with the given reason. For the branch a test should never reach.


isErr

`tests/assert/basic.zirr:53`
fn isErr(val) -> Result

An Ok when the value is a failed result, reading it through @AnyResult when it is not an Ok or an Err itself.


isError

`tests/assert/basic.zirr:71`
fn isError(val) -> Result

An Ok when the value’s type carries @Error, whatever else it is.


isFalse

`tests/assert/basic.zirr:28`
fn isFalse(val) -> Result

An Ok when the value is false.


isOk

`tests/assert/basic.zirr:33`
fn isOk(val) -> Result

An Ok when the value is a successful result, reading it through @AnyResult when it is not an Ok or an Err itself.


isTrue

`tests/assert/basic.zirr:23`
fn isTrue(val) -> Result

An Ok when the value is true.