Skip to content

Commit a730f25

Browse files
committed
Ensure that all guide 'main' functions return Unit
1 parent 5ea2c05 commit a730f25

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kotlinx-coroutines-core/jvm/test/guide/test/TestUtil.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private const val SHUTDOWN_TIMEOUT = 5000L // 5 sec at most to wait
2626
private val OUT_ENABLED = systemProp("guide.tests.sout", false)
2727

2828
@Suppress("DEPRECATION")
29-
fun test(name: String, block: () -> Unit): List<String> = outputException(name) {
29+
fun <R> test(name: String, block: () -> R): List<String> = outputException(name) {
3030
val sout = System.out
3131
val oldOut = if (OUT_ENABLED) System.out else NullOut
3232
val oldErr = System.err
@@ -45,7 +45,8 @@ fun test(name: String, block: () -> Unit): List<String> = outputException(name)
4545
var bytes = ByteArray(0)
4646
withVirtualTimeSource(oldOut) {
4747
try {
48-
block()
48+
val result = block()
49+
require(result === Unit) { "Test 'main' shall return Unit" }
4950
} catch (e: Throwable) {
5051
System.err.print("Exception in thread \"main\" ")
5152
e.printStackTrace()

0 commit comments

Comments
 (0)