syncKotlinAndAndroidSourceSets.kt: Cover flavors with tests
This commit is contained in:
committed by
Sebastian Sellmair
parent
cdfbbca580
commit
3e5cbf324d
+11
-2
@@ -49,9 +49,18 @@ open class KotlinAndroid36GradleIT : KotlinAndroid33GradleIT() {
|
||||
assertContains("JNI sources: [lib/src/androidTestDebug/jni, lib/src/androidAndroidTestDebug/jni]")
|
||||
assertContains("JNI libraries: [lib/src/androidTestDebug/jniLibs, lib/src/androidAndroidTestDebug/jniLibs]")
|
||||
assertContains("Java-style resources: [lib/src/androidTestDebug/resources, lib/src/androidAndroidTestDebug/resources]")
|
||||
|
||||
assertContains("Java sources: [lib/betaSrc/paidBeta/java, lib/src/androidPaidBeta/kotlin, lib/src/paidBeta/kotlin]")
|
||||
assertContains("Java sources: [lib/betaSrc/paidBetaDebug/java, lib/src/androidPaidBetaDebug/kotlin, lib/src/paidBetaDebug/kotlin]")
|
||||
assertContains("Java sources: [lib/betaSrc/paidBetaRelease/java, lib/src/androidPaidBetaRelease/kotlin, lib/src/paidBetaRelease/kotlin]")
|
||||
|
||||
assertContains("Java sources: [lib/betaSrc/freeBeta/java, lib/src/androidFreeBeta/kotlin, lib/src/freeBeta/kotlin]")
|
||||
assertContains("Java sources: [lib/betaSrc/freeBetaDebug/java, lib/src/androidFreeBetaDebug/kotlin, lib/src/freeBetaDebug/kotlin]")
|
||||
assertContains("Java sources: [lib/betaSrc/freeBetaRelease/java, lib/src/androidFreeBetaRelease/kotlin, lib/src/freeBetaRelease/kotlin]")
|
||||
|
||||
}
|
||||
|
||||
build("testDebug") {
|
||||
build("testFreeBetaDebug") {
|
||||
assertFailed()
|
||||
assertContains("CommonTest > fail FAILED")
|
||||
assertContains("TestKotlin > fail FAILED")
|
||||
@@ -886,4 +895,4 @@ fun getSomething() = 10
|
||||
assertContainsRegex(kotlinJvmTarget18Regex)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+43
-2
@@ -10,6 +10,47 @@ android {
|
||||
targetSdkVersion(28)
|
||||
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
flavorDimensions("pricing", "releaseType")
|
||||
|
||||
productFlavors {
|
||||
create("beta") {
|
||||
setDimension("releaseType")
|
||||
}
|
||||
create("production") {
|
||||
setDimension("releaseType")
|
||||
}
|
||||
create("free") {
|
||||
setDimension("pricing")
|
||||
}
|
||||
create("paid") {
|
||||
setDimension("pricing")
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
maybeCreate("beta").apply {
|
||||
setRoot("betaSrc/beta")
|
||||
}
|
||||
maybeCreate("freeBeta").apply {
|
||||
setRoot("betaSrc/freeBeta")
|
||||
}
|
||||
maybeCreate("freeBetaDebug").apply {
|
||||
setRoot("betaSrc/freeBetaDebug")
|
||||
}
|
||||
maybeCreate("freeBetaRelease").apply {
|
||||
setRoot("betaSrc/freeBetaRelease")
|
||||
}
|
||||
maybeCreate("paidBeta").apply {
|
||||
setRoot("betaSrc/paidBeta")
|
||||
}
|
||||
maybeCreate("paidBetaDebug").apply {
|
||||
setRoot("betaSrc/paidBetaDebug")
|
||||
}
|
||||
maybeCreate("paidBetaRelease").apply {
|
||||
setRoot("betaSrc/paidBetaRelease")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
@@ -21,7 +62,7 @@ kotlin {
|
||||
implementation(kotlin("stdlib-common"))
|
||||
}
|
||||
|
||||
getByName("commonMain").dependencies {
|
||||
getByName("commonTest").dependencies {
|
||||
implementation(kotlin("test"))
|
||||
implementation(kotlin("test-annotations-common"))
|
||||
}
|
||||
@@ -35,4 +76,4 @@ kotlin {
|
||||
implementation("com.android.support.test:runner:1.0.2")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+40
-1
@@ -2,7 +2,7 @@
|
||||
* Copyright 2010-2020 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("invisible_reference", "invisible_member", "FunctionName")
|
||||
@file:Suppress("invisible_reference", "invisible_member", "FunctionName", "DuplicatedCode")
|
||||
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
@@ -89,8 +89,47 @@ class SyncKotlinAndAndroidSourceSetsTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `two product flavor dimensions`() {
|
||||
android.flavorDimensions("pricing", "releaseType")
|
||||
android.productFlavors {
|
||||
it.create("beta").dimension = "releaseType"
|
||||
it.create("production").dimension = "releaseType"
|
||||
it.create("free").dimension = "pricing"
|
||||
it.create("paid").dimension = "pricing"
|
||||
}
|
||||
kotlin.android()
|
||||
project.evaluate()
|
||||
|
||||
fun assertSourceSetsExist(androidName: String, kotlinName: String) {
|
||||
val androidSourceSet = assertNotNull(android.sourceSets.findByName(androidName), "Expected Android source set '$androidName'")
|
||||
val kotlinSourceSet = assertNotNull(kotlin.sourceSets.findByName(kotlinName), "Expected Kotlin source set '$kotlinName'")
|
||||
assertSame(kotlinSourceSet, androidSourceSet.kotlinSourceSet)
|
||||
}
|
||||
|
||||
assertSourceSetsExist("freeBetaDebug", "androidFreeBetaDebug")
|
||||
assertSourceSetsExist("freeBetaRelease", "androidFreeBetaRelease")
|
||||
|
||||
assertSourceSetsExist("freeProductionDebug", "androidFreeProductionDebug")
|
||||
assertSourceSetsExist("freeProductionRelease", "androidFreeProductionRelease")
|
||||
|
||||
|
||||
assertSourceSetsExist("paidBetaDebug", "androidPaidBetaDebug")
|
||||
assertSourceSetsExist("paidBetaRelease", "androidPaidBetaRelease")
|
||||
|
||||
assertSourceSetsExist("paidProductionDebug", "androidPaidProductionDebug")
|
||||
assertSourceSetsExist("paidProductionRelease", "androidPaidProductionRelease")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `all source directories are disjoint in source sets`() {
|
||||
android.flavorDimensions("pricing", "releaseType")
|
||||
android.productFlavors {
|
||||
it.create("beta").dimension = "releaseType"
|
||||
it.create("production").dimension = "releaseType"
|
||||
it.create("free").dimension = "pricing"
|
||||
it.create("paid").dimension = "pricing"
|
||||
}
|
||||
kotlin.android()
|
||||
project.evaluate()
|
||||
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ private fun syncKotlinAndAndroidResources(
|
||||
androidSourceSet.resources.srcDirs(*kotlinSourceSet.resources.toList().toTypedArray())
|
||||
if (androidSourceSet.resources.srcDirs.isNotEmpty()) {
|
||||
androidSourceSet.resources.srcDir(kotlinSourceSet.sourceFolderFor(project, "resources"))
|
||||
kotlinSourceSet.resources.srcDirs(androidSourceSet.resources.srcDirs - kotlinSourceSet.resources.srcDirs)
|
||||
kotlinSourceSet.resources.srcDirs(androidSourceSet.resources.srcDirs)
|
||||
}
|
||||
|
||||
if (androidSourceSet.assets.srcDirs.isNotEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user