[Tests] Add .knm stub consistency test
The test compares stub trees built from .knm files directly and from the decompiled text. Test data for .class decompiler is reused, JVM-specific cases are ignored KT-61354
This commit is contained in:
committed by
Space Team
parent
2537ff94b7
commit
cf98fb5612
+3
@@ -1,3 +1,6 @@
|
||||
// KNM_K2_IGNORE
|
||||
// KNM_FE10_IGNORE
|
||||
|
||||
package test
|
||||
|
||||
public class AnnotatedFlexibleTypes(val javaClass: d.JavaClass) {
|
||||
|
||||
Vendored
+4
@@ -1,3 +1,7 @@
|
||||
// Issue: KTIJ-26788 (need stdlib for lazy)
|
||||
// KNM_K2_IGNORE
|
||||
// KNM_FE10_IGNORE
|
||||
|
||||
@a public class Annotations private @a constructor(private @property:a @param:a val c1: Int, @property:a @param:a val c2: Int) {
|
||||
@a() val hasValueArguments = 42
|
||||
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// Issue: KTIJ-26761
|
||||
// KNM_K2_IGNORE
|
||||
public class AnnotationsOnNullableTypes {
|
||||
fun B<@A C?>.receiverArgument() {}
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// FIR_IDENTICAL
|
||||
// JVM_FILE_NAME: ContextReceiversOnFunctionTypeKt
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
|
||||
// KNM_K2_IGNORE
|
||||
fun f(g: context(A, B) Int.(Int) -> Int) {}
|
||||
|
||||
class A {
|
||||
|
||||
Vendored
+3
@@ -1,4 +1,7 @@
|
||||
// FIR_IDENTICAL
|
||||
// KNM_K2_IGNORE
|
||||
// KNM_FE10_IGNORE
|
||||
|
||||
package test
|
||||
|
||||
class LocalClass {
|
||||
|
||||
Vendored
+4
@@ -1,3 +1,7 @@
|
||||
// Issue: KTIJ-26788 (need stdlib for Continuation)
|
||||
// KNM_K2_IGNORE
|
||||
// KNM_FE10_IGNORE
|
||||
|
||||
package test
|
||||
import kotlin.coroutines.*
|
||||
|
||||
|
||||
+3
@@ -1,3 +1,6 @@
|
||||
// Issue: KTIJ-26761
|
||||
// KNM_K2_IGNORE
|
||||
|
||||
package foo.TopLevelMembers
|
||||
|
||||
fun funWithBlockBody() {
|
||||
|
||||
+7
-3
@@ -144,9 +144,7 @@ internal data class TestData(
|
||||
companion object {
|
||||
fun createFromDirectory(directory: Path): TestData {
|
||||
val allFiles = Files.list(directory).collect(Collectors.toList())
|
||||
val mainKotlinFile = allFiles.single { path: Path ->
|
||||
path.name.replaceFirstChar { Character.toUpperCase(it) } == "${directory.name.removeSuffix("Kt")}.kt"
|
||||
}
|
||||
val mainKotlinFile = findMainTestKotlinFile(directory)
|
||||
val fileText = mainKotlinFile.readText()
|
||||
val jvmFileName = InTextDirectivesUtils.findStringWithPrefixes(fileText, "JVM_FILE_NAME:") ?: directory.name
|
||||
val additionalCompilerOptions = InTextDirectivesUtils.findListWithPrefixes(fileText, "// !LANGUAGE: ").map { "-XXLanguage:$it" }
|
||||
@@ -179,3 +177,9 @@ internal data class TestData(
|
||||
}
|
||||
}
|
||||
|
||||
fun findMainTestKotlinFile(directory: Path): Path {
|
||||
val allFiles = Files.list(directory).collect(Collectors.toList())
|
||||
return allFiles.singleOrNull { path: Path ->
|
||||
path.name.replaceFirstChar { Character.toUpperCase(it) } == "${directory.name.removeSuffix("Kt")}.kt"
|
||||
} ?: error("Test directory should contain a single primary kt source file")
|
||||
}
|
||||
|
||||
+3
-1
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.impl.DebugUtil
|
||||
import com.intellij.psi.stubs.PsiFileStub
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.STUB_TO_STRING_PREFIX
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
@@ -40,7 +41,8 @@ abstract class AbstractStubBuilderTest : AbstractDecompiledClassTest() {
|
||||
protected abstract fun getStubToTest(classFile: VirtualFile): PsiFileStub<*>
|
||||
}
|
||||
|
||||
private fun StubElement<out PsiElement>.serializeToString(): String {
|
||||
@TestOnly
|
||||
fun StubElement<out PsiElement>.serializeToString(): String {
|
||||
return serializeStubToString(this)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user