From 09c131afd2a30b35f903bfc27cd28ef36789c680 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Thu, 28 Jul 2022 19:36:10 +0200 Subject: [PATCH] [Native][tests] Add standalone test for KClass package names To ensure that after introducing `ReflectionPackageName` annotation, we still have tests that check KClass package names without it. --- .../nativeWithoutPackagePatching.kt | 40 +++++++++++++++++++ .../NativeCodegenBoxTestGenerated.java | 6 +++ 2 files changed, 46 insertions(+) create mode 100644 compiler/testData/codegen/box/reflection/classLiterals/nativeWithoutPackagePatching.kt diff --git a/compiler/testData/codegen/box/reflection/classLiterals/nativeWithoutPackagePatching.kt b/compiler/testData/codegen/box/reflection/classLiterals/nativeWithoutPackagePatching.kt new file mode 100644 index 00000000000..100fa4a1bd0 --- /dev/null +++ b/compiler/testData/codegen/box/reflection/classLiterals/nativeWithoutPackagePatching.kt @@ -0,0 +1,40 @@ +// TARGET_BACKEND: NATIVE +// NATIVE_STANDALONE + +// Purpose of this test is to check that Kotlin/Native still generates correct +// package names in reflection information without package patching. +// +// Native test engine by default groups tests to single compilation, and +// renames packages to avoid clashes. +// To make reflection-related tests work, it inserts ReflectionPackageName +// annotations when patching, to instruct the compiler to use the original +// package name for reflection information. +// +// The NATIVE_STANDALONE directive above disables test grouping. +// So this test basically checks that without ReflectionPackageName the compiler +// can still properly handle reflection information for classes and generates +// correct package names. + +// FILE: pkg.kt +package pkg + +class A + +// FILE: pkg.sub.kt +package pkg.sub + +class B + +// FILE: defaut.kt +import pkg.* +import pkg.sub.* + +class C + +fun box(): String { + if (A::class.qualifiedName != "pkg.A") return "FAIL 1: ${A::class.qualifiedName}" + if (B::class.qualifiedName != "pkg.sub.B") return "FAIL 2: ${B::class.qualifiedName}" + if (C::class.qualifiedName != "C") return "FAIL 3: ${C::class.qualifiedName}" + + return "OK" +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 60f4cf41d55..8ef3c9f34de 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -34681,6 +34681,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/reflection/classLiterals/lambdaClass.kt"); } + @Test + @TestMetadata("nativeWithoutPackagePatching.kt") + public void testNativeWithoutPackagePatching() throws Exception { + runTest("compiler/testData/codegen/box/reflection/classLiterals/nativeWithoutPackagePatching.kt"); + } + @Test @TestMetadata("simpleClassLiteral.kt") public void testSimpleClassLiteral() throws Exception {