Add a bunch of tests on corner-cases in Gradle MPP Import

For most of those the behaviour isn't set in stone, though at the moment
of making that commit we're more or less sure that it's reasonable.

Behaviour in some cases might be more strictly enforces (as much as you
can enforce something in esoteric cases with misconfigured project
sturcture). Those are marked with comments with '!'.
This commit is contained in:
Dmitry Savvinov
2020-12-15 17:38:33 +03:00
parent 69261ca1e6
commit 09286504b7
19 changed files with 399 additions and 0 deletions
@@ -420,6 +420,153 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
module("my-app.submodule.jsTest") { targetPlatform(js) }
}
}
@Test
@PluginTargetVersions(gradleVersionForLatestPlugin = mppImportTestMinVersionForMaster)
fun testOrphanSourceSet() {
configureByFiles()
importProject()
val jvm = JvmPlatforms.defaultJvmPlatform
val js = JsPlatforms.defaultJsPlatform
val native = NativePlatforms.unspecifiedNativePlatform
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
module("my-app.commonMain") {
// must not be (jvm, js, native)
targetPlatform(jvm, js)
}
module("my-app.orphan") {
targetPlatform(jvm, js)
}
}
}
@Test
@PluginTargetVersions(gradleVersionForLatestPlugin = mppImportTestMinVersionForMaster)
fun testSourceSetIncludedIntoCompilationDirectly() {
configureByFiles()
importProject()
val jvm = JvmPlatforms.defaultJvmPlatform
val js = JsPlatforms.defaultJsPlatform
val native = NativePlatforms.unspecifiedNativePlatform
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
module("my-app.commonMain") {
targetPlatform(jvm, js) // must not be (jvm, js, native)
}
module("my-app.includedIntoJvm") {
targetPlatform(jvm) // !
}
module("my-app.includedIntoJvmAndJs") {
targetPlatform(jvm, js) // !
}
}
}
@Test
@PluginTargetVersions(gradleVersionForLatestPlugin = mppImportTestMinVersionForMaster)
fun testDefaultSourceSetDependsOnDefaultSourceSet() {
configureByFiles()
importProject()
val jvm = JvmPlatforms.defaultJvmPlatform
val js = JsPlatforms.defaultJsPlatform
val native = NativePlatforms.unspecifiedNativePlatform
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
module("my-app.commonMain") {
targetPlatform(jvm, js) // must not be (jvm, js, native)
}
module("my-app.intermediateBetweenJsAndCommon") {
targetPlatform(jvm, js) // must not be (jvm, js, native)
}
module("my-app.jsMain") {
targetPlatform(js) // must not be (jvm, js)
}
module("my-app.jvmMain") {
targetPlatform(jvm)
}
}
}
@Test
@PluginTargetVersions(gradleVersionForLatestPlugin = mppImportTestMinVersionForMaster)
fun testDefaultSourceSetIncludedIntoAnotherCompilationDirectly() {
configureByFiles()
importProject()
val jvm = JvmPlatforms.defaultJvmPlatform
val js = JsPlatforms.defaultJsPlatform
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
module("my-app.jvmMain") {
targetPlatform(jvm) // must not be (jvm, js)
}
module("my-app.jsMain") {
targetPlatform(js)
}
}
}
@Test
@PluginTargetVersions(gradleVersionForLatestPlugin = mppImportTestMinVersionForMaster)
fun testSourceSetsWithDependsOnButNotIncludedIntoCompilation() {
configureByFiles()
importProject()
val jvm = JvmPlatforms.defaultJvmPlatform
val js = JsPlatforms.defaultJsPlatform
val native = NativePlatforms.unspecifiedNativePlatform
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
// (jvm, js, native) is highly undesirable
module("my-app.danglingOnJvm") {
targetPlatform(jvm, js)
}
module("my-app.commonMain") {
targetPlatform(jvm, js)
}
module("my-app.danglingOnCommon") {
targetPlatform(jvm, js)
}
module("my-app.danglingOnJvmAndJs") {
targetPlatform(jvm, js)
}
}
}
@Test
@PluginTargetVersions(gradleVersionForLatestPlugin = mppImportTestMinVersionForMaster)
fun testCustomAddToCompilationPlusDependsOn() {
configureByFiles()
importProject()
val jvm = JvmPlatforms.defaultJvmPlatform
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
module("my-app.includedIntoJvm") {
targetPlatform(jvm) // !
}
module("my-app.pseudoOrphan") {
targetPlatform(jvm) // !
}
}
}
private fun checkProjectStructure(
exhaustiveModuleList: Boolean = true,
exhaustiveSourceSourceRootList: Boolean = true,
@@ -0,0 +1,32 @@
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()
js()
sourceSets {
val pseudoOrphan by creating {
}
val includedIntoJvm by creating {
dependsOn(pseudoOrphan)
}
jvm().compilations["main"].source(includedIntoJvm)
}
}
@@ -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,37 @@
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()
js()
sourceSets {
val commonMain by getting {}
val intermediateBetweenJsAndCommon by creating {
dependsOn(commonMain)
}
val jsMain by getting {
dependsOn(intermediateBetweenJsAndCommon)
}
val jvmMain by getting {
dependsOn(jsMain)
}
}
}
@@ -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,27 @@
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()
js()
sourceSets {
val jvmMain by getting { }
js().compilations["main"].source(jvmMain)
}
}
@@ -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,25 @@
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()
js()
sourceSets {
val orphan by creating { }
}
}
@@ -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,31 @@
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()
js()
sourceSets {
val includedIntoJvm by creating { }
val includedIntoJvmAndJs by creating { }
jvm().compilations["main"].source(includedIntoJvm)
jvm().compilations["main"].source(includedIntoJvmAndJs)
js().compilations["main"].source(includedIntoJvmAndJs)
}
}
@@ -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,40 @@
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()
js()
sourceSets {
val commonMain by getting { }
val jvmMain by getting { }
val jsMain by getting { }
val danglingOnJvm by creating {
dependsOn(jvmMain)
}
val danglingOnCommon by creating {
dependsOn(commonMain)
}
val danglingOnJvmAndJs by creating {
dependsOn(jvmMain)
dependsOn(jsMain)
}
}
}
@@ -0,0 +1 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
@@ -0,0 +1,9 @@
pluginManagement {
repositories {
{{kts_kotlin_plugin_repositories}}
}
}
rootProject.name = "my-app"
enableFeaturePreview("GRADLE_METADATA")