Skip to content

Compatibility with Arrowopensavvy.prepared.compat.arrow.core

Package-level declarations

Helpers to integrate Arrow's Raise DSL into tests.

Let's assume we want to test a function which raises when it receives a negative number:

data object NegativeSquareRoot

context(Raise<NegativeSquareRoot>)
fun sqrt(value: Double): Double {
    ensure(value >= 0) { NegativeSquareRoot }
    return kotlin.math.sqrt(value)
}

We can write a test that ensures the function does not raise, using failOnRaise:

test("√4 does not raise") {
    failOnRaise {
        sqrt(4.0)
    } shouldBe 2.0
}

We can write a test that ensures the function does raise, using assertRaises or assertRaisesWith:

test("√-1 raises") {
    // assert raises a specific value
    assertRaises(NegativeSquareRoot) {
        sqrt(-1.0)
    }

    // assert raises any value of a specific type
    assertRaisesWith<NegativeSquareRoot> {
        sqrt(-1.0)
    }
}

Functions

assertRaises

inline fun <Failure> assertRaises(expected: Failure, block: Raise<Failure>.() -> Any?)

Fails the test if block doesn't raise with expected.

assertRaisesWith

inline fun <Failure> assertRaisesWith(block: Raise<Any?>.() -> Any?)

Fails the test if block doesn't raise with a value of type Failure.

checkRaises

inline fun <Failure> checkRaises(block: Raise<Any?>.() -> Any?)

Fails the test if block doesn't raise with a value of type Failure.

inline fun <Failure> checkRaises(expected: Failure, block: Raise<Any?>.() -> Any?)

Fails the test if block doesn't raise with expected.

failOnRaise

Fails the test if block raises.