[Gradle] Migrate HierarchicalStructureOptInMigrationArtifactContentMppIT to new test DSL
^KT-65528 In Progress
This commit is contained in:
committed by
Space Team
parent
81fded3c8b
commit
eac48d065b
+80
-52
@@ -5,69 +5,97 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.jetbrains.kotlin.gradle.HierarchicalStructureOptInMigrationArtifactContentMppIT.Mode.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.extension.ExtensionContext
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.Arguments
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource
|
||||
import java.util.stream.Stream
|
||||
import java.util.zip.ZipFile
|
||||
import kotlin.io.path.deleteIfExists
|
||||
import kotlin.streams.asStream
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.streams.toList
|
||||
|
||||
@RunWith(Parameterized::class)
|
||||
internal class HierarchicalStructureOptInMigrationArtifactContentMppIT : BaseGradleIT() {
|
||||
override val defaultGradleVersion: GradleVersionRequired = GradleVersionRequired.FOR_MPP_SUPPORT
|
||||
@MppGradlePluginTests
|
||||
@DisplayName("Hierarchical multiplatform publication artifact content")
|
||||
internal class HierarchicalStructureOptInMigrationArtifactContentMppIT : KGPBaseTest() {
|
||||
|
||||
@GradleWithHmppModeTest
|
||||
@DisplayName("Artifact format and content conformance")
|
||||
fun testArtifactFormatAndContent(
|
||||
gradleVersion: GradleVersion,
|
||||
hmppMode: Mode,
|
||||
) {
|
||||
project("new-mpp-published", gradleVersion) {
|
||||
gradleProperties.deleteIfExists()
|
||||
|
||||
val hierarchicalStructureFlag = when (hmppMode) {
|
||||
Mode.OPT_OUT_HMPP, Mode.HMPP_BY_DEFAULT -> null
|
||||
Mode.DISABLE_HMPP_BY_DEFAULT -> "-Pkotlin.internal.mpp.hierarchicalStructureByDefault=false"
|
||||
}
|
||||
val hierarchicalStructureSupportFlag = when(hmppMode) {
|
||||
Mode.OPT_OUT_HMPP -> "-Pkotlin.mpp.hierarchicalStructureSupport=false"
|
||||
Mode.HMPP_BY_DEFAULT, Mode.DISABLE_HMPP_BY_DEFAULT -> null
|
||||
}
|
||||
|
||||
build(
|
||||
buildArguments = listOfNotNull(
|
||||
"clean",
|
||||
"publish",
|
||||
"-Pkotlin.internal.suppressGradlePluginErrors=PreHMPPFlagsError",
|
||||
hierarchicalStructureFlag,
|
||||
hierarchicalStructureSupportFlag
|
||||
).toTypedArray()
|
||||
) {
|
||||
val metadataJarEntries = ZipFile(
|
||||
projectPath.resolve("../repo/com/example/bar/my-lib-bar/1.0/my-lib-bar-1.0.jar").toFile()
|
||||
).use { zip ->
|
||||
zip.entries().asSequence().toList().map { it.name }
|
||||
}
|
||||
|
||||
if (hmppMode != Mode.DISABLE_HMPP_BY_DEFAULT) {
|
||||
assertTrue { metadataJarEntries.any { "commonMain" in it } }
|
||||
}
|
||||
|
||||
val hasJvmAndJsMainEntries = metadataJarEntries.any { "jvmAndJsMain" in it }
|
||||
val shouldHaveJvmAndJsMainEntries = when (hmppMode) {
|
||||
Mode.OPT_OUT_HMPP, Mode.DISABLE_HMPP_BY_DEFAULT -> false
|
||||
Mode.HMPP_BY_DEFAULT -> true
|
||||
}
|
||||
assertEquals(shouldHaveJvmAndJsMainEntries, hasJvmAndJsMainEntries)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class Mode {
|
||||
HMPP_BY_DEFAULT, OPT_OUT_HMPP, DISABLE_HMPP_BY_DEFAULT
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
@JvmStatic
|
||||
fun params() = Mode.values().map { arrayOf(it) }
|
||||
}
|
||||
class GradleAndHmppModeProvider : GradleArgumentsProvider() {
|
||||
override fun provideArguments(
|
||||
context: ExtensionContext
|
||||
): Stream<out Arguments> {
|
||||
val gradleVersions = super.provideArguments(context).map { it.get().first() as GradleVersion }.toList()
|
||||
|
||||
@Parameterized.Parameter(0)
|
||||
lateinit var mode: Mode
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
@Test
|
||||
@Suppress("NON_EXHAUSTIVE_WHEN")
|
||||
fun testArtifactFormatAndContent() = with(transformProjectWithPluginsDsl("new-mpp-published")) {
|
||||
projectDir.resolve("gradle.properties").delete()
|
||||
|
||||
build(
|
||||
*buildList {
|
||||
add("clean")
|
||||
add("publish")
|
||||
add("-Pkotlin.internal.suppressGradlePluginErrors=PreHMPPFlagsError")
|
||||
when (mode) {
|
||||
OPT_OUT_HMPP, HMPP_BY_DEFAULT -> {}
|
||||
DISABLE_HMPP_BY_DEFAULT -> { add("-Pkotlin.internal.mpp.hierarchicalStructureByDefault=false") }
|
||||
return gradleVersions
|
||||
.flatMap { gradleVersion ->
|
||||
Mode.entries.map {
|
||||
Arguments.of(gradleVersion, it)
|
||||
}
|
||||
}
|
||||
when (mode) {
|
||||
OPT_OUT_HMPP -> add("-Pkotlin.mpp.hierarchicalStructureSupport=false")
|
||||
HMPP_BY_DEFAULT, DISABLE_HMPP_BY_DEFAULT -> {}
|
||||
}
|
||||
}.toTypedArray(),
|
||||
) {
|
||||
assertSuccessful()
|
||||
val metadataJarEntries = ZipFile(
|
||||
projectDir.resolve("../repo/com/example/bar/my-lib-bar/1.0/my-lib-bar-1.0.jar")
|
||||
).use { zip ->
|
||||
zip.entries().asSequence().toList().map { it.name }
|
||||
}
|
||||
|
||||
if (mode != DISABLE_HMPP_BY_DEFAULT) {
|
||||
assertTrue { metadataJarEntries.any { "commonMain" in it } }
|
||||
}
|
||||
|
||||
val hasJvmAndJsMainEntries = metadataJarEntries.any { "jvmAndJsMain" in it }
|
||||
val shouldHaveJvmAndJsMainEntries = when (mode) {
|
||||
OPT_OUT_HMPP, DISABLE_HMPP_BY_DEFAULT -> false
|
||||
HMPP_BY_DEFAULT -> true
|
||||
}
|
||||
assertEquals(shouldHaveJvmAndJsMainEntries, hasJvmAndJsMainEntries)
|
||||
.asSequence()
|
||||
.asStream()
|
||||
}
|
||||
}
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@GradleTestVersions
|
||||
@ParameterizedTest(name = "{0} mode {1}: {displayName}")
|
||||
@ArgumentsSource(GradleAndHmppModeProvider::class)
|
||||
annotation class GradleWithHmppModeTest
|
||||
}
|
||||
Reference in New Issue
Block a user