[Tests] Add JavaAgainstKotlin tests for K2

^KT-64405 Fixed
This commit is contained in:
Iaroslav Postovalov
2024-01-07 13:34:22 +01:00
committed by Space Team
parent 34877130c7
commit 29c68c8aa7
8 changed files with 2853 additions and 5 deletions
@@ -1,3 +1,5 @@
// !IGNORE_FIR
// KT-64909
// !LANGUAGE: +InlineClasses
package test
@@ -10,4 +12,4 @@ interface IFoo<T> {
open class KFooZ : IFoo<Z> {
override fun foo(): Z = Z(42)
}
}
@@ -58,7 +58,7 @@ abstract class AbstractCompileJavaAgainstKotlinTest : TestCaseWithTmpdir() {
}
@Throws(IOException::class)
protected fun doTest(ktFilePath: String, useJavac: Boolean) {
protected open fun doTest(ktFilePath: String, useJavac: Boolean) {
Assert.assertTrue(ktFilePath.endsWith(".kt"))
val ktFile = File(ktFilePath)
val javaFile = File(ktFilePath.replaceFirst("\\.kt$".toRegex(), ".java"))
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2024 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.
*/
package org.jetbrains.kotlin.jvm.compiler
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
abstract class AbstractFirCompileJavaAgainstKotlinTest(private val useLightTree: Boolean) : AbstractCompileJavaAgainstKotlinTest() {
override fun doTest(ktFilePath: String, useJavac: Boolean) {
val ktFile = File(ktFilePath)
val directives = KotlinTestUtils.parseDirectives(ktFile.readText())
if (directives.contains("IGNORE_FIR")) return
super.doTest(ktFilePath, useJavac)
}
override fun updateConfiguration(configuration: CompilerConfiguration) {
configuration.put(JVMConfigurationKeys.IR, true)
configuration.put(CommonConfigurationKeys.USE_FIR, true)
if (useLightTree) configuration.put(CommonConfigurationKeys.USE_LIGHT_TREE, true)
}
}
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2024 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.
*/
package org.jetbrains.kotlin.jvm.compiler.ir
import org.jetbrains.kotlin.jvm.compiler.AbstractFirCompileJavaAgainstKotlinTest
abstract class AbstractFirLightTreeCompileJavaAgainstKotlinTest : AbstractFirCompileJavaAgainstKotlinTest(true)
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2024 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.
*/
package org.jetbrains.kotlin.jvm.compiler.ir
import org.jetbrains.kotlin.jvm.compiler.AbstractFirCompileJavaAgainstKotlinTest
abstract class AbstractFirPsiCompileJavaAgainstKotlinTest : AbstractFirCompileJavaAgainstKotlinTest(false)
@@ -28,9 +28,7 @@ import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_OR_KTS_WITHOUT_
import org.jetbrains.kotlin.integration.AbstractAntTaskTest
import org.jetbrains.kotlin.ir.AbstractIrCfgTestCase
import org.jetbrains.kotlin.jvm.compiler.*
import org.jetbrains.kotlin.jvm.compiler.ir.AbstractIrCompileJavaAgainstKotlinTest
import org.jetbrains.kotlin.jvm.compiler.ir.AbstractIrCompileKotlinAgainstJavaTest
import org.jetbrains.kotlin.jvm.compiler.ir.AbstractIrLoadJavaTest
import org.jetbrains.kotlin.jvm.compiler.ir.*
import org.jetbrains.kotlin.jvm.compiler.javac.AbstractLoadJavaUsingJavacTest
import org.jetbrains.kotlin.klib.AbstractKlibIrTextTestCase
import org.jetbrains.kotlin.klib.AbstractKlibJsIrTextTestCase
@@ -208,6 +206,8 @@ fun generateJUnit3CompilerTests(args: Array<String>, mainClassName: String?) {
)
}
testClass<AbstractCompileKotlinAgainstJavaTest> {
model(
"compileKotlinAgainstJava",
@@ -309,6 +309,37 @@ fun generateJUnit3CompilerTests(args: Array<String>, mainClassName: String?) {
)
}
testClass<AbstractFirLightTreeCompileJavaAgainstKotlinTest> {
model(
"compileJavaAgainstKotlin",
testClassName = "WithoutJavac",
testMethod = "doTestWithoutJavac",
targetBackend = TargetBackend.JVM_IR
)
model(
"compileJavaAgainstKotlin",
testClassName = "WithJavac",
testMethod = "doTestWithJavac",
targetBackend = TargetBackend.JVM_IR
)
}
testClass<AbstractFirPsiCompileJavaAgainstKotlinTest> {
model(
"compileJavaAgainstKotlin",
testClassName = "WithoutJavac",
testMethod = "doTestWithoutJavac",
targetBackend = TargetBackend.JVM_IR
)
model(
"compileJavaAgainstKotlin",
testClassName = "WithJavac",
testMethod = "doTestWithJavac",
targetBackend = TargetBackend.JVM_IR
)
}
testClass<AbstractIrCompileKotlinAgainstJavaTest> {
model(
"compileKotlinAgainstJava",