23 lines
681 B
Kotlin
23 lines
681 B
Kotlin
/*
|
|
* Copyright (c) 2025. Sergey S. Chernov - All Rights Reserved
|
|
*
|
|
* You may use, distribute and modify this code under the
|
|
* terms of the private license, which you must obtain from the author
|
|
*
|
|
* To obtain the license, contact the author: https://t.me/real_sergeych or email to
|
|
* real dot sergeych at gmail.
|
|
*/
|
|
|
|
import kotlin.test.fail
|
|
|
|
inline fun <reified T: Throwable>assertThrows(f: ()->Unit): T {
|
|
val name = T::class.simpleName
|
|
try {
|
|
f()
|
|
fail("expected to throw $name but threw nothing")
|
|
}
|
|
catch(x: Throwable) {
|
|
if( x is T ) return x
|
|
fail("expected to throw $name but instead threw ${x::class.simpleName}: $x")
|
|
}
|
|
} |