Make kotlin-test tests compile as tests for multiplatform project
Also remove utils not needed anymore.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
@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))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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)})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user