[K/N][tests] Move some more native tests to new testing infra
^KT-61259
This commit is contained in:
committed by
Space Team
parent
4080776fe3
commit
0a0da76a56
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 runtime.basic.statements0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun simple() {
|
||||
var a = 238
|
||||
a++
|
||||
println(a)
|
||||
--a
|
||||
println(a)
|
||||
}
|
||||
|
||||
class Foo() {
|
||||
val j = 2
|
||||
var i = 29
|
||||
|
||||
fun more() {
|
||||
i++
|
||||
}
|
||||
|
||||
fun less() {
|
||||
--i
|
||||
}
|
||||
}
|
||||
|
||||
fun fields() {
|
||||
val foo = Foo()
|
||||
foo.more()
|
||||
println(foo.i)
|
||||
foo.less()
|
||||
println(foo.i)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
simple()
|
||||
fields()
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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 runtime.basic.enum_equals
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class EnumA {
|
||||
A, B
|
||||
}
|
||||
|
||||
enum class EnumB {
|
||||
B
|
||||
}
|
||||
|
||||
fun main() {
|
||||
println(EnumA.A == EnumA.A)
|
||||
println(EnumA.A == EnumA.B)
|
||||
println(EnumA.A == EnumB.B)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 runtime.exceptions.catch1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
try {
|
||||
println("Before")
|
||||
foo()
|
||||
println("After")
|
||||
} catch (e: Throwable) {
|
||||
println("Caught Throwable")
|
||||
}
|
||||
|
||||
println("Done")
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
throw Error("Error happens")
|
||||
println("After in foo()")
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 runtime.exceptions.catch2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
try {
|
||||
println("Before")
|
||||
foo()
|
||||
println("After")
|
||||
} catch (e: Exception) {
|
||||
println("Caught Exception")
|
||||
} catch (e: Error) {
|
||||
println("Caught Error")
|
||||
} catch (e: Throwable) {
|
||||
println("Caught Throwable")
|
||||
}
|
||||
|
||||
println("Done")
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
throw Error("Error happens")
|
||||
println("After in foo()")
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 runtime.exceptions.catch7
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Throwable) {
|
||||
val message = e.message
|
||||
if (message != null) {
|
||||
println(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
throw Error("Error happens")
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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 runtime.exceptions.extend0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class C : Exception("OK")
|
||||
|
||||
@Test fun runTest() {
|
||||
try {
|
||||
throw C()
|
||||
} catch (e: Throwable) {
|
||||
println(e.message!!)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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 runtime.exceptions.rethtow
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
assertFailsWith<IllegalStateException>("My error") {
|
||||
try {
|
||||
error("My error")
|
||||
} catch (e: Throwable) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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 runtime.basic.throw0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val cond = 1
|
||||
if (cond == 2) throw RuntimeException()
|
||||
if (cond == 3) throw NoSuchElementException("no such element")
|
||||
if (cond == 4) throw Error("error happens")
|
||||
|
||||
println("Done")
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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 runtime.exceptions.throw_from_catch
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
assertFailsWith<IllegalStateException>("My another error") {
|
||||
try {
|
||||
error("My error")
|
||||
} catch (e: Throwable) {
|
||||
error("My another error")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 runtime.basic.initializers0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
init{
|
||||
println ("A::init")
|
||||
}
|
||||
|
||||
val a = 1
|
||||
|
||||
companion object :B(1) {
|
||||
init {
|
||||
println ("A::companion")
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
println("A::companion::foo")
|
||||
}
|
||||
}
|
||||
|
||||
object AObj : B(){
|
||||
init {
|
||||
println("A::Obj")
|
||||
}
|
||||
fun foo() {
|
||||
println("A::AObj::foo")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println("main")
|
||||
A.foo()
|
||||
A.foo()
|
||||
A.AObj.foo()
|
||||
A.AObj.foo()
|
||||
}
|
||||
|
||||
open class B(val a:Int, val b:Int) {
|
||||
constructor(a:Int):this (a, 0) {
|
||||
println("B::constructor(" + a.toString()+ ")")
|
||||
}
|
||||
constructor():this(0) {
|
||||
println("B::constructor()")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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 runtime.basic.initializers1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class TestClass {
|
||||
companion object {
|
||||
init {
|
||||
println("Init Test")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val t1 = TestClass()
|
||||
val t2 = TestClass()
|
||||
println("Done")
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
class A(val msg: String) {
|
||||
init {
|
||||
println("init $msg")
|
||||
}
|
||||
override fun toString(): String = msg
|
||||
}
|
||||
|
||||
val globalValue1 = 1
|
||||
val globalValue2 = A("globalValue2")
|
||||
val globalValue3 = A("globalValue3")
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(globalValue1.toString())
|
||||
println(globalValue2.toString())
|
||||
println(globalValue3.toString())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 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 runtime.basic.initializers3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class Foo(val bar: Int)
|
||||
|
||||
var x = Foo(42)
|
||||
|
||||
@Test fun runTest() {
|
||||
println(x.bar)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 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 runtime.basic.initializers4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1
|
||||
val DOUBLE = Double.MAX_VALUE - 1.0
|
||||
|
||||
@Test fun runTest() {
|
||||
println(INT_MAX_POWER_OF_TWO)
|
||||
println(DOUBLE > 0.0)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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 runtime.basic.initializers5
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
object A {
|
||||
val a = 42
|
||||
val b = A.a
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(A.b)
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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 runtime.basic.initializers7
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
object A {
|
||||
init {
|
||||
assertAUninitialized()
|
||||
}
|
||||
val a1 = 7
|
||||
val a2 = 12
|
||||
}
|
||||
|
||||
// Check that A is initialized dynamically.
|
||||
fun assertAUninitialized() {
|
||||
assertEquals(0, A.a1)
|
||||
assertEquals(0, A.a2)
|
||||
}
|
||||
|
||||
object B {
|
||||
init {
|
||||
assertBUninitialized()
|
||||
}
|
||||
val b1 = A.a2
|
||||
val b2 = C.c1
|
||||
}
|
||||
|
||||
// Check that B is initialized dynamically.
|
||||
fun assertBUninitialized() {
|
||||
assertEquals(0, B.b1)
|
||||
assertEquals(0, B.b2)
|
||||
}
|
||||
|
||||
object C {
|
||||
init {
|
||||
assertCUninitialized()
|
||||
}
|
||||
val c1 = 42
|
||||
val c2 = A.a1
|
||||
val c3 = B.b1
|
||||
val c4 = B.b2
|
||||
}
|
||||
|
||||
// Check that C is initialized dynamically.
|
||||
fun assertCUninitialized() {
|
||||
assertEquals(0, C.c1)
|
||||
assertEquals(0, C.c2)
|
||||
assertEquals(0, C.c3)
|
||||
assertEquals(0, C.c4)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
assertEquals(A.a1, C.c2)
|
||||
assertEquals(A.a2, C.c3)
|
||||
assertEquals(C.c1, C.c4)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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 runtime.basic.initializers8
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
var globalString = "abc"
|
||||
|
||||
@Test fun runTest() {
|
||||
assertEquals("abc", globalString)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 runtime.basic.interface0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A {
|
||||
fun b() = c()
|
||||
fun c()
|
||||
}
|
||||
|
||||
class B(): A {
|
||||
override fun c() {
|
||||
println("PASSED")
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val a:A = B()
|
||||
a.b()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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 datagen.literals.listof1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val list = foo()
|
||||
println(list === foo())
|
||||
println(list.toString())
|
||||
}
|
||||
|
||||
fun foo(): List<String> {
|
||||
return listOf("a", "b", "c")
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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 datagen.literals.strdedup1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val str1 = "Hello"
|
||||
val str2 = "Hello"
|
||||
println(str1 == str2)
|
||||
println(str1 === str2)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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 datagen.literals.strdedup2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val str1 = ""
|
||||
val str2 = "hello".subSequence(2, 2)
|
||||
println(str1 == str2)
|
||||
println(str1 === str2)
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
// Ideally, this test must fail with gcType=NOOP with any cache mode.
|
||||
// KT-63944: unfortunately, GC flavours are silently not switched in presence of caches.
|
||||
// As soon the issue would be fixed, please remove `&& cacheMode=NO` from next line.
|
||||
// IGNORE_NATIVE: gcType=NOOP && cacheMode=NO
|
||||
|
||||
import kotlin.native.internal.*
|
||||
import kotlin.test.*
|
||||
|
||||
value class BoxInt(val x: Int)
|
||||
value class BoxBoxInt(val x: BoxInt)
|
||||
data class A(val x: Int)
|
||||
value class BoxA(val x: A)
|
||||
value class BoxBoxA(val x: BoxA)
|
||||
|
||||
|
||||
class X(
|
||||
val a: Int,
|
||||
val b: List<Int>,
|
||||
val c: IntArray,
|
||||
val d: Array<Int>,
|
||||
val e: Array<Any>,
|
||||
val f: BoxInt,
|
||||
val g: BoxBoxInt,
|
||||
val h: A,
|
||||
val i: BoxA,
|
||||
val j: BoxBoxA,
|
||||
val k: Any?,
|
||||
val l: Any?,
|
||||
val m: Any?,
|
||||
val n: Any?,
|
||||
val o: IntArray?
|
||||
) {
|
||||
val p by lazy { 1 }
|
||||
lateinit var q: IntArray
|
||||
lateinit var r: IntArray
|
||||
}
|
||||
|
||||
fun `big class with mixed values`() {
|
||||
val lst = listOf(1, 2, 3)
|
||||
val ia = intArrayOf(1, 2, 3)
|
||||
val ia2 = intArrayOf(3, 4, 5)
|
||||
val ai = arrayOf(1, 2, 3)
|
||||
val astr: Array<Any> = arrayOf("123", "456", 1, 2, 3)
|
||||
val bi = BoxInt(2)
|
||||
val bbi = BoxBoxInt(BoxInt(3))
|
||||
val a1 = A(1)
|
||||
val a2 = A(2)
|
||||
val a3 = A(3)
|
||||
val a6 = A(3)
|
||||
val x = X(
|
||||
1, lst, ia, ai, astr, bi, bbi,
|
||||
a1, BoxA(a2), BoxBoxA(BoxA(a3)),
|
||||
4, BoxInt(5), BoxA(a6), null, null
|
||||
)
|
||||
x.r = ia2
|
||||
val fields = x.collectReferenceFieldValues()
|
||||
assertEquals(12, fields.size)
|
||||
// not using assertContains because of ===
|
||||
assertTrue(fields.any { it === lst }, "Should contain list $lst")
|
||||
assertTrue(fields.any { it === ia }, "Should contain int array $ia")
|
||||
assertTrue(fields.any { it === ia2 }, "Should contain int array $ia2")
|
||||
assertTrue(fields.any { it === ai }, "Should contain array of int $ai")
|
||||
assertTrue(fields.any { it === astr }, "Should contain array of string $astr")
|
||||
assertTrue(fields.any { it === a1 }, "Should contain A(1)")
|
||||
assertTrue(fields.any { it === a2 }, "Should contain A(2)")
|
||||
assertTrue(fields.any { it === a3 }, "Should contain A(3)")
|
||||
assertTrue(fields.any { it.toString().startsWith("Lazy value not initialized yet") }, "Should contain lazy delegate")
|
||||
assertContains(fields, 4)
|
||||
assertContains(fields, BoxInt(5))
|
||||
assertContains(fields, BoxA(a6))}
|
||||
|
||||
fun `call on primitive`() {
|
||||
assertEquals(1.collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals(123456.collectReferenceFieldValues(), emptyList<Any>())
|
||||
}
|
||||
|
||||
fun `call on value over primitive class`() {
|
||||
assertEquals(BoxInt(1).collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals(BoxBoxInt(BoxInt(1)).collectReferenceFieldValues(), emptyList<Any>())
|
||||
}
|
||||
|
||||
fun `call on value class`() {
|
||||
val a1 = A(1)
|
||||
assertEquals(BoxA(a1).collectReferenceFieldValues(), listOf(a1))
|
||||
assertEquals(BoxBoxA(BoxA(a1)).collectReferenceFieldValues(), listOf(a1))
|
||||
}
|
||||
|
||||
fun `call on String`() {
|
||||
assertEquals("1234".collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals("".collectReferenceFieldValues(), emptyList<Any>())
|
||||
}
|
||||
|
||||
fun `call on primitive array`() {
|
||||
assertEquals(intArrayOf(1, 2, 3).collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals(intArrayOf().collectReferenceFieldValues(), emptyList<Any>())
|
||||
}
|
||||
|
||||
fun `call on array`() {
|
||||
assertEquals(arrayOf(1, 2, 3).collectReferenceFieldValues(), listOf<Any>(1, 2, 3))
|
||||
assertEquals(arrayOf(null, "10", null, 3).collectReferenceFieldValues(), listOf<Any>("10", 3))
|
||||
assertEquals(arrayOf<Any>().collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals(emptyArray<Any>().collectReferenceFieldValues(), emptyList<Any>())
|
||||
assertEquals(emptyArray<Any?>().collectReferenceFieldValues(), emptyList<Any>())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
`big class with mixed values`()
|
||||
`call on value over primitive class`()
|
||||
`call on primitive`()
|
||||
`call on array`()
|
||||
`call on String`()
|
||||
`call on value class`()
|
||||
`call on primitive array`()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user