[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
|
package org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.HierarchicalStructureOptInMigrationArtifactContentMppIT.Mode.*
|
import org.gradle.util.GradleVersion
|
||||||
import org.junit.Test
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.junit.runner.RunWith
|
import org.junit.jupiter.api.DisplayName
|
||||||
import org.junit.runners.Parameterized
|
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 java.util.zip.ZipFile
|
||||||
|
import kotlin.io.path.deleteIfExists
|
||||||
|
import kotlin.streams.asStream
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
import kotlin.streams.toList
|
||||||
|
|
||||||
@RunWith(Parameterized::class)
|
@MppGradlePluginTests
|
||||||
internal class HierarchicalStructureOptInMigrationArtifactContentMppIT : BaseGradleIT() {
|
@DisplayName("Hierarchical multiplatform publication artifact content")
|
||||||
override val defaultGradleVersion: GradleVersionRequired = GradleVersionRequired.FOR_MPP_SUPPORT
|
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 {
|
enum class Mode {
|
||||||
HMPP_BY_DEFAULT, OPT_OUT_HMPP, DISABLE_HMPP_BY_DEFAULT
|
HMPP_BY_DEFAULT, OPT_OUT_HMPP, DISABLE_HMPP_BY_DEFAULT
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
class GradleAndHmppModeProvider : GradleArgumentsProvider() {
|
||||||
@Parameterized.Parameters(name = "{0}")
|
override fun provideArguments(
|
||||||
@JvmStatic
|
context: ExtensionContext
|
||||||
fun params() = Mode.values().map { arrayOf(it) }
|
): Stream<out Arguments> {
|
||||||
}
|
val gradleVersions = super.provideArguments(context).map { it.get().first() as GradleVersion }.toList()
|
||||||
|
|
||||||
@Parameterized.Parameter(0)
|
return gradleVersions
|
||||||
lateinit var mode: Mode
|
.flatMap { gradleVersion ->
|
||||||
|
Mode.entries.map {
|
||||||
@ExperimentalStdlibApi
|
Arguments.of(gradleVersion, it)
|
||||||
@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") }
|
|
||||||
}
|
}
|
||||||
when (mode) {
|
.asSequence()
|
||||||
OPT_OUT_HMPP -> add("-Pkotlin.mpp.hierarchicalStructureSupport=false")
|
.asStream()
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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