From d9d7b87fd9e7d60cf0dfa3ffec8a168ebbbe37e2 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 27 Apr 2018 00:46:26 +0300 Subject: [PATCH] Reformat kotlin.test library --- .../src/main/kotlin/kotlin/test/Assertions.kt | 3 +- .../common/src/main/kotlin/org/junit/Test.kt | 8 +- .../kotlin/test/tests/AnnotationsTest.kt | 16 ++-- .../kotlin/test/tests/BasicAssertionsTest.kt | 22 +++-- .../js/it/src/test/kotlin/MainTest.kt | 19 +++-- .../kotlin/kotlin/test/DefaultJsAsserter.kt | 6 +- .../js/src/main/kotlin/kotlin/test/TestApi.kt | 16 ++-- .../kotlin/kotlin/test/adapters/Externals.kt | 3 +- .../test/adapters/JasmineLikeAdapter.kt | 6 +- .../kotlin/test/adapters/QUnitAdapter.kt | 3 +- .../js/src/main/kotlin/org/junit/junitTest.kt | 8 +- .../junit/src/main/kotlin/Annotations.kt | 1 + .../jvm/src/main/kotlin/AssertionsImpl.kt | 4 +- .../test/kotlin/CollectionAssertionTest.kt | 1 + .../jvm/src/test/kotlin/TestJVMTest.kt | 82 +++++++++---------- .../testng/src/main/kotlin/Annotations.kt | 1 + 16 files changed, 108 insertions(+), 91 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 080cc0230ac..e3abde699aa 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 @@ -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 assertFailsWith(message: String? = null, noinline block: () -> Unit): T = assertFailsWith(T::class, message, block) +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/common/src/main/kotlin/org/junit/Test.kt b/libraries/kotlin.test/common/src/main/kotlin/org/junit/Test.kt index 520f0f847ac..4f4196820c9 100644 --- a/libraries/kotlin.test/common/src/main/kotlin/org/junit/Test.kt +++ b/libraries/kotlin.test/common/src/main/kotlin/org/junit/Test.kt @@ -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() diff --git a/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/AnnotationsTest.kt b/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/AnnotationsTest.kt index f70698a86b6..dd6e1340e36 100644 --- a/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/AnnotationsTest.kt +++ b/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/AnnotationsTest.kt @@ -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) } diff --git a/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/BasicAssertionsTest.kt b/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/BasicAssertionsTest.kt index 336d7e00b26..37955a9ae98 100644 --- a/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/BasicAssertionsTest.kt +++ b/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/BasicAssertionsTest.kt @@ -30,24 +30,23 @@ class BasicAssertionsTest { assertFailsWith { throw AssertionError() } } - @Test fun testAssertFailsWithFails() { + @Test + fun testAssertFailsWithFails() { assertTrue(true) // at least one assertion required for qunit - withDefaultAsserter run@ { + withDefaultAsserter run@{ try { assertFailsWith { throw IllegalArgumentException() } - } - catch (e: AssertionError) { + } catch (e: AssertionError) { return@run } throw AssertionError("Expected to fail") } - withDefaultAsserter run@ { + withDefaultAsserter run@{ try { - assertFailsWith { } - } - catch (e: AssertionError) { + assertFailsWith { } + } 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) } } diff --git a/libraries/kotlin.test/js/it/src/test/kotlin/MainTest.kt b/libraries/kotlin.test/js/it/src/test/kotlin/MainTest.kt index c5fadc0b954..b86c1a8a157 100644 --- a/libraries/kotlin.test/js/it/src/test/kotlin/MainTest.kt +++ b/libraries/kotlin.test/js/it/src/test/kotlin/MainTest.kt @@ -5,23 +5,29 @@ var value = 5 class SimpleTest { - @BeforeTest fun beforeFun() { + @BeforeTest + fun beforeFun() { value *= 2 } - @AfterTest fun afterFun() { + @AfterTest + fun afterFun() { value /= 2 } - @Test fun testFoo() { + @Test + fun testFoo() { assertNotEquals(value, foo()) } - @Test fun testBar() { + @Test + fun testBar() { assertEquals(value, foo()) } - @Ignore @Test fun testFooWrong() { + @Ignore + @Test + fun testFooWrong() { assertEquals(20, foo()) } @@ -29,7 +35,8 @@ class SimpleTest { @Ignore class TestTest { - @Test fun emptyTest() { + @Test + fun emptyTest() { } } diff --git a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/DefaultJsAsserter.kt b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/DefaultJsAsserter.kt index 98e3ab99333..8ca95bdda6a 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/DefaultJsAsserter.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/DefaultJsAsserter.kt @@ -58,8 +58,7 @@ internal object DefaultJsAsserter : Asserter { override fun assertTrue(lazyMessage: () -> String?, actual: Boolean) { if (!actual) { failWithMessage(lazyMessage) - } - else { + } else { invokeHook(true, lazyMessage) } } @@ -89,8 +88,7 @@ internal object DefaultJsAsserter : Asserter { override val actual: Any? = a override val lazyMessage: () -> String? = lazyMessage }) - } - finally { + } finally { e = undefined a = undefined } diff --git a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/TestApi.kt b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/TestApi.kt index 393b31ffd07..67c198b7d9a 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/TestApi.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/TestApi.kt @@ -21,9 +21,8 @@ internal fun setAdapter(adapter: dynamic) { if (js("typeof adapter === 'string'")) { NAME_TO_ADAPTER[adapter]?.let { setAdapter(it.invoke()) - }?: throw IllegalArgumentException("Unsupported test framework adapter: '$adapter'") - } - else { + } ?: throw IllegalArgumentException("Unsupported test framework adapter: '$adapter'") + } else { currentAdapter = adapter } } @@ -74,8 +73,9 @@ internal fun detectAdapter() = when { } internal val NAME_TO_ADAPTER: Map FrameworkAdapter> = mapOf( - "qunit" to ::QUnitAdapter, - "jasmine" to ::JasmineLikeAdapter, - "mocha" to ::JasmineLikeAdapter, - "jest" to ::JasmineLikeAdapter, - "auto" to ::detectAdapter) \ No newline at end of file + "qunit" to ::QUnitAdapter, + "jasmine" to ::JasmineLikeAdapter, + "mocha" to ::JasmineLikeAdapter, + "jest" to ::JasmineLikeAdapter, + "auto" to ::detectAdapter +) \ No newline at end of file diff --git a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/Externals.kt b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/Externals.kt index 0927eda7cd9..246df3d733a 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/Externals.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/Externals.kt @@ -14,9 +14,10 @@ internal external object QUnit { fun skip(name: String, testFn: (dynamic) -> Unit): Unit } -/** +/* * Jasmine/Mocha/Jest API */ + internal external fun describe(name: String, fn: () -> Unit) internal external fun xdescribe(name: String, fn: () -> Unit) internal external fun it(name: String, fn: () -> Unit) diff --git a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/JasmineLikeAdapter.kt b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/JasmineLikeAdapter.kt index d70006240b1..56b6781ed20 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/JasmineLikeAdapter.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/JasmineLikeAdapter.kt @@ -15,8 +15,7 @@ internal class JasmineLikeAdapter : FrameworkAdapter { override fun suite(name: String, ignored: Boolean, suiteFn: () -> Unit) { if (ignored) { xdescribe(name, suiteFn) - } - else { + } else { describe(name, suiteFn) } } @@ -24,8 +23,7 @@ internal class JasmineLikeAdapter : FrameworkAdapter { override fun test(name: String, ignored: Boolean, testFn: () -> Unit) { if (ignored) { xit(name, testFn) - } - else { + } else { it(name, testFn) } } diff --git a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/QUnitAdapter.kt b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/QUnitAdapter.kt index 764895457a8..2d5d7990cf9 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/QUnitAdapter.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/adapters/QUnitAdapter.kt @@ -25,8 +25,7 @@ internal class QUnitAdapter : FrameworkAdapter { override fun test(name: String, ignored: Boolean, testFn: () -> Unit) { if (ignored or ignoredSuite) { QUnit.skip(name, wrapTest(testFn)) - } - else { + } else { QUnit.test(name, wrapTest(testFn)) } } diff --git a/libraries/kotlin.test/js/src/main/kotlin/org/junit/junitTest.kt b/libraries/kotlin.test/js/src/main/kotlin/org/junit/junitTest.kt index 843566c707c..ba85ebb7e7b 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/org/junit/junitTest.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/org/junit/junitTest.kt @@ -5,7 +5,9 @@ package org.junit -@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 +) actual typealias Test = kotlin.test.Test diff --git a/libraries/kotlin.test/junit/src/main/kotlin/Annotations.kt b/libraries/kotlin.test/junit/src/main/kotlin/Annotations.kt index 1067d376cca..7540bf6c29e 100644 --- a/libraries/kotlin.test/junit/src/main/kotlin/Annotations.kt +++ b/libraries/kotlin.test/junit/src/main/kotlin/Annotations.kt @@ -6,6 +6,7 @@ @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") @file:JvmPackageName("kotlin.test.junit.annotations") + package kotlin.test public actual typealias Test = org.junit.Test diff --git a/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt index bd86c6c5243..c276ec2d63e 100644 --- a/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt +++ b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt @@ -6,6 +6,7 @@ @file:kotlin.jvm.JvmMultifileClass @file:kotlin.jvm.JvmName("AssertionsKt") @file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") + package kotlin.test import kotlin.internal.* @@ -32,7 +33,8 @@ private fun assertFailsWithImpl(exceptionClass: Class, messag /** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */ -actual fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T = assertFailsWithImpl(exceptionClass.java, message, block) +actual fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T = + assertFailsWithImpl(exceptionClass.java, message, block) /** diff --git a/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt b/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt index 1b8bd54dd92..e9a24a43bcf 100644 --- a/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt +++ b/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt @@ -4,6 +4,7 @@ */ @file:Suppress("DEPRECATION") + package kotlin.test.tests import org.junit.Assert diff --git a/libraries/kotlin.test/jvm/src/test/kotlin/TestJVMTest.kt b/libraries/kotlin.test/jvm/src/test/kotlin/TestJVMTest.kt index 1f9bdc38033..80c6299fc65 100644 --- a/libraries/kotlin.test/jvm/src/test/kotlin/TestJVMTest.kt +++ b/libraries/kotlin.test/jvm/src/test/kotlin/TestJVMTest.kt @@ -12,8 +12,7 @@ class TestJVMTest { private fun expectAssertion(checkAssertion: (String?) -> Unit, block: () -> Unit) { try { block() - } - catch (e: AssertionError) { + } catch (e: AssertionError) { checkAssertion(e.message) return } @@ -30,67 +29,68 @@ class TestJVMTest { @Test fun assertEqualsMessage() { - expectAssertion( { msg -> - assertNotNull(msg); msg!! - assertTrue { msg.contains(expected.toString()) } - assertTrue { msg.contains(actual.toString()) } - assertFalse { msg.startsWith(".") } - }, { assertEquals(expected, actual) }) + expectAssertion({ msg -> + assertNotNull(msg); msg!! + assertTrue { msg.contains(expected.toString()) } + assertTrue { msg.contains(actual.toString()) } + assertFalse { msg.startsWith(".") } + }, { assertEquals(expected, actual) }) - expectAssertion( { msg -> - assertNotNull(msg); msg!! - assertTrue { msg.contains(message) } - assertTrue { msg.contains(expected.toString()) } - assertTrue { msg.contains(actual.toString()) } - } , { assertEquals(expected, actual, message) }) + expectAssertion({ msg -> + assertNotNull(msg); msg!! + assertTrue { msg.contains(message) } + assertTrue { msg.contains(expected.toString()) } + assertTrue { msg.contains(actual.toString()) } + }, { assertEquals(expected, actual, message) }) } @Test fun assertNotEqualsMessage() { - expectAssertion( { msg -> - assertNotNull(msg); msg!! - assertTrue { msg.contains(actual.toString()) } - assertFalse { msg.startsWith(".") } - }, { assertNotEquals(actual, actual) }) + expectAssertion({ msg -> + assertNotNull(msg); msg!! + assertTrue { msg.contains(actual.toString()) } + assertFalse { msg.startsWith(".") } + }, { assertNotEquals(actual, actual) }) - expectAssertion( { msg -> - assertNotNull(msg); msg!! - assertTrue { msg.contains(message) } - assertTrue { msg.contains(actual.toString()) } - } , { assertNotEquals(actual, actual, message) }) + expectAssertion({ msg -> + assertNotNull(msg); msg!! + assertTrue { msg.contains(message) } + assertTrue { msg.contains(actual.toString()) } + }, { assertNotEquals(actual, actual, message) }) } @Test fun assertTrueMessage() { - expectAssertion( { msg -> assertNotNull(msg) }, { assertTrue(false) }) - expectAssertion( { msg -> assertNotNull(msg) }, { assertTrue { false } }) - expectAssertion( { msg -> assertNotNull(msg) }, { assertTrue(null) { false } }) - expectAssertion( { msg -> msg!!.contains(message)}, { assertTrue(false, message)}) - expectAssertion( { msg -> msg!!.contains(message)}, { assertTrue(message) { false }}) + expectAssertion({ msg -> assertNotNull(msg) }, { assertTrue(false) }) + expectAssertion({ msg -> assertNotNull(msg) }, { assertTrue { false } }) + expectAssertion({ msg -> assertNotNull(msg) }, { assertTrue(null) { false } }) + expectAssertion({ msg -> msg!!.contains(message) }, { assertTrue(false, message) }) + expectAssertion({ msg -> msg!!.contains(message) }, { assertTrue(message) { false } }) } @Test fun assertFalseMessage() { - expectAssertion( { msg -> assertNotNull(msg) }, { assertFalse(true) }) - expectAssertion( { msg -> assertNotNull(msg) }, { assertFalse { true } }) - expectAssertion( { msg -> assertNotNull(msg) }, { assertFalse(null) { true } }) - expectAssertion( { msg -> assertTrue(msg!!.contains(message)) }, { assertFalse(true, message)}) - expectAssertion( { msg -> assertTrue(msg!!.contains(message)) }, { assertFalse(message) { true }}) + expectAssertion({ msg -> assertNotNull(msg) }, { assertFalse(true) }) + expectAssertion({ msg -> assertNotNull(msg) }, { assertFalse { true } }) + expectAssertion({ msg -> assertNotNull(msg) }, { assertFalse(null) { true } }) + expectAssertion({ msg -> assertTrue(msg!!.contains(message)) }, { assertFalse(true, message) }) + expectAssertion({ msg -> assertTrue(msg!!.contains(message)) }, { assertFalse(message) { true } }) } @Test fun assertNotNullMessage() { - expectAssertion( { msg -> msg!! }, { assertNotNull(null) }) - expectAssertion( { msg -> assertTrue(msg!!.contains(message)) }, { assertNotNull(null, message)}) + expectAssertion({ msg -> msg!! }, { assertNotNull(null) }) + expectAssertion({ msg -> assertTrue(msg!!.contains(message)) }, { assertNotNull(null, message) }) } @Test fun assertNullMessage() { - expectAssertion( { msg -> msg!! }, { assertNull(actual) }) - expectAssertion( { msg -> msg!! - assertTrue(msg.contains(message)) - assertTrue(msg.contains(actual.toString())) - }, { assertNull(actual, message)}) + expectAssertion({ msg -> msg!! }, { assertNull(actual) }) + expectAssertion({ msg -> + msg!! + assertTrue(msg.contains(message)) + assertTrue(msg.contains(actual.toString())) + }, { assertNull(actual, message) }) } } \ No newline at end of file diff --git a/libraries/kotlin.test/testng/src/main/kotlin/Annotations.kt b/libraries/kotlin.test/testng/src/main/kotlin/Annotations.kt index 053673b5ac9..e8fdd3f55d3 100644 --- a/libraries/kotlin.test/testng/src/main/kotlin/Annotations.kt +++ b/libraries/kotlin.test/testng/src/main/kotlin/Annotations.kt @@ -6,6 +6,7 @@ @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") @file:JvmPackageName("kotlin.test.testng.annotations") + package kotlin.test public actual typealias Test = org.testng.annotations.Test