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:
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user