Make kotlin-test tests compile as tests for multiplatform project
Also remove utils not needed anymore.
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
package kotlin.test.tests
|
||||
|
||||
import kotlin.test.*
|
||||
import org.junit.*
|
||||
|
||||
class BasicAssertionsJVMTest {
|
||||
@Test
|
||||
fun testFailsWith() {
|
||||
assertFailsWith(IllegalArgumentException::class) {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
fun testFailsWithFails() {
|
||||
assertFailsWith(IllegalArgumentException::class) {
|
||||
throw IllegalStateException()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFailsWithMessage() {
|
||||
assertFailsWith<IllegalArgumentException>() {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
@Test
|
||||
fun testFailsWithClassMessage() {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(assertFailsWith((Class.forName("java.lang.IllegalArgumentException") as Class<Throwable>).kotlin) {
|
||||
throw IllegalArgumentException()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package kotlin.test.tests
|
||||
|
||||
import org.junit.Test
|
||||
import kotlin.test.*
|
||||
|
||||
// NOTE: These tests verify line numbers of stack frames, so they might be quite fragile to reordering etc
|
||||
|
||||
class StackTraceJVMTest {
|
||||
|
||||
@Test
|
||||
fun testCurrentStackTrace() {
|
||||
/* <-- line number */ val topFrame = currentStackTrace()[0]
|
||||
assertEquals("StackTraceJVMTest.kt", topFrame.fileName)
|
||||
assertEquals(12, topFrame.lineNumber)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToDo() {
|
||||
todo {
|
||||
fail("Shouldn't pass here")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.test.tests
|
||||
|
||||
import kotlin.test.*
|
||||
import org.junit.Test
|
||||
|
||||
class TestJVMTest {
|
||||
|
||||
private fun expectAssertion(checkAssertion: (String?) -> Unit, block: () -> Unit) {
|
||||
try {
|
||||
block()
|
||||
}
|
||||
catch (e: AssertionError) {
|
||||
checkAssertion(e.message)
|
||||
return
|
||||
}
|
||||
fail("Expected AssertionError to be thrown.")
|
||||
}
|
||||
|
||||
private val message = "Some details"
|
||||
private val expected = object {
|
||||
override fun toString() = "expected"
|
||||
}
|
||||
private val actual = object {
|
||||
override fun toString() = "actual"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun assertEqualsMessage() {
|
||||
expectAssertion( { msg ->
|
||||
assertNotNull(msg); msg!!
|
||||
assertTrue { msg.contains(expected.toString()) }
|
||||
assertTrue { msg.contains(actual.toString()) }
|
||||
assertFalse { msg.startsWith(".") }
|
||||
}, { assertEquals<Any>(expected, actual) })
|
||||
|
||||
expectAssertion( { msg ->
|
||||
assertNotNull(msg); msg!!
|
||||
assertTrue { msg.contains(message) }
|
||||
assertTrue { msg.contains(expected.toString()) }
|
||||
assertTrue { msg.contains(actual.toString()) }
|
||||
} , { assertEquals<Any>(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(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 }})
|
||||
}
|
||||
|
||||
@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 }})
|
||||
}
|
||||
|
||||
@Test
|
||||
fun assertNotNullMessage() {
|
||||
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)})
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
+50
-46
@@ -14,49 +14,55 @@ class BasicAssertionsTest {
|
||||
assertEquals("a", "a")
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
@Test
|
||||
fun testAssertFailsWith() {
|
||||
assertFailsWith<IllegalStateException> { throw IllegalStateException() }
|
||||
assertFailsWith<AssertionError> { throw AssertionError() }
|
||||
|
||||
run {
|
||||
try {
|
||||
assertFailsWith<IllegalStateException> { throw IllegalArgumentException() }
|
||||
}
|
||||
catch (e: AssertionError) {
|
||||
return@run
|
||||
}
|
||||
throw AssertionError("Expected to fail")
|
||||
}
|
||||
|
||||
run {
|
||||
try {
|
||||
assertFailsWith<IllegalStateException> { }
|
||||
}
|
||||
catch (e: AssertionError) {
|
||||
return@run
|
||||
}
|
||||
throw AssertionError("Expected to fail")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAssertEqualsFails() {
|
||||
assertEquals(1, 2)
|
||||
assertFailsWith<AssertionError> { 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<AssertionError> { assertTrue(false) }
|
||||
assertFailsWith<AssertionError> { 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<AssertionError> { assertFalse(true) }
|
||||
assertFailsWith<AssertionError> { 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<AssertionError> { assertFails { } }
|
||||
}
|
||||
|
||||
|
||||
@@ -76,9 +81,9 @@ class BasicAssertionsTest {
|
||||
assertNotEquals(1, 2)
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
@Test()
|
||||
fun testAssertNotEqualsFails() {
|
||||
assertNotEquals(1, 1)
|
||||
assertFailsWith<AssertionError> { assertNotEquals(1, 1) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,9 +91,9 @@ class BasicAssertionsTest {
|
||||
assertNotNull(true)
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
@Test()
|
||||
fun testAssertNotNullFails() {
|
||||
assertNotNull(null)
|
||||
assertFailsWith<AssertionError> { 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<AssertionError> {
|
||||
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<AssertionError> { assertNull("") }
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
@Test()
|
||||
fun testFail() {
|
||||
fail("should fail")
|
||||
assertFailsWith<AssertionError> { fail("should fail") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testExpect() {
|
||||
expect(1) { 1 }
|
||||
assertFailsWith<AssertionError> { expect(1) { 2 } }
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
fun testExpectFails() {
|
||||
expect(1) { 2 }
|
||||
}
|
||||
}
|
||||
-137
@@ -1,137 +0,0 @@
|
||||
@file:Suppress("DEPRECATION")
|
||||
package kotlin.test.tests
|
||||
|
||||
import org.junit.*
|
||||
import java.util.*
|
||||
import kotlin.test.*
|
||||
|
||||
class CollectionAssertionTest {
|
||||
@Test
|
||||
fun testList() {
|
||||
assert(listOf(1, 2, 3)) {
|
||||
sizeShouldBe(3)
|
||||
elementAtShouldBe(0, 1)
|
||||
elementAtShouldComply(0) { it > 0 }
|
||||
lastElementShouldBe(3)
|
||||
containsAll(1, 2)
|
||||
|
||||
shouldBe(listOf(1, 2, 3))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSet() {
|
||||
assert(setOf(1, 2, 3)) {
|
||||
sizeShouldBe(3)
|
||||
elementAtShouldBe(0, 1)
|
||||
elementAtShouldComply(0) { it > 0 }
|
||||
lastElementShouldBe(3)
|
||||
containsAll(1, 2)
|
||||
|
||||
shouldBeSet(setOf(1, 2, 3))
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
fun testSizeShouldBeFails() {
|
||||
assert(listOf(1, 2, 3)) {
|
||||
sizeShouldBe(1)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
fun testElementAtShouldBeFail() {
|
||||
assert(listOf(1, 2, 3)) {
|
||||
elementAtShouldBe(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
fun testElementAtShouldComplyFail() {
|
||||
assert(listOf(1, 2, 3)) {
|
||||
elementAtShouldComply(0) { it < 0 }
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
fun testLastElementFail() {
|
||||
assert(listOf(1, 2, 3)) {
|
||||
lastElementShouldBe(0)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchElementException::class)
|
||||
fun testLastElementOnEmptyFail() {
|
||||
assert(listOf<Int>()) {
|
||||
lastElementShouldBe(0)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
fun testContainsAll() {
|
||||
assert(listOf(1, 2, 3)) {
|
||||
containsAll(1, 8)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
fun testContainsAllWithSet() {
|
||||
assert(setOf(1, 2, 3)) {
|
||||
containsAll(1, 8)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testShouldBeLess() {
|
||||
try {
|
||||
assert(listOf(1, 2, 3)) {
|
||||
shouldBe(listOf(1, 2, 3, 4))
|
||||
}
|
||||
Assert.fail("It shouldn't pass here")
|
||||
} catch (e: AssertionError) {
|
||||
assertTrue { "[4]" in e.message!! }
|
||||
assertTrue { "shorter" in e.message!! }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testShouldBeLonger() {
|
||||
try {
|
||||
assert(listOf(1, 2, 3)) {
|
||||
shouldBe(listOf(1, 2))
|
||||
}
|
||||
Assert.fail("It shouldn't pass here")
|
||||
} catch (e: AssertionError) {
|
||||
assertTrue { "[3]" in e.message!! }
|
||||
assertTrue { "longer" in e.message!! }
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
fun testShouldBeSetExtra() {
|
||||
assert(setOf(1, 2, 3)) {
|
||||
shouldBeSet(setOf(1, 2))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testShouldBeSetExact() {
|
||||
assert(setOf(1, 2, 3)) {
|
||||
shouldBeSet(setOf(1, 2, 3))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testShouldBeSetExactVararg() {
|
||||
assert(setOf(1, 2, 3)) {
|
||||
shouldBeSet(1, 2, 3)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
fun testShouldBeSetMissing() {
|
||||
assert(setOf(1, 2, 3)) {
|
||||
shouldBeSet(setOf(1, 2, 3, 4))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package kotlin.test.tests
|
||||
|
||||
import java.util.*
|
||||
|
||||
internal fun <T> listOf(vararg elements: T): List<T> {
|
||||
val result = ArrayList<T>(elements.size)
|
||||
for (e in elements) {
|
||||
result.add(e)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun <T> setOf(vararg elements: T): Set<T> {
|
||||
val result = HashSet<T>(elements.size)
|
||||
for (e in elements) {
|
||||
result.add(e)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user