Add tests on precise platforms importing

Note the behaviour in 'precisePlatformsWithUnrelatedModuleHmpp': it is
incorrect, as set of platforms still contains unrelated platforms.

This is because in the current solution, some source-sets
(commonMain/commonTest) always receive COMMON platform and then it gets
coerced to set of targets actually seen in the project.This helps if
projects uses as much targets as current module (like in
precisePlatformsHmpp), but fails if it uses more targets than the
current module (like in precisePlatformsWithUnrelatedModuleHmppp)

The upcoming commits will fix that issue
This commit is contained in:
Dmitry Savvinov
2020-12-15 17:38:12 +03:00
parent 250cc1dc92
commit 69261ca1e6
8 changed files with 262 additions and 0 deletions
@@ -340,6 +340,86 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
}
}
@Test
@PluginTargetVersions(gradleVersionForLatestPlugin = mppImportTestMinVersionForMaster)
fun testPrecisePlatformsHmpp() {
configureByFiles()
importProject()
val jvm = JvmPlatforms.defaultJvmPlatform
val anyNative = NativePlatforms.unspecifiedNativePlatform
val linux = NativePlatforms.nativePlatformBySingleTarget(KonanTarget.LINUX_X64)
val macos = NativePlatforms.nativePlatformBySingleTarget(KonanTarget.MACOS_X64)
checkProjectStructure(exhaustiveModuleList = true, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
module("my-app") {
targetPlatform(jvm)
}
module("my-app.commonMain") { targetPlatform(jvm, anyNative) }
module("my-app.commonTest") { targetPlatform(jvm, anyNative) }
module("my-app.jvmAndLinuxMain") { targetPlatform(jvm, anyNative) }
module("my-app.jvmAndLinuxTest") { targetPlatform(jvm, anyNative) }
module("my-app.jvmMain") { targetPlatform(jvm) }
module("my-app.jvmTest") { targetPlatform(jvm) }
module("my-app.linuxX64Main") { targetPlatform(linux) }
module("my-app.linuxX64Test") { targetPlatform(linux) }
module("my-app.macosX64Main") { targetPlatform(macos) }
module("my-app.macosX64Test") { targetPlatform(macos) }
}
}
@Test
@PluginTargetVersions(gradleVersionForLatestPlugin = mppImportTestMinVersionForMaster)
fun testPrecisePlatformsWithUnrelatedModuleHmpp() {
configureByFiles()
importProject()
val jvm = JvmPlatforms.defaultJvmPlatform
val anyNative = NativePlatforms.unspecifiedNativePlatform
val js = JsPlatforms.defaultJsPlatform
val linux = NativePlatforms.nativePlatformBySingleTarget(KonanTarget.LINUX_X64)
val macos = NativePlatforms.nativePlatformBySingleTarget(KonanTarget.MACOS_X64)
checkProjectStructure(exhaustiveModuleList = true, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
// root project
module("my-app") {
targetPlatform(jvm)
}
module("my-app.commonMain") { targetPlatform(jvm, anyNative, js) } // :( should be (jvm, anyNative)
module("my-app.commonTest") { targetPlatform(jvm, anyNative, js) } // :( should be (jvm, anyNative)
module("my-app.jvmAndLinuxMain") { targetPlatform(jvm, anyNative) }
module("my-app.jvmAndLinuxTest") { targetPlatform(jvm, anyNative) }
module("my-app.jvmMain") { targetPlatform(jvm) }
module("my-app.jvmTest") { targetPlatform(jvm) }
module("my-app.linuxX64Main") { targetPlatform(linux) }
module("my-app.linuxX64Test") { targetPlatform(linux) }
module("my-app.macosX64Main") { targetPlatform(macos) }
module("my-app.macosX64Test") { targetPlatform(macos) }
// submodule
module("my-app.submodule") { targetPlatform(jvm) }
module("my-app.submodule.commonMain") { targetPlatform(js, jvm, anyNative) } // :( should be (js, jvm)
module("my-app.submodule.commonTest") { targetPlatform(js, jvm, anyNative) } // :( should be (js, jvm)
module("my-app.submodule.jvmMain") { targetPlatform(jvm) }
module("my-app.submodule.jvmTest") { targetPlatform(jvm) }
module("my-app.submodule.jsMain") { targetPlatform(js) }
module("my-app.submodule.jsTest") { targetPlatform(js) }
}
}
private fun checkProjectStructure(
exhaustiveModuleList: Boolean = true,
exhaustiveSourceSourceRootList: Boolean = true,
@@ -0,0 +1,71 @@
/**
* commonMain----
* / \
* jvmAndLinuxMain \
* / \ \
* jvm linuxX64 macosX64
*
* (the tests structure is the same)
*/
buildscript {
repositories {
{{kts_kotlin_plugin_repositories}}
}
}
repositories {
{{kts_kotlin_plugin_repositories}}
}
plugins {
kotlin("multiplatform").version("{{kotlin_plugin_version}}")
}
group = "project"
version = "1.0"
kotlin {
jvm()
linuxX64()
macosX64()
sourceSets {
val commonMain by getting {
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmAndLinuxMain by creating {
dependsOn(commonMain)
}
val jvmAndLinuxTest by creating {
dependsOn(commonTest)
}
val jvmMain by getting {
dependsOn(jvmAndLinuxMain)
}
val jvmTest by getting {
dependsOn(jvmAndLinuxTest)
dependencies {
implementation(kotlin("test-junit"))
}
}
val linuxX64Main by getting {
dependsOn(jvmAndLinuxMain)
}
val linuxX64Test by getting {
dependsOn(jvmAndLinuxTest)
}
}
}
@@ -0,0 +1 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
@@ -0,0 +1,9 @@
pluginManagement {
repositories {
{{kts_kotlin_plugin_repositories}}
}
}
rootProject.name = "my-app"
enableFeaturePreview("GRADLE_METADATA")
@@ -0,0 +1,71 @@
/**
* commonMain----
* / \
* jvmAndLinuxMain \
* / \ \
* jvm linuxX64 macosX64
*
* (the tests structure is the same)
*/
buildscript {
repositories {
{{kts_kotlin_plugin_repositories}}
}
}
repositories {
{{kts_kotlin_plugin_repositories}}
}
plugins {
kotlin("multiplatform").version("{{kotlin_plugin_version}}")
}
group = "project"
version = "1.0"
kotlin {
jvm()
linuxX64()
macosX64()
sourceSets {
val commonMain by getting {
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmAndLinuxMain by creating {
dependsOn(commonMain)
}
val jvmAndLinuxTest by creating {
dependsOn(commonTest)
}
val jvmMain by getting {
dependsOn(jvmAndLinuxMain)
}
val jvmTest by getting {
dependsOn(jvmAndLinuxTest)
dependencies {
implementation(kotlin("test-junit"))
}
}
val linuxX64Main by getting {
dependsOn(jvmAndLinuxMain)
}
val linuxX64Test by getting {
dependsOn(jvmAndLinuxTest)
}
}
}
@@ -0,0 +1 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
@@ -0,0 +1,11 @@
pluginManagement {
repositories {
{{kts_kotlin_plugin_repositories}}
}
}
rootProject.name = "my-app"
enableFeaturePreview("GRADLE_METADATA")
include(":submodule")
@@ -0,0 +1,18 @@
buildscript {
repositories {
{{kts_kotlin_plugin_repositories}}
}
}
repositories {
{{kts_kotlin_plugin_repositories}}
}
plugins {
kotlin("multiplatform")
}
kotlin {
js()
jvm()
}