[Parcelize] Add test for parcelize in multiplatform setting.
This tests that classes in common code can have code generated for them in android compilations.
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_STDLIB
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.*
|
||||
|
||||
annotation class TriggerParcelize
|
||||
|
||||
@TriggerParcelize
|
||||
data class User(val name: String) : Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val user = User("John")
|
||||
user.writeToParcel(parcel, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
parcel.setDataPosition(0)
|
||||
|
||||
val user2 = parcelableCreator<User>().createFromParcel(parcel)
|
||||
assert(user == user2)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// WITH_STDLIB
|
||||
|
||||
// Metadata compilations do not see through the expect/actuals and therefore,
|
||||
// there are parcelize errors in metadata compilations.
|
||||
// IGNORE_FIR_DIAGNOSTICS_DIFF
|
||||
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
package test
|
||||
|
||||
expect interface MyParcelable
|
||||
|
||||
annotation class TriggerParcelize
|
||||
|
||||
@TriggerParcelize
|
||||
data class User(val name: String) : MyParcelable
|
||||
|
||||
// MODULE: m2-jvm()()(m1-common)
|
||||
// FILE: android.kt
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import kotlinx.parcelize.*
|
||||
|
||||
actual typealias MyParcelable = android.os.Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val user = User("John")
|
||||
user.writeToParcel(parcel, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
parcel.setDataPosition(0)
|
||||
|
||||
val user2 = parcelableCreator<User>().createFromParcel(parcel)
|
||||
assert(user == user2)
|
||||
}
|
||||
+12
@@ -19,6 +19,12 @@ import java.util.regex.Pattern;
|
||||
@TestMetadata("plugins/parcelize/parcelize-compiler/testData/box")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class ParcelizeFirLightTreeBoxTestGenerated extends AbstractParcelizeFirLightTreeBoxTest {
|
||||
@Test
|
||||
@TestMetadata("additionalAnnotationTrigger.kt")
|
||||
public void testAdditionalAnnotationTrigger() {
|
||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/additionalAnnotationTrigger.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInBox() {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/parcelize/parcelize-compiler/testData/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
@@ -324,6 +330,12 @@ public class ParcelizeFirLightTreeBoxTestGenerated extends AbstractParcelizeFirL
|
||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/maps.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("mppWithExpectParcelable.kt")
|
||||
public void testMppWithExpectParcelable() {
|
||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/mppWithExpectParcelable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nestedArrays.kt")
|
||||
public void testNestedArrays() {
|
||||
|
||||
+12
@@ -19,6 +19,12 @@ import java.util.regex.Pattern;
|
||||
@TestMetadata("plugins/parcelize/parcelize-compiler/testData/box")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class ParcelizeIrBoxTestGenerated extends AbstractParcelizeIrBoxTest {
|
||||
@Test
|
||||
@TestMetadata("additionalAnnotationTrigger.kt")
|
||||
public void testAdditionalAnnotationTrigger() {
|
||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/additionalAnnotationTrigger.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInBox() {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/parcelize/parcelize-compiler/testData/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
@@ -324,6 +330,12 @@ public class ParcelizeIrBoxTestGenerated extends AbstractParcelizeIrBoxTest {
|
||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/maps.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("mppWithExpectParcelable.kt")
|
||||
public void testMppWithExpectParcelable() {
|
||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/mppWithExpectParcelable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nestedArrays.kt")
|
||||
public void testNestedArrays() {
|
||||
|
||||
+2
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact
|
||||
import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticsHandler
|
||||
import org.jetbrains.kotlin.test.frontend.fir.Fir2IrJvmResultsConverter
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirMetaInfoDiffSuppressor
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact
|
||||
import org.jetbrains.kotlin.test.frontend.fir.handlers.FirDiagnosticsHandler
|
||||
import org.jetbrains.kotlin.test.model.*
|
||||
@@ -122,6 +123,7 @@ abstract class AbstractParcelizeFirBoxTestBase(val parser: FirParser) : Abstract
|
||||
+ENABLE_PLUGIN_PHASES
|
||||
FirDiagnosticsDirectives.FIR_PARSER with parser
|
||||
}
|
||||
useAfterAnalysisCheckers(::FirMetaInfoDiffSuppressor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -42,13 +42,17 @@ class ParcelizeEnvironmentConfigurator(testServices: TestServices) : Environment
|
||||
kotlinxCollectionsImmutable
|
||||
)
|
||||
)
|
||||
|
||||
// Hard coding a name of an additional annotation for parcelize. Test that use this, need to provide the
|
||||
// additional annotations as part of the test sources.
|
||||
configuration.put(ParcelizeConfigurationKeys.ADDITIONAL_ANNOTATION, listOf("test.TriggerParcelize"))
|
||||
}
|
||||
|
||||
override fun CompilerPluginRegistrar.ExtensionStorage.registerCompilerExtensions(
|
||||
module: TestModule,
|
||||
configuration: CompilerConfiguration
|
||||
) {
|
||||
val additionalAnnotation = configuration.get(ParcelizeConfigurationKeys.ADDITIONAL_ANNOTATION)
|
||||
val additionalAnnotation = configuration.get(ParcelizeConfigurationKeys.ADDITIONAL_ANNOTATION) ?: emptyList()
|
||||
ParcelizeComponentRegistrar.registerParcelizeComponents(
|
||||
this,
|
||||
additionalAnnotation,
|
||||
|
||||
+3
-1
@@ -17,6 +17,8 @@ class ParcelizeUtilSourcesProvider(testServices: TestServices, baseDir: String =
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
override fun produceAdditionalFiles(globalDirectives: RegisteredDirectives, module: TestModule): List<TestFile> {
|
||||
return listOf(File(libraryPath).toTestFile())
|
||||
// Only provide the additional files for a JVM only module. In multiplatform tests, this ensures that the
|
||||
// additional files are only provided once and in the right module.
|
||||
return if (module.targetPlatform.all { it.platformName == "JVM" }) listOf(File(libraryPath).toTestFile()) else listOf()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user