From 2c32bae5ca56ac8fee08088737e63a371bdf16c2 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 19 Apr 2017 08:13:52 +0300 Subject: [PATCH] kotlin-test: Make assertFailsWith() common --- .../common/src/main/kotlin/kotlin/test/Assertions.kt | 8 +------- libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt | 11 ----------- .../kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt | 7 ------- 3 files changed, 1 insertion(+), 25 deletions(-) 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 57f0ce05ebb..3c104fb9126 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 @@ -114,13 +114,7 @@ fun assertFails(message: String?, block: () -> Unit): Throwable { * 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 -} +inline fun assertFailsWith(message: String? = null, noinline block: () -> Unit): T = assertFailsWith(T::class, message, block) /** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */ fun assertFailsWith(exceptionClass: KClass, block: () -> Unit): T = assertFailsWith(exceptionClass, null, block) diff --git a/libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt b/libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt index 41f5372d404..7aa8c834349 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/JsImpl.kt @@ -27,18 +27,7 @@ impl fun todo(block: () -> Unit) { 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. - */ -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 -} -*/ /** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */ impl fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T { val exception = assertFails(message, block) diff --git a/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt index d3aa1df5cc8..45cd80887ca 100644 --- a/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt +++ b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt @@ -45,13 +45,6 @@ private fun assertFailsWithImpl(exceptionClass: Class, messag /** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */ impl 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