[Gradle] Add unit test, checking which metadata compilations are created
This will quickly notify any developer if some code has unexpected effects on the creation of metadata compilations ^KT-58319 Verification Pending
This commit is contained in:
committed by
Space Team
parent
8273328726
commit
56ba5a284d
+3
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.metadata
|
||||
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.result.ResolvedArtifactResult
|
||||
import org.gradle.api.attributes.Category
|
||||
@@ -505,8 +506,9 @@ private val KotlinMetadataTarget.metadataCompilationsCreated: CompletableFuture<
|
||||
CompletableFuture()
|
||||
}
|
||||
|
||||
internal suspend fun KotlinMetadataTarget.awaitMetadataCompilationsCreated() {
|
||||
internal suspend fun KotlinMetadataTarget.awaitMetadataCompilationsCreated(): NamedDomainObjectContainer<KotlinCompilation<*>> {
|
||||
metadataCompilationsCreated.await()
|
||||
return compilations
|
||||
}
|
||||
|
||||
internal suspend fun Project.findMetadataCompilation(sourceSet: KotlinSourceSet): KotlinMetadataCompilation<*>? {
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@file:Suppress("FunctionName")
|
||||
|
||||
package org.jetbrains.kotlin.gradle.unitTests
|
||||
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.awaitMetadataCompilationsCreated
|
||||
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
|
||||
import org.jetbrains.kotlin.gradle.util.runLifecycleAwareTest
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.fail
|
||||
|
||||
class KotlinMetadataTargetCompilationsTest {
|
||||
@Test
|
||||
fun `test - metadata compilations created for shared source sets`() {
|
||||
val project = buildProjectWithMPP()
|
||||
val kotlin = project.multiplatformExtension
|
||||
|
||||
kotlin.jvm()
|
||||
kotlin.linuxX64()
|
||||
kotlin.linuxArm64()
|
||||
kotlin.targetHierarchy.default()
|
||||
|
||||
project.runLifecycleAwareTest {
|
||||
val target = kotlin.metadata() as KotlinMetadataTarget
|
||||
val metadataCompilations = target.awaitMetadataCompilationsCreated()
|
||||
metadataCompilations.assertExists("commonMain")
|
||||
metadataCompilations.assertExists("nativeMain")
|
||||
metadataCompilations.assertExists("linuxMain")
|
||||
|
||||
metadataCompilations.assertExistsNot("commonTest")
|
||||
metadataCompilations.assertExistsNot("nativeTest")
|
||||
metadataCompilations.assertExistsNot("linuxTest")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test - metadata compilations - single target project`() {
|
||||
val project = buildProjectWithMPP()
|
||||
val kotlin = project.multiplatformExtension
|
||||
kotlin.jvm()
|
||||
kotlin.targetHierarchy.default()
|
||||
|
||||
project.runLifecycleAwareTest {
|
||||
val target = kotlin.metadata() as KotlinMetadataTarget
|
||||
val compilations = target.awaitMetadataCompilationsCreated()
|
||||
compilations.assertExistsNot("commonMain")
|
||||
}
|
||||
}
|
||||
|
||||
private fun NamedDomainObjectContainer<KotlinCompilation<*>>.assertExists(name: String) {
|
||||
if (name !in names) fail("Missing '$name' compilation")
|
||||
}
|
||||
|
||||
private fun NamedDomainObjectContainer<KotlinCompilation<*>>.assertExistsNot(name: String) {
|
||||
if (name in names) fail("Unexpected '$name' compilation")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user