Skip to content

Commit

Permalink
Automatically add the Burst dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Oct 10, 2024
1 parent 2719db0 commit a64bcd4
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 3 deletions.
1 change: 1 addition & 0 deletions burst-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.vanniktech.maven.publish.MavenPublishBaseExtension

plugins {
id("java-gradle-plugin")
`kotlin-dsl`
kotlin("jvm")
id("com.github.gmazzo.buildconfig")
id("org.jetbrains.dokka")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@
*/
package app.cash.burst.gradle

import app.cash.burst.gradle.BuildConfig.burstVersion
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption

Expand All @@ -33,6 +42,30 @@ class BurstPlugin : KotlinCompilerPluginSupportPlugin {
version = BuildConfig.KOTLIN_PLUGIN_VERSION,
)

override fun apply(target: Project) {
super.apply(target)

// kotlin("multiplatform") targeting Java platforms.
target.plugins.withType<KotlinMultiplatformPluginWrapper> {
target.configure<KotlinMultiplatformExtension> {
sourceSets {
commonTest {
dependencies {
implementation("app.cash.burst:burst:$burstVersion")
}
}
}
}
}

// kotlin("jvm")
target.plugins.withType<KotlinPluginWrapper> {
target.dependencies {
add("testImplementation", "app.cash.burst:burst:$burstVersion")
}
}
}

override fun applyToCompilation(
kotlinCompilation: KotlinCompilation<*>,
): Provider<List<SubpluginOption>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import org.junit.Test

class BurstGradlePluginTest {
@Test
fun happyPath() {
val projectDir = File("src/test/projects/basic")
fun multiplatform() {
val projectDir = File("src/test/projects/multiplatform")

val taskName = ":lib:jvmTest"
val result = createRunner(projectDir, "clean", taskName).build()
Expand Down Expand Up @@ -61,6 +61,40 @@ class BurstGradlePluginTest {
assertThat(sampleVariant.skipped).isFalse()
}

@Test
fun jvm() {
val projectDir = File("src/test/projects/jvm")

val taskName = ":lib:test"
val result = createRunner(projectDir, "clean", taskName).build()
assertThat(SUCCESS_OUTCOMES)
.contains(result.task(taskName)!!.outcome)

val testResults = projectDir.resolve("lib/build/test-results")
val testXmlFile = testResults.resolve("test/TEST-CoffeeTest.xml")

val testSuite = readTestSuite(testXmlFile)

assertThat(testSuite.testCases.map { it.name }).containsExactlyInAnyOrder(
"test",
"test_Decaf_Oat",
"test_Regular_Milk",
"test_Regular_None",
"test_Decaf_Milk",
"test_Decaf_None",
"test_Double_Milk",
"test_Double_None",
"test_Regular_Oat",
"test_Double_Oat",
)

val originalTest = testSuite.testCases.single { it.name == "test" }
assertThat(originalTest.skipped).isTrue()

val sampleVariant = testSuite.testCases.single { it.name == "test_Decaf_Oat" }
assertThat(sampleVariant.skipped).isFalse()
}

private fun createRunner(
projectDir: File,
vararg taskNames: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
kotlin("jvm")
id("app.cash.burst")
}

dependencies {
testImplementation(kotlin("test"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
buildscript {
repositories {
maven {
url = file("$rootDir/../../../../../build/testMaven").toURI()
}
mavenCentral()
google()
}
dependencies {
classpath("app.cash.burst:burst-gradle-plugin:${project.property("burstVersion")}")
classpath(libs.kotlin.gradle.plugin)
}
}

allprojects {
repositories {
maven {
url = file("$rootDir/../../../../../build/testMaven").toURI()
}
mavenCentral()
google()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ kotlin {
sourceSets {
commonTest {
dependencies {
implementation("app.cash.burst:burst:${project.property("burstVersion")}")
implementation(kotlin("test"))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import app.cash.burst.Burst
import kotlin.test.Test

@Burst
class CoffeeTest {
val log = mutableListOf<String>()

@Test
fun test(espresso: Espresso, dairy: Dairy) {
log += "running $espresso $dairy"
}
}

enum class Espresso { Decaf, Regular, Double }

enum class Dairy { None, Milk, Oat }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../../../../../gradle/libs.versions.toml"))
}
}
}

include(":lib")

0 comments on commit a64bcd4

Please sign in to comment.