f624800b84
I was forced to manually do update the following files, because otherwise they would be ignored according .gitignore settings. Probably they should be deleted from repo. Interop/.idea/compiler.xml Interop/.idea/gradle.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml Interop/.idea/modules.xml Interop/.idea/modules/Indexer/Indexer.iml Interop/.idea/modules/Runtime/Runtime.iml Interop/.idea/modules/StubGenerator/StubGenerator.iml backend.native/backend.native.iml backend.native/bc.frontend/bc.frontend.iml backend.native/cli.bc/cli.bc.iml backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt backend.native/tests/link/lib/foo.kt backend.native/tests/link/lib/foo2.kt backend.native/tests/teamcity-test.property
195 lines
4.1 KiB
Kotlin
195 lines
4.1 KiB
Kotlin
/*
|
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
* that can be found in the LICENSE file.
|
|
*/
|
|
|
|
package kotlin.test.tests
|
|
|
|
import kotlin.test.*
|
|
|
|
class BasicAssertionsTest {
|
|
@Test
|
|
fun testAssertEquals() {
|
|
assertEquals(1, 1)
|
|
}
|
|
|
|
@Test
|
|
fun testAssertEqualsString() {
|
|
assertEquals("a", "a")
|
|
}
|
|
|
|
@Test
|
|
fun testAssertFailsWith() {
|
|
assertFailsWith<IllegalStateException> { throw IllegalStateException() }
|
|
assertFailsWith<AssertionError> { throw AssertionError() }
|
|
}
|
|
|
|
@Test
|
|
fun testAssertFailsWithFails() {
|
|
withDefaultAsserter run@ {
|
|
try {
|
|
assertFailsWith<IllegalStateException> { throw IllegalArgumentException() }
|
|
}
|
|
catch (e: AssertionError) {
|
|
return@run
|
|
}
|
|
throw AssertionError("Expected to fail")
|
|
}
|
|
withDefaultAsserter run@ {
|
|
try {
|
|
assertFailsWith<IllegalStateException> { }
|
|
}
|
|
catch (e: AssertionError) {
|
|
return@run
|
|
}
|
|
throw AssertionError("Expected to fail")
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun testAssertFailsWithClass() {
|
|
assertFailsWith<IllegalArgumentException> {
|
|
throw IllegalArgumentException("This is illegal")
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun testAssertFailsWithClassFails() {
|
|
checkFailedAssertion {
|
|
assertFailsWith<IllegalArgumentException> { throw IllegalStateException() }
|
|
}
|
|
|
|
checkFailedAssertion {
|
|
assertFailsWith<Exception> { }
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun testAssertEqualsFails() {
|
|
checkFailedAssertion { assertEquals(1, 2) }
|
|
}
|
|
|
|
@Test
|
|
fun testAssertTrue() {
|
|
assertTrue(true)
|
|
assertTrue { true }
|
|
}
|
|
|
|
@Test()
|
|
fun testAssertTrueFails() {
|
|
checkFailedAssertion { assertTrue(false) }
|
|
checkFailedAssertion { assertTrue { false } }
|
|
}
|
|
|
|
@Test
|
|
fun testAssertFalse() {
|
|
assertFalse(false)
|
|
assertFalse { false }
|
|
}
|
|
|
|
@Test
|
|
fun testAssertFalseFails() {
|
|
checkFailedAssertion { assertFalse(true) }
|
|
checkFailedAssertion{ assertFalse { true } }
|
|
}
|
|
|
|
@Test
|
|
fun testAssertFails() {
|
|
assertFails { throw IllegalStateException() }
|
|
}
|
|
|
|
@Test()
|
|
fun testAssertFailsFails() {
|
|
checkFailedAssertion { assertFails { } }
|
|
}
|
|
|
|
|
|
@Test
|
|
fun testAssertNotEquals() {
|
|
assertNotEquals(1, 2)
|
|
}
|
|
|
|
@Test()
|
|
fun testAssertNotEqualsFails() {
|
|
checkFailedAssertion { assertNotEquals(1, 1) }
|
|
}
|
|
|
|
@Test
|
|
fun testAssertNotNull() {
|
|
assertNotNull(true)
|
|
}
|
|
|
|
@Test()
|
|
fun testAssertNotNullFails() {
|
|
checkFailedAssertion { assertNotNull(null) }
|
|
}
|
|
|
|
@Test
|
|
fun testAssertNotNullLambda() {
|
|
assertNotNull("") { assertEquals("", it) }
|
|
}
|
|
|
|
@Test
|
|
fun testAssertNotNullLambdaFails() {
|
|
checkFailedAssertion {
|
|
val value: String? = null
|
|
assertNotNull(value) {
|
|
it.substring(0, 0)
|
|
}
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun testAssertNull() {
|
|
assertNull(null)
|
|
}
|
|
|
|
@Test
|
|
fun testAssertNullFails() {
|
|
checkFailedAssertion { assertNull("") }
|
|
}
|
|
|
|
@Test()
|
|
fun testFail() {
|
|
checkFailedAssertion { fail("should fail") }
|
|
}
|
|
|
|
@Test
|
|
fun testExpect() {
|
|
expect(1) { 1 }
|
|
}
|
|
|
|
@Test
|
|
fun testExpectFails() {
|
|
checkFailedAssertion { expect(1) { 2 } }
|
|
}
|
|
|
|
@Test
|
|
fun testContracts() {
|
|
open class S
|
|
class P(val str: String = "P") : S()
|
|
|
|
val s: S = P()
|
|
val p: Any = P("A")
|
|
|
|
assertTrue(s is P)
|
|
assertEquals("P", s.str)
|
|
assertFalse(p !is P)
|
|
assertEquals("A", p.str)
|
|
|
|
val nullableT: P? = P("N")
|
|
assertNotNull(nullableT)
|
|
assertEquals("N", nullableT.str)
|
|
}
|
|
}
|
|
|
|
|
|
private fun checkFailedAssertion(assertion: () -> Unit) {
|
|
assertFailsWith<AssertionError> { withDefaultAsserter(assertion) }
|
|
}
|
|
|
|
@Suppress("INVISIBLE_MEMBER")
|
|
private fun withDefaultAsserter(block: () -> Unit) {
|
|
block()
|
|
}
|