Remove LocalClassProtoTestGenerated, replace with kotlinp tests

This test uses a hacky mode of the compiler which is not worth it to
support further (especially in K2), `USE_SINGLE_MODULE`, where
everything is compiled in one module. The purpose of the test is just to
check that metadata for local/anonymous classes is written correctly.
So we can replace it with the tests on kotlinp, which uses
kotlinx-metadata-jvm and dumps all loaded metadata to text.

This replacement is not perfect, in particular because it won't check
that the reflection machinery is able to load this metadata, and because
it won't check that annotations are loaded correctly from the bytecode.
But IMHO it's good enough, there are box tests on reflection on local
classes (e.g. `reflection/annotations/localClassLiteral.kt`), so this
way is better than having to support the weird compiler mode for just
one test.
This commit is contained in:
Alexander Udalov
2022-08-26 13:30:56 +02:00
parent 7bf6d64cfb
commit abaffeddab
24 changed files with 178 additions and 263 deletions
@@ -59,11 +59,6 @@ public class KotlinpTestGenerated extends AbstractKotlinpTest {
runTest("libraries/tools/kotlinp/testData/Lambda.kt");
}
@TestMetadata("LocalClass.kt")
public void testLocalClass() throws Exception {
runTest("libraries/tools/kotlinp/testData/LocalClass.kt");
}
@TestMetadata("LocalDelegatedProperties.kt")
public void testLocalDelegatedProperties() throws Exception {
runTest("libraries/tools/kotlinp/testData/LocalDelegatedProperties.kt");
@@ -156,4 +151,37 @@ public class KotlinpTestGenerated extends AbstractKotlinpTest {
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 AbstractKotlinpTest {
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");
}
}
}
@@ -0,0 +1,3 @@
fun test() = object : Runnable {
override fun run() { }
}
@@ -0,0 +1,23 @@
// AnonymousObjectKt.class
// ------------------------------------------
package {
// signature: test()Ljava/lang/Runnable;
public final fun test(): java/lang/Runnable
}
// AnonymousObjectKt$test$1.class
// ------------------------------------------
local final class .AnonymousObjectKt$test$1 : java/lang/Runnable {
// signature: run()V
public open fun run(): kotlin/Unit
// module name: test-module
}
// META-INF/test-module.kotlin_module
// ------------------------------------------
module {
package <root> {
AnonymousObjectKt
}
}
@@ -0,0 +1,20 @@
fun test() {
class Local {
inner class Inner {
val prop = object {
fun foo() {
fun bar() {
class DeepLocal {
inner class Deepest {
fun local(): Local = Local()
fun inner(): Inner = Inner()
fun deep(): DeepLocal = DeepLocal()
fun deepest(): Deepest? = Deepest()
}
}
}
}
}
}
}
}
@@ -0,0 +1,80 @@
// DeepInnerLocalChainKt.class
// ------------------------------------------
package {
// signature: test()V
public final fun test(): kotlin/Unit
}
// DeepInnerLocalChainKt$test$Local.class
// ------------------------------------------
local final class .DeepInnerLocalChainKt$test$Local : kotlin/Any {
// signature: <init>()V
public constructor()
// nested class: Inner
// module name: test-module
}
// DeepInnerLocalChainKt$test$Local$Inner.class
// ------------------------------------------
local final inner class .DeepInnerLocalChainKt$test$Local.Inner : kotlin/Any {
// signature: <init>(LDeepInnerLocalChainKt$test$Local;)V
public constructor()
// field: prop:LDeepInnerLocalChainKt$test$Local$Inner$prop$1;
// getter: getProp()LDeepInnerLocalChainKt$test$Local$Inner$prop$1;
public final val prop: .DeepInnerLocalChainKt$test$Local$Inner$prop$1
public final get
// module name: test-module
}
// DeepInnerLocalChainKt$test$Local$Inner$prop$1.class
// ------------------------------------------
local final class .DeepInnerLocalChainKt$test$Local$Inner$prop$1 : kotlin/Any {
// signature: foo()V
public final fun foo(): kotlin/Unit
// module name: test-module
}
// DeepInnerLocalChainKt$test$Local$Inner$prop$1$foo$bar$DeepLocal.class
// ------------------------------------------
local final class .DeepInnerLocalChainKt$test$Local$Inner$prop$1$foo$bar$DeepLocal : kotlin/Any {
// signature: <init>(LDeepInnerLocalChainKt$test$Local;)V
public constructor()
// nested class: Deepest
// module name: test-module
}
// DeepInnerLocalChainKt$test$Local$Inner$prop$1$foo$bar$DeepLocal$Deepest.class
// ------------------------------------------
local final inner class .DeepInnerLocalChainKt$test$Local$Inner$prop$1$foo$bar$DeepLocal.Deepest : kotlin/Any {
// signature: <init>(LDeepInnerLocalChainKt$test$Local$Inner$prop$1$foo$bar$DeepLocal;)V
public constructor()
// signature: deep()LDeepInnerLocalChainKt$test$Local$Inner$prop$1$foo$bar$DeepLocal;
public final fun deep(): .DeepInnerLocalChainKt$test$Local$Inner$prop$1$foo$bar$DeepLocal
// signature: deepest()LDeepInnerLocalChainKt$test$Local$Inner$prop$1$foo$bar$DeepLocal$Deepest;
public final fun deepest(): .DeepInnerLocalChainKt$test$Local$Inner$prop$1$foo$bar$DeepLocal.Deepest?
// signature: inner()LDeepInnerLocalChainKt$test$Local$Inner;
public final fun inner(): .DeepInnerLocalChainKt$test$Local.Inner
// signature: local()LDeepInnerLocalChainKt$test$Local;
public final fun local(): .DeepInnerLocalChainKt$test$Local
// module name: test-module
}
// META-INF/test-module.kotlin_module
// ------------------------------------------
module {
package <root> {
DeepInnerLocalChainKt
}
}
@@ -0,0 +1,11 @@
fun test() {
open class Local {
fun param(l: Local) {}
val returnType: Local = this
fun Local.receiver() = this
fun <T : Local, U : T> generic(t: T): U = null!!
}
}
@@ -0,0 +1,37 @@
// LocalClassInSignatureKt.class
// ------------------------------------------
package {
// signature: test()V
public final fun test(): kotlin/Unit
}
// LocalClassInSignatureKt$test$Local.class
// ------------------------------------------
local open class .LocalClassInSignatureKt$test$Local : kotlin/Any {
// signature: <init>()V
public constructor()
// signature: generic(LLocalClassInSignatureKt$test$Local;)LLocalClassInSignatureKt$test$Local;
public final fun <T#0 /* T */ : .LocalClassInSignatureKt$test$Local, T#1 /* U */ : T#0> generic(t: T#0): T#1
// signature: param(LLocalClassInSignatureKt$test$Local;)V
public final fun param(l: .LocalClassInSignatureKt$test$Local): kotlin/Unit
// signature: receiver(LLocalClassInSignatureKt$test$Local;)LLocalClassInSignatureKt$test$Local;
public final fun .LocalClassInSignatureKt$test$Local.receiver(): .LocalClassInSignatureKt$test$Local
// field: returnType:LLocalClassInSignatureKt$test$Local;
// getter: getReturnType()LLocalClassInSignatureKt$test$Local;
public final val returnType: .LocalClassInSignatureKt$test$Local
public final get
// module name: test-module
}
// META-INF/test-module.kotlin_module
// ------------------------------------------
module {
package <root> {
LocalClassInSignatureKt
}
}