[Tests] Add tests for additional stub info in .knm files
KTIJ-28668
This commit is contained in:
committed by
Space Team
parent
604dec7a87
commit
1c1bdae973
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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.analysis.decompiler.konan
|
||||||
|
|
||||||
|
import com.intellij.util.indexing.FileContentImpl
|
||||||
|
import org.jetbrains.kotlin.analysis.decompiler.stub.files.extractAdditionalStubInfo
|
||||||
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
|
import org.jetbrains.kotlin.test.directives.model.Directive
|
||||||
|
import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability
|
||||||
|
import org.jetbrains.kotlin.test.directives.model.SimpleDirectivesContainer
|
||||||
|
import java.nio.file.Path
|
||||||
|
import kotlin.io.path.name
|
||||||
|
|
||||||
|
abstract class AbstractAdditionalStubInfoKnmTest : AbstractDecompiledKnmFileTest() {
|
||||||
|
private object Directives : SimpleDirectivesContainer() {
|
||||||
|
val KNM_K2_IGNORE by directive(
|
||||||
|
description = "Ignore test for KNM files with K2 K/N Decompiler",
|
||||||
|
applicability = DirectiveApplicability.Global,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val ignoreDirective: Directive
|
||||||
|
get() = Directives.KNM_K2_IGNORE
|
||||||
|
|
||||||
|
override fun doTest(testDirectoryPath: Path) {
|
||||||
|
val stubBuilder = K2KotlinNativeMetadataDecompiler().stubBuilder
|
||||||
|
val knmFiles = compileToKnmFiles(testDirectoryPath)
|
||||||
|
val knmFile = knmFiles.singleOrNull { "root_package" !in it.path }
|
||||||
|
?: error("Expected a single non-root .knm file, but received:${System.lineSeparator()}" +
|
||||||
|
knmFiles.joinToString(separator = System.lineSeparator()) { it.path }
|
||||||
|
)
|
||||||
|
|
||||||
|
val stub = stubBuilder.buildFileStub(FileContentImpl.createByFile(knmFile, environment.project))!!
|
||||||
|
KotlinTestUtils.assertEqualsToFile(
|
||||||
|
testDirectoryPath.resolve("${testDirectoryPath.name}.txt"),
|
||||||
|
extractAdditionalStubInfo(stub)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -29,6 +29,14 @@ abstract class AbstractDecompiledKnmFileTest : KotlinTestWithEnvironment() {
|
|||||||
|
|
||||||
protected abstract fun doTest(testDirectoryPath: Path)
|
protected abstract fun doTest(testDirectoryPath: Path)
|
||||||
|
|
||||||
|
override fun setUp() {
|
||||||
|
super.setUp()
|
||||||
|
|
||||||
|
environment.projectEnvironment.environment.registerFileType(
|
||||||
|
KlibMetaFileType, KlibMetaFileType.defaultExtension
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override fun createEnvironment(): KotlinCoreEnvironment {
|
override fun createEnvironment(): KotlinCoreEnvironment {
|
||||||
return KotlinCoreEnvironment.createForTests(
|
return KotlinCoreEnvironment.createForTests(
|
||||||
ApplicationEnvironmentDisposer.ROOT_DISPOSABLE,
|
ApplicationEnvironmentDisposer.ROOT_DISPOSABLE,
|
||||||
|
|||||||
-8
@@ -67,14 +67,6 @@ abstract class AbstractDecompiledKnmStubConsistencyK2Test : AbstractDecompiledKn
|
|||||||
abstract class AbstractDecompiledKnmStubConsistencyTest : AbstractDecompiledKnmFileTest() {
|
abstract class AbstractDecompiledKnmStubConsistencyTest : AbstractDecompiledKnmFileTest() {
|
||||||
abstract fun createDecompiler(): KlibMetadataDecompiler<*>
|
abstract fun createDecompiler(): KlibMetadataDecompiler<*>
|
||||||
|
|
||||||
override fun setUp() {
|
|
||||||
super.setUp()
|
|
||||||
|
|
||||||
environment.projectEnvironment.environment.registerFileType(
|
|
||||||
KlibMetaFileType, KlibMetaFileType.defaultExtension
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun doTest(testDirectoryPath: Path) {
|
override fun doTest(testDirectoryPath: Path) {
|
||||||
val files = compileToKnmFiles(testDirectoryPath)
|
val files = compileToKnmFiles(testDirectoryPath)
|
||||||
|
|
||||||
|
|||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* 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.analysis.decompiler.konan;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.TestDataPath;
|
||||||
|
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||||
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.analysis.api.GenerateAnalysisApiTestsKt}. DO NOT MODIFY MANUALLY */
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("analysis/decompiled/decompiler-to-file-stubs/testData/additionalClsStubInfo")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
public class AdditionalStubInfoKnmTestGenerated extends AbstractAdditionalStubInfoKnmTest {
|
||||||
|
@Test
|
||||||
|
public void testAllFilesPresentInAdditionalClsStubInfo() throws Exception {
|
||||||
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/decompiled/decompiler-to-file-stubs/testData/additionalClsStubInfo"), Pattern.compile("^([^\\.]+)$"), null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("AnnotatedFlexibleTypes")
|
||||||
|
public void testAnnotatedFlexibleTypes() throws Exception {
|
||||||
|
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/additionalClsStubInfo/AnnotatedFlexibleTypes/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("AnnotationValues")
|
||||||
|
public void testAnnotationValues() throws Exception {
|
||||||
|
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/additionalClsStubInfo/AnnotationValues/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("Contracts")
|
||||||
|
public void testContracts() throws Exception {
|
||||||
|
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/additionalClsStubInfo/Contracts/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("OuterClassesWithFlexibleArgs")
|
||||||
|
public void testOuterClassesWithFlexibleArgs() throws Exception {
|
||||||
|
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/additionalClsStubInfo/OuterClassesWithFlexibleArgs/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("ParameterName")
|
||||||
|
public void testParameterName() throws Exception {
|
||||||
|
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/additionalClsStubInfo/ParameterName/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("PropertyInitializer")
|
||||||
|
public void testPropertyInitializer() throws Exception {
|
||||||
|
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/additionalClsStubInfo/PropertyInitializer/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("TypeParametersInFlexibleTypes")
|
||||||
|
public void testTypeParametersInFlexibleTypes() throws Exception {
|
||||||
|
runTest("analysis/decompiled/decompiler-to-file-stubs/testData/additionalClsStubInfo/TypeParametersInFlexibleTypes/");
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -1,3 +1,6 @@
|
|||||||
|
/* Java interop */
|
||||||
|
// KNM_K2_IGNORE
|
||||||
|
|
||||||
package test
|
package test
|
||||||
|
|
||||||
public class AnnotatedFlexibleTypes(val javaClass: d.JavaClass) {
|
public class AnnotatedFlexibleTypes(val javaClass: d.JavaClass) {
|
||||||
|
|||||||
+4
@@ -1,3 +1,7 @@
|
|||||||
|
/* K2 is skipped because of the test data: multiple KNM parts are produced */
|
||||||
|
// KNM_K2_IGNORE
|
||||||
|
|
||||||
|
|
||||||
package test
|
package test
|
||||||
|
|
||||||
import test.E.E1
|
import test.E.E1
|
||||||
|
|||||||
Vendored
+2
@@ -1,3 +1,5 @@
|
|||||||
|
/* KTIJ-28668 */
|
||||||
|
// KNM_K2_IGNORE
|
||||||
// JVM_FILE_NAME: ContractsKt
|
// JVM_FILE_NAME: ContractsKt
|
||||||
|
|
||||||
@file:OptIn(ExperimentalContracts::class)
|
@file:OptIn(ExperimentalContracts::class)
|
||||||
|
|||||||
+3
@@ -1,3 +1,6 @@
|
|||||||
|
/* Java interop */
|
||||||
|
// KNM_K2_IGNORE
|
||||||
|
|
||||||
package test
|
package test
|
||||||
|
|
||||||
public class OuterClassesWithFlexibleArgs<K, L>(k: K, l: L) {
|
public class OuterClassesWithFlexibleArgs<K, L>(k: K, l: L) {
|
||||||
|
|||||||
+2
@@ -1,3 +1,5 @@
|
|||||||
|
// KNM_K2_IGNORE
|
||||||
|
|
||||||
package test
|
package test
|
||||||
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|||||||
+3
@@ -1,3 +1,6 @@
|
|||||||
|
/* Java interop */
|
||||||
|
// KNM_K2_IGNORE
|
||||||
|
|
||||||
package test
|
package test
|
||||||
|
|
||||||
public class TypeParametersInFlexibleTypes<A, D>(val javaClass: d.JavaClass<A>, val t: D & Any) {
|
public class TypeParametersInFlexibleTypes<A, D>(val javaClass: d.JavaClass<A>, val t: D & Any) {
|
||||||
|
|||||||
+10
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.generators.tests.analysis.api
|
package org.jetbrains.kotlin.generators.tests.analysis.api
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.analysis.decompiler.konan.AbstractAdditionalStubInfoKnmTest
|
||||||
import org.jetbrains.kotlin.analysis.decompiler.konan.AbstractDecompiledKnmStubConsistencyFe10Test
|
import org.jetbrains.kotlin.analysis.decompiler.konan.AbstractDecompiledKnmStubConsistencyFe10Test
|
||||||
import org.jetbrains.kotlin.analysis.decompiler.konan.AbstractDecompiledKnmStubConsistencyK2Test
|
import org.jetbrains.kotlin.analysis.decompiler.konan.AbstractDecompiledKnmStubConsistencyK2Test
|
||||||
import org.jetbrains.kotlin.analysis.decompiler.psi.AbstractByDecompiledPsiStubBuilderK2CompilerTest
|
import org.jetbrains.kotlin.analysis.decompiler.psi.AbstractByDecompiledPsiStubBuilderK2CompilerTest
|
||||||
@@ -66,4 +67,13 @@ internal fun TestGroupSuite.generateDecompiledTests() {
|
|||||||
model("clsFileStubBuilder", extension = null, recursive = false)
|
model("clsFileStubBuilder", extension = null, recursive = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testGroup(
|
||||||
|
"analysis/decompiled/decompiler-native/tests",
|
||||||
|
"analysis/decompiled/decompiler-to-file-stubs/testData",
|
||||||
|
) {
|
||||||
|
testClass<AbstractAdditionalStubInfoKnmTest> {
|
||||||
|
model("additionalClsStubInfo", extension = null, recursive = false)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user