stdlib: Enable assertFailsWith function

The function was disabled due to an issue with catch serialization.
Now the issue is fixed and the function can be re-enabled.
This commit is contained in:
Ilya Matveev
2017-12-18 15:14:11 +07:00
committed by ilmat192
parent bf67bc38fc
commit 92e666f023
3 changed files with 44 additions and 68 deletions
-19
View File
@@ -1,24 +1,5 @@
package kotlin.test
// TODO: Remove it when such method from library is available.
/** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */
inline fun <reified T : Throwable> assertFailsWith(message: String? = null, block: () -> Unit): T {
try {
block()
} catch (e: Throwable) {
if (e is T) {
@Suppress("UNCHECKED_CAST")
return e
}
@Suppress("INVISIBLE_MEMBER")
fail(message + ". Expected an exception of type //TODO: add type!// to be thrown, but was $e")
}
@Suppress("INVISIBLE_MEMBER")
fail(message + ". Expected an exception of type //TODO: add type!// to be thrown, but was completed successfully.")
}
@Suppress("UNUSED_PARAMETER")
public fun assertTypeEquals(expected: Any?, actual: Any?) {
//TODO: find analogue
+21 -24
View File
@@ -19,30 +19,27 @@ class BasicAssertionsTest {
assertFailsWith<AssertionError> { throw AssertionError() }
}
// TODO: Uncomment with the catch serialization bug is fixed.
// @Test fun testAssertFailsWithFails() {
// assertTrue(true) // at least one assertion required for qunit
//
// withDefaultAsserter run@ {
// try {
// assertFailsWith<IllegalStateException> { throw IllegalArgumentException() }
// }
// catch (e: AssertionError) {
// return@run
// }
// throw AssertionError("Expected to fail")
// }
//
// withDefaultAsserter run@ {
// try {
// assertFailsWith<IllegalStateException> { }
// }
// catch (e: AssertionError) {
// return@run
// }
// throw AssertionError("Expected to fail")
// }
// }
@Test
fun testAssertFailsWithFails() {
withDefaultAsserter run@ {
try {
assertFailsWith<IllegalStateException> { throw IllegalArgumentException() }
}
catch (e: AssertionError) {
return@run
}
throw AssertionError("Expected to fail")
}
withDefaultAsserter run@ {
try {
assertFailsWith<IllegalStateException> { }
}
catch (e: AssertionError) {
return@run
}
throw AssertionError("Expected to fail")
}
}
@Test
fun testAssertFailsWithClass() {