diff --git a/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/Assertions.kt b/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/Assertions.kt index 28a2d1d592c..de99f29e364 100644 --- a/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/Assertions.kt +++ b/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/Assertions.kt @@ -102,6 +102,18 @@ fun assertFails(message: String?, block: () -> Unit): Throwable { asserter.fail(messagePrefix(message) + "Expected an exception to be thrown, but was completed successfully.") } +/** Asserts that a [block] fails with a specific exception of type [T] being thrown. + * Since inline method doesn't allow to trace where it was invoked, it is required to pass a [message] to distinguish this method call from others. + */ +@InlineOnly +inline fun assertFailsWith(message: String? = null, noinline block: () -> Unit): T { + val exception = assertFails(message, block) + val messagePrefix = if (message == null) "" else "$message. " + + assertTrue(exception is T, "${messagePrefix}An exception thrown is not of the expected type: $exception") + return exception as T +} + /** * Abstracts the logic for performing assertions. Specific implementations of [Asserter] can use JUnit * or TestNG assertion facilities. diff --git a/libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt b/libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt index a89e0403d91..192115d9c46 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt @@ -25,6 +25,7 @@ fun todo(block: () -> Any) { println("TODO at " + block) } +/* /** Asserts that a [block] fails with a specific exception of type [T] being thrown. * Since inline method doesn't allow to trace where it was invoked, it is required to pass a [message] to distinguish this method call from others. */ @@ -35,6 +36,7 @@ inline fun assertFailsWith(message: String? = null, noin assertTrue(exception is T, "${messagePrefix}An exception thrown is not of the expected type: $exception") return exception as T } +*/ var _asserter: Asserter = QUnitAsserter() diff --git a/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt index 96e3e0be465..8834da445a6 100644 --- a/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt +++ b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt @@ -47,12 +47,13 @@ fun assertFailsWith(exceptionClass: KClass, block: () -> Unit /** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */ fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T = assertFailsWithImpl(exceptionClass.java, message, block) +/* /** Asserts that a [block] fails with a specific exception of type [T] being thrown. * Since inline method doesn't allow to trace where it was invoked, it is required to pass a [message] to distinguish this method call from others. */ @InlineOnly inline fun assertFailsWith(message: String? = null, noinline block: () -> Unit): T = assertFailsWith(T::class, message, block) - +*/ /** * Comments out a [block] of test code until it is implemented while keeping a link to the code