Reformat kotlin.test library

This commit is contained in:
Ilya Gorbunov
2018-04-27 00:46:26 +03:00
parent 06aaa990be
commit d9d7b87fd9
16 changed files with 108 additions and 91 deletions
@@ -118,7 +118,8 @@ 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 <reified T : Throwable> assertFailsWith(message: String? = null, noinline block: () -> Unit): T = assertFailsWith(T::class, message, block)
inline fun <reified T : Throwable> 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 <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, block: () -> Unit): T = assertFailsWith(exceptionClass, null, block)
@@ -7,7 +7,9 @@ package org.junit
/** @suppress */
@Suppress("NO_ACTUAL_FOR_EXPECT")
@Deprecated("Use 'Test' from kotlin.test package",
replaceWith = ReplaceWith("kotlin.test.Test", "kotlin.test.Test"),
level = DeprecationLevel.WARNING)
@Deprecated(
"Use 'Test' from kotlin.test package",
replaceWith = ReplaceWith("kotlin.test.Test", "kotlin.test.Test"),
level = DeprecationLevel.WARNING
)
expect annotation class Test()
@@ -11,23 +11,29 @@ private var value = 5
class AnnotationsTest {
@BeforeTest fun setup() {
@BeforeTest
fun setup() {
value *= 2
}
@AfterTest fun teardown() {
@AfterTest
fun teardown() {
value /= 2
}
@Test fun testValue() {
@Test
fun testValue() {
assertEquals(10, value)
}
@Test fun testValueAgain() {
@Test
fun testValueAgain() {
assertEquals(10, value)
}
@Ignore @Test fun testValueWrong() {
@Ignore
@Test
fun testValueWrong() {
assertEquals(20, value)
}
@@ -30,24 +30,23 @@ class BasicAssertionsTest {
assertFailsWith<AssertionError> { throw AssertionError() }
}
@Test fun testAssertFailsWithFails() {
@Test
fun testAssertFailsWithFails() {
assertTrue(true) // at least one assertion required for qunit
withDefaultAsserter run@ {
withDefaultAsserter run@{
try {
assertFailsWith<IllegalStateException> { throw IllegalArgumentException() }
}
catch (e: AssertionError) {
} catch (e: AssertionError) {
return@run
}
throw AssertionError("Expected to fail")
}
withDefaultAsserter run@ {
withDefaultAsserter run@{
try {
assertFailsWith<IllegalStateException> { }
}
catch (e: AssertionError) {
assertFailsWith<IllegalStateException> { }
} catch (e: AssertionError) {
return@run
}
throw AssertionError("Expected to fail")
@@ -105,7 +104,7 @@ class BasicAssertionsTest {
@Test
fun testAssertFalseFails() {
checkFailedAssertion { assertFalse(true) }
checkFailedAssertion{ assertFalse { true } }
checkFailedAssertion { assertFalse { true } }
}
@Test
@@ -115,7 +114,7 @@ class BasicAssertionsTest {
@Test()
fun testAssertFailsFails() {
checkFailedAssertion { assertFails { } }
checkFailedAssertion { assertFails { } }
}
@@ -203,8 +202,7 @@ private fun withDefaultAsserter(block: () -> Unit) {
val current = overrideAsserter(DefaultAsserter())
try {
block()
}
finally {
} finally {
overrideAsserter(current)
}
}