Skip to content

Commit

Permalink
there is no longer a need to directly disable kover for test sharding
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Jul 27, 2023
1 parent cc7be15 commit 7d93b76
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions build-logic/src/main/kotlin/AndroidTestConfiguration.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.android.build.gradle.TestedExtension
import kotlinx.kover.gradle.plugin.dsl.KoverProjectExtension
import kotlinx.kover.gradle.plugin.dsl.KoverReportExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
Expand Down Expand Up @@ -40,8 +39,17 @@ internal fun TestedExtension.configureTestOptions(project: Project) {
}
}

// Test Sharding
val shard = project.findProperty("testShard")?.toString()?.toIntOrNull()
val totalShards = project.findProperty("testTotalShards")?.toString()?.toIntOrNull()
if (shard != null && totalShards != null) {
if (Math.floorMod(project.path.hashCode(), totalShards) != Math.floorMod(shard, totalShards)) {
project.androidComponents.beforeVariants { it.enableUnitTest = false }
}
}

// Kotlin Kover
project.apply(plugin = "org.jetbrains.kotlinx.kover")
project.plugins.apply("org.jetbrains.kotlinx.kover")
project.extensions.configure<KoverReportExtension> {
project.androidComponents.onVariants {
androidReports(it.name) {
Expand All @@ -52,14 +60,4 @@ internal fun TestedExtension.configureTestOptions(project: Project) {
}
}
}

// Test Sharding
val shard = project.findProperty("testShard")?.toString()?.toIntOrNull()
val totalShards = project.findProperty("testTotalShards")?.toString()?.toIntOrNull()
if (shard != null && totalShards != null) {
if (Math.floorMod(project.path.hashCode(), totalShards) != Math.floorMod(shard, totalShards)) {
project.extensions.configure<KoverProjectExtension> { disable() }
project.androidComponents.beforeVariants { it.enableUnitTest = false }
}
}
}

0 comments on commit 7d93b76

Please sign in to comment.