diff --git a/libraries/kotlin.test/common/build.gradle b/libraries/kotlin.test/common/build.gradle index 0b90b1b8300..873c6512f48 100644 --- a/libraries/kotlin.test/common/build.gradle +++ b/libraries/kotlin.test/common/build.gradle @@ -6,14 +6,6 @@ dependencies { compile project(':kotlin-stdlib-common') } -sourceSets { - test { - kotlin { - srcDir 'src/test' - exclude '**' - } - } -} // common block diff --git a/libraries/kotlin.test/common/src/test/kotlin.jvm/UtilsJVM.kt b/libraries/kotlin.test/common/src/test/kotlin.jvm/UtilsJVM.kt deleted file mode 100644 index a8998de9adf..00000000000 --- a/libraries/kotlin.test/common/src/test/kotlin.jvm/UtilsJVM.kt +++ /dev/null @@ -1,7 +0,0 @@ -package kotlin.test.tests - -@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") -internal operator fun String.contains(sub: String) = (this as java.lang.String).contains(sub) - -@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") -internal fun String.startsWith(other: String) = (this as java.lang.String).startsWith(other) 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 224152dab20..735bbc0ee17 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 @@ -14,49 +14,55 @@ class BasicAssertionsTest { assertEquals("a", "a") } - @Test(expected = AssertionError::class) + @Test + fun testAssertFailsWith() { + assertFailsWith { throw IllegalStateException() } + assertFailsWith { throw AssertionError() } + + run { + try { + assertFailsWith { throw IllegalArgumentException() } + } + catch (e: AssertionError) { + return@run + } + throw AssertionError("Expected to fail") + } + + run { + try { + assertFailsWith { } + } + catch (e: AssertionError) { + return@run + } + throw AssertionError("Expected to fail") + } + } + + @Test fun testAssertEqualsFails() { - assertEquals(1, 2) + assertFailsWith { assertEquals(1, 2) } } @Test fun testAssertTrue() { assertTrue(true) - } - - @Test - fun testAssertTrueWithLambda() { assertTrue { true } } - @Test(expected = AssertionError::class) + @Test() fun testAssertTrueFails() { - assertTrue(false) - } - - @Test(expected = AssertionError::class) - fun testAssertTrueWithLambdaFails() { - assertTrue { false } + assertFailsWith { assertTrue(false) } + assertFailsWith { assertTrue { false } } } @Test fun testAssertFalse() { assertFalse(false) - } - - @Test - fun testAssertFalseLambda() { assertFalse { false } - } - - @Test(expected = AssertionError::class) - fun testAssertFalseFails() { - assertFalse(true) - } - - @Test(expected = AssertionError::class) - fun testAssertFalseWithLambdaFails() { - assertFalse { true } + assertFailsWith { assertFalse(true) } + assertFailsWith { assertFalse { true } } } @Test @@ -64,10 +70,9 @@ class BasicAssertionsTest { assertFails { throw IllegalStateException() } } - @Test(expected = AssertionError::class) + @Test() fun testAssertFailsFails() { - assertFails { } - Assert.fail("Shouldn't pass here") + assertFailsWith { assertFails { } } } @@ -76,9 +81,9 @@ class BasicAssertionsTest { assertNotEquals(1, 2) } - @Test(expected = AssertionError::class) + @Test() fun testAssertNotEqualsFails() { - assertNotEquals(1, 1) + assertFailsWith { assertNotEquals(1, 1) } } @Test @@ -86,9 +91,9 @@ class BasicAssertionsTest { assertNotNull(true) } - @Test(expected = AssertionError::class) + @Test() fun testAssertNotNullFails() { - assertNotNull(null) + assertFailsWith { assertNotNull(null) } } @Test @@ -96,11 +101,13 @@ class BasicAssertionsTest { assertNotNull("") { assertEquals("", it) } } - @Test(expected = AssertionError::class) + @Test fun testAssertNotNullLambdaFails() { - assertNotNull(null) { - @Suppress("UNREACHABLE_CODE") - assertNotNull(it) + assertFailsWith { + val value: String? = null + assertNotNull(value) { + it.substring(0, 0) + } } } @@ -109,23 +116,20 @@ class BasicAssertionsTest { assertNull(null) } - @Test(expected = AssertionError::class) + @Test fun testAssertNullFails() { - assertNull(true) + assertFailsWith { assertNull("") } } - @Test(expected = AssertionError::class) + @Test() fun testFail() { - fail("should fail") + assertFailsWith { fail("should fail") } } @Test fun testExpect() { expect(1) { 1 } + assertFailsWith { expect(1) { 2 } } } - @Test(expected = AssertionError::class) - fun testExpectFails() { - expect(1) { 2 } - } } \ No newline at end of file diff --git a/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/util.kt b/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/util.kt deleted file mode 100644 index 0eb8052436d..00000000000 --- a/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/util.kt +++ /dev/null @@ -1,22 +0,0 @@ -package kotlin.test.tests - -import java.util.* - -internal fun listOf(vararg elements: T): List { - val result = ArrayList(elements.size) - for (e in elements) { - result.add(e) - } - - return result -} - -internal fun setOf(vararg elements: T): Set { - val result = HashSet(elements.size) - for (e in elements) { - result.add(e) - } - - return result -} - diff --git a/libraries/kotlin.test/js/build.gradle b/libraries/kotlin.test/js/build.gradle index bb08f97cc8d..e8eb1427d73 100644 --- a/libraries/kotlin.test/js/build.gradle +++ b/libraries/kotlin.test/js/build.gradle @@ -18,6 +18,9 @@ compileKotlin2Js { compileTestKotlin2Js { kotlinOptions.freeCompilerArgs = ["-Xallow-kotlin-package"] + kotlinOptions { + metaInfo = false + } } diff --git a/libraries/kotlin.test/common/src/test/kotlin.jvm/BasicAssertionsJVMTest.kt b/libraries/kotlin.test/jvm/src/test/kotlin/BasicAssertionsJVMTest.kt similarity index 100% rename from libraries/kotlin.test/common/src/test/kotlin.jvm/BasicAssertionsJVMTest.kt rename to libraries/kotlin.test/jvm/src/test/kotlin/BasicAssertionsJVMTest.kt diff --git a/libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/CollectionAssertionTest.kt b/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt similarity index 100% rename from libraries/kotlin.test/common/src/test/kotlin/kotlin/test/tests/CollectionAssertionTest.kt rename to libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt diff --git a/libraries/kotlin.test/common/src/test/kotlin.jvm/StackTraceJVMTest.kt b/libraries/kotlin.test/jvm/src/test/kotlin/StackTraceJVMTest.kt similarity index 100% rename from libraries/kotlin.test/common/src/test/kotlin.jvm/StackTraceJVMTest.kt rename to libraries/kotlin.test/jvm/src/test/kotlin/StackTraceJVMTest.kt diff --git a/libraries/kotlin.test/common/src/test/kotlin.jvm/TestJVMTest.kt b/libraries/kotlin.test/jvm/src/test/kotlin/TestJVMTest.kt similarity index 100% rename from libraries/kotlin.test/common/src/test/kotlin.jvm/TestJVMTest.kt rename to libraries/kotlin.test/jvm/src/test/kotlin/TestJVMTest.kt