This repository was archived by the owner on Feb 2, 2025. It is now read-only.
File tree 2 files changed +29
-6
lines changed
kotest-assertions-arrow/src
commonMain/kotlin/io/kotest/assertions/arrow/core
commonTest/kotlin/io/kotest/assertions/arrow/core
2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -17,10 +17,10 @@ import io.kotest.assertions.print.print
17
17
* }
18
18
* ```
19
19
*/
20
- public suspend inline fun <reified T > shouldRaise (noinline block : suspend Raise <Any ?>.() -> Any? ): T {
20
+ public inline fun <reified T > shouldRaise (block : Raise <Any ?>.() -> Any? ): T {
21
21
val expectedRaiseClass = T ::class
22
22
return recover({
23
- block()
23
+ block(this )
24
24
throw failure(" Expected to raise ${expectedRaiseClass.simpleName} but nothing was raised." )
25
25
}) { raised ->
26
26
when (raised) {
@@ -40,10 +40,8 @@ public suspend inline fun <reified T> shouldRaise(noinline block: suspend Raise<
40
40
* }
41
41
* ```
42
42
*/
43
- public suspend fun <T > shouldNotRaise (block : suspend Raise <Any ?>.() -> T ): T {
44
- return recover({
45
- block()
46
- }) { raised ->
43
+ public inline fun <T > shouldNotRaise (block : Raise <Any ?>.() -> T ): T {
44
+ return recover(block) { raised ->
47
45
throw failure(" No raise expected, but ${raised.print ().value} was raised." )
48
46
}
49
47
}
Original file line number Diff line number Diff line change 1
1
package io.kotest.assertions.arrow.core
2
2
3
+ import arrow.core.raise.Raise
3
4
import io.kotest.assertions.arrow.shouldBe
4
5
import io.kotest.assertions.throwables.shouldThrowWithMessage
5
6
import io.kotest.core.spec.style.StringSpec
@@ -72,4 +73,28 @@ class RaiseMatchers : StringSpec({
72
73
}
73
74
}
74
75
}
76
+
77
+ " shouldNotRaise: allows suspend call in block" {
78
+ val res = shouldNotRaise {
79
+ suspend { 42 }()
80
+ }
81
+ res shouldBe 42
82
+ }
83
+
84
+ " shouldRaise: allows suspend call in block" {
85
+ val res = shouldRaise<Int > {
86
+ raise(suspend { 42 }())
87
+ }
88
+ res shouldBe 42
89
+ }
90
+
91
+ " shouldNotRaise: callable from non-suspend" {
92
+ fun test() = shouldNotRaise { " success" }
93
+ test() shouldBe " success"
94
+ }
95
+
96
+ " shouldRaise: callable from non-suspend" {
97
+ fun test() = shouldRaise<String > { raise("failed") }
98
+ test() shouldBe " failed"
99
+ }
75
100
})
You can’t perform that action at this time.
0 commit comments