Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically add the Burst dependency #14

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")}")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the goal of the PR

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")