[K2] Add support for running Kotlinp tests with K2.

The tests fail spectacularly at this point in time.
This commit is contained in:
Mads Ager
2023-03-06 16:14:44 +01:00
committed by Space Cloud
parent f2ecb097f1
commit 04a088039c
10 changed files with 290 additions and 10 deletions
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2023 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.kotlinp.test
abstract class AbstractK1KotlinpTest : AbstractKotlinpTest() {
override fun useK2() = false
}
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2023 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.kotlinp.test
abstract class AbstractK2KotlinpTest: AbstractKotlinpTest() {
override fun useK2() = true
}
@@ -9,7 +9,16 @@ import org.jetbrains.kotlin.test.TestCaseWithTmpdir
import java.io.File
abstract class AbstractKotlinpTest : TestCaseWithTmpdir() {
abstract fun useK2(): Boolean
protected fun doTest(fileName: String) {
compileAndPrintAllFiles(File(fileName), testRootDisposable, tmpdir, compareWithTxt = true, readWriteAndCompare = true)
compileAndPrintAllFiles(
File(fileName),
testRootDisposable,
tmpdir,
compareWithTxt = true,
readWriteAndCompare = true,
useK2 = useK2()
)
}
}
@@ -12,7 +12,10 @@ fun main(args: Array<String>) {
generateTestGroupSuite(args) {
testGroup("libraries/tools/kotlinp/test", "libraries/tools/kotlinp/testData") {
testClass<AbstractKotlinpTest> {
testClass<AbstractK1KotlinpTest> {
model("")
}
testClass<AbstractK2KotlinpTest> {
model("")
}
}
@@ -20,7 +20,7 @@ import java.util.regex.Pattern;
@TestMetadata("libraries/tools/kotlinp/testData")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class KotlinpTestGenerated extends AbstractKotlinpTest {
public class K1KotlinpTestGenerated extends AbstractK1KotlinpTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@@ -44,6 +44,11 @@ public class KotlinpTestGenerated extends AbstractKotlinpTest {
runTest("libraries/tools/kotlinp/testData/Contracts.kt");
}
@TestMetadata("Delegation.kt")
public void testDelegation() throws Exception {
runTest("libraries/tools/kotlinp/testData/Delegation.kt");
}
@TestMetadata("EnumEntries.kt")
public void testEnumEntries() throws Exception {
runTest("libraries/tools/kotlinp/testData/EnumEntries.kt");
@@ -132,7 +137,7 @@ public class KotlinpTestGenerated extends AbstractKotlinpTest {
@TestMetadata("libraries/tools/kotlinp/testData/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmDefault extends AbstractKotlinpTest {
public static class JvmDefault extends AbstractK1KotlinpTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@@ -165,7 +170,7 @@ public class KotlinpTestGenerated extends AbstractKotlinpTest {
@TestMetadata("libraries/tools/kotlinp/testData/localClasses")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class LocalClasses extends AbstractKotlinpTest {
public static class LocalClasses extends AbstractK1KotlinpTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@@ -0,0 +1,202 @@
/*
* Copyright 2010-2023 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.kotlinp.test;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.kotlinp.test.GenerateKotlinpTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("libraries/tools/kotlinp/testData")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class K2KotlinpTestGenerated extends AbstractK2KotlinpTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInTestData() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("libraries/tools/kotlinp/testData"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("Annotations.kt")
public void testAnnotations() throws Exception {
runTest("libraries/tools/kotlinp/testData/Annotations.kt");
}
@TestMetadata("ContextReceivers.kt")
public void testContextReceivers() throws Exception {
runTest("libraries/tools/kotlinp/testData/ContextReceivers.kt");
}
@TestMetadata("Contracts.kt")
public void testContracts() throws Exception {
runTest("libraries/tools/kotlinp/testData/Contracts.kt");
}
@TestMetadata("Delegation.kt")
public void testDelegation() throws Exception {
runTest("libraries/tools/kotlinp/testData/Delegation.kt");
}
@TestMetadata("EnumEntries.kt")
public void testEnumEntries() throws Exception {
runTest("libraries/tools/kotlinp/testData/EnumEntries.kt");
}
@TestMetadata("FunInterface.kt")
public void testFunInterface() throws Exception {
runTest("libraries/tools/kotlinp/testData/FunInterface.kt");
}
@TestMetadata("IntersectionTypeInLambdaLiteralAndDelegatedProperty.kt")
public void testIntersectionTypeInLambdaLiteralAndDelegatedProperty() throws Exception {
runTest("libraries/tools/kotlinp/testData/IntersectionTypeInLambdaLiteralAndDelegatedProperty.kt");
}
@TestMetadata("Lambda.kt")
public void testLambda() throws Exception {
runTest("libraries/tools/kotlinp/testData/Lambda.kt");
}
@TestMetadata("LocalDelegatedProperties.kt")
public void testLocalDelegatedProperties() throws Exception {
runTest("libraries/tools/kotlinp/testData/LocalDelegatedProperties.kt");
}
@TestMetadata("MultiFileClass.kt")
public void testMultiFileClass() throws Exception {
runTest("libraries/tools/kotlinp/testData/MultiFileClass.kt");
}
@TestMetadata("NestedClasses.kt")
public void testNestedClasses() throws Exception {
runTest("libraries/tools/kotlinp/testData/NestedClasses.kt");
}
@TestMetadata("NotEnumWithEnumEntriesEnabled.kt")
public void testNotEnumWithEnumEntriesEnabled() throws Exception {
runTest("libraries/tools/kotlinp/testData/NotEnumWithEnumEntriesEnabled.kt");
}
@TestMetadata("OptionalAnnotation.kt")
public void testOptionalAnnotation() throws Exception {
runTest("libraries/tools/kotlinp/testData/OptionalAnnotation.kt");
}
@TestMetadata("PlatformType.kt")
public void testPlatformType() throws Exception {
runTest("libraries/tools/kotlinp/testData/PlatformType.kt");
}
@TestMetadata("Properties.kt")
public void testProperties() throws Exception {
runTest("libraries/tools/kotlinp/testData/Properties.kt");
}
@TestMetadata("SimpleClass.kt")
public void testSimpleClass() throws Exception {
runTest("libraries/tools/kotlinp/testData/SimpleClass.kt");
}
@TestMetadata("SimplePackage.kt")
public void testSimplePackage() throws Exception {
runTest("libraries/tools/kotlinp/testData/SimplePackage.kt");
}
@TestMetadata("SyntheticClass.kt")
public void testSyntheticClass() throws Exception {
runTest("libraries/tools/kotlinp/testData/SyntheticClass.kt");
}
@TestMetadata("TypeParameters.kt")
public void testTypeParameters() throws Exception {
runTest("libraries/tools/kotlinp/testData/TypeParameters.kt");
}
@TestMetadata("ValueClass.kt")
public void testValueClass() throws Exception {
runTest("libraries/tools/kotlinp/testData/ValueClass.kt");
}
@TestMetadata("VersionRequirement.kt")
public void testVersionRequirement() throws Exception {
runTest("libraries/tools/kotlinp/testData/VersionRequirement.kt");
}
@TestMetadata("libraries/tools/kotlinp/testData/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmDefault extends AbstractK2KotlinpTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("All.kt")
public void testAll() throws Exception {
runTest("libraries/tools/kotlinp/testData/jvmDefault/All.kt");
}
@TestMetadata("AllCompatibility.kt")
public void testAllCompatibility() throws Exception {
runTest("libraries/tools/kotlinp/testData/jvmDefault/AllCompatibility.kt");
}
public void testAllFilesPresentInJvmDefault() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("libraries/tools/kotlinp/testData/jvmDefault"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("withCompatibility.kt")
public void testWithCompatibility() throws Exception {
runTest("libraries/tools/kotlinp/testData/jvmDefault/withCompatibility.kt");
}
@TestMetadata("withoutCompatibility.kt")
public void testWithoutCompatibility() throws Exception {
runTest("libraries/tools/kotlinp/testData/jvmDefault/withoutCompatibility.kt");
}
}
@TestMetadata("libraries/tools/kotlinp/testData/localClasses")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class LocalClasses extends AbstractK2KotlinpTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInLocalClasses() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("libraries/tools/kotlinp/testData/localClasses"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("AnonymousObject.kt")
public void testAnonymousObject() throws Exception {
runTest("libraries/tools/kotlinp/testData/localClasses/AnonymousObject.kt");
}
@TestMetadata("DeepInnerLocalChain.kt")
public void testDeepInnerLocalChain() throws Exception {
runTest("libraries/tools/kotlinp/testData/localClasses/DeepInnerLocalChain.kt");
}
@TestMetadata("LocalClassInConstructor.kt")
public void testLocalClassInConstructor() throws Exception {
runTest("libraries/tools/kotlinp/testData/localClasses/LocalClassInConstructor.kt");
}
@TestMetadata("LocalClassInSignature.kt")
public void testLocalClassInSignature() throws Exception {
runTest("libraries/tools/kotlinp/testData/localClasses/LocalClassInSignature.kt");
}
}
}
@@ -25,7 +25,7 @@ class KotlinpCompilerTestDataTest(private val file: File) {
val disposable = TestDisposable()
try {
compileAndPrintAllFiles(file, disposable, tmpdir, compareWithTxt = false, readWriteAndCompare = true)
compileAndPrintAllFiles(file, disposable, tmpdir, compareWithTxt = false, readWriteAndCompare = true, useK2 = false)
} finally {
Disposer.dispose(disposable)
}
@@ -14,10 +14,11 @@ import org.jetbrains.kotlin.checkers.setupLanguageVersionSettingsForCompilerTest
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.codegen.GenerationUtils
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.jvm.compiler.AbstractLoadJavaTest
import org.jetbrains.kotlin.kotlinp.Kotlinp
import org.jetbrains.kotlin.kotlinp.KotlinpSettings
import org.jetbrains.kotlin.load.java.JavaTypeEnhancementState
import org.jetbrains.kotlin.test.ConfigurationKind
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.KotlinTestUtils
@@ -26,7 +27,14 @@ import org.jetbrains.kotlin.test.util.KtTestUtil
import java.io.File
import kotlin.test.fail
fun compileAndPrintAllFiles(file: File, disposable: Disposable, tmpdir: File, compareWithTxt: Boolean, readWriteAndCompare: Boolean) {
fun compileAndPrintAllFiles(
file: File,
disposable: Disposable,
tmpdir: File,
compareWithTxt: Boolean,
readWriteAndCompare: Boolean,
useK2: Boolean
) {
val main = StringBuilder()
val afterVisitors = StringBuilder()
val afterNodes = StringBuilder()
@@ -34,7 +42,7 @@ fun compileAndPrintAllFiles(file: File, disposable: Disposable, tmpdir: File, co
val kotlinp = Kotlinp(KotlinpSettings(isVerbose = true))
@OptIn(UnstableMetadataApi::class)
compile(file, disposable, tmpdir) { outputFile ->
compile(file, disposable, tmpdir, useK2) { outputFile ->
when (outputFile.extension) {
"kotlin_module" -> {
val moduleFile = kotlinp.readModuleFile(outputFile)!!
@@ -74,10 +82,11 @@ fun compileAndPrintAllFiles(file: File, disposable: Disposable, tmpdir: File, co
}
}
private fun compile(file: File, disposable: Disposable, tmpdir: File, forEachOutputFile: (File) -> Unit) {
private fun compile(file: File, disposable: Disposable, tmpdir: File, useK2: Boolean, forEachOutputFile: (File) -> Unit) {
val content = file.readText()
val configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK)
configuration.put(JVMConfigurationKeys.IR, true)
configuration.put(CommonConfigurationKeys.USE_FIR, useK2)
AbstractLoadJavaTest.updateConfigurationWithDirectives(content, configuration)
val environment = KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
setupLanguageVersionSettingsForCompilerTests(content, environment)
+7
View File
@@ -0,0 +1,7 @@
interface I {
fun foo()
}
class A(i: I): I by i {
}
+25
View File
@@ -0,0 +1,25 @@
// A.class
// ------------------------------------------
public final class A : I {
// signature: <init>(LI;)V
public constructor(i: I)
// signature: foo()V
public open /* delegation */ fun foo(): kotlin/Unit
// module name: test-module
}
// I.class
// ------------------------------------------
public abstract interface I : kotlin/Any {
// signature: foo()V
public abstract fun foo(): kotlin/Unit
// module name: test-module
}
// META-INF/test-module.kotlin_module
// ------------------------------------------
module {
}