[K/N][tests] Move some more native tests to new testing infra

^KT-61259
This commit is contained in:
Vladimir Sukharev
2024-01-03 22:35:22 +01:00
committed by Space Team
parent 4080776fe3
commit 0a0da76a56
43 changed files with 7475 additions and 7233 deletions
@@ -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()
}