Skip to content

Commit 7d4e975

Browse files
committed
Generate final test functions
Our two features didn't interact well.
1 parent 32156bb commit 7d4e975

File tree

10 files changed

+185
-0
lines changed

10 files changed

+185
-0
lines changed

burst-gradle-plugin/src/test/kotlin/app/cash/burst/gradle/TestInterceptorGradlePluginTest.kt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,65 @@ class TestInterceptorGradlePluginTest {
211211
)
212212
}
213213
}
214+
215+
@Test
216+
fun interceptorAndBurstConstructor() {
217+
val tester = GradleTester("interceptorAndBurst")
218+
tester.cleanAndBuild(":lib:test")
219+
220+
with(tester.readTestSuite("app.cash.burst.tests.InterceptorAndBurstConstructorTest_false")) {
221+
assertThat(systemOut).isEqualTo(
222+
"""
223+
|intercepting false test
224+
|running false
225+
|
226+
""".trimMargin(),
227+
)
228+
}
229+
with(tester.readTestSuite("app.cash.burst.tests.InterceptorAndBurstConstructorTest_true")) {
230+
assertThat(systemOut).isEqualTo(
231+
"""
232+
|intercepting true test
233+
|running true
234+
|
235+
""".trimMargin(),
236+
)
237+
}
238+
}
239+
240+
@Test
241+
fun interceptorAndBurstFunction() {
242+
val tester = GradleTester("interceptorAndBurst")
243+
tester.cleanAndBuild(":lib:test")
244+
245+
with(tester.readTestSuite("app.cash.burst.tests.InterceptorAndBurstFunctionTest")) {
246+
assertThat(systemOut).isEqualTo(
247+
"""
248+
|intercepting function test_true
249+
|running true
250+
|intercepting function test_false
251+
|running false
252+
|
253+
""".trimMargin(),
254+
)
255+
}
256+
}
257+
258+
@Test
259+
fun interceptorAndBurstSubclass() {
260+
val tester = GradleTester("interceptorAndBurst")
261+
tester.cleanAndBuild(":lib:test")
262+
263+
with(tester.readTestSuite("app.cash.burst.tests.InterceptorAndBurstSubclassTest")) {
264+
assertThat(systemOut).isEqualTo(
265+
"""
266+
|intercepting abstract test_true
267+
|running subclass true
268+
|intercepting abstract test_false
269+
|running subclass false
270+
|
271+
""".trimMargin(),
272+
)
273+
}
274+
}
214275
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
3+
4+
buildscript {
5+
repositories {
6+
maven {
7+
url = file("$rootDir/../../../../../build/testMaven").toURI()
8+
}
9+
mavenCentral()
10+
google()
11+
}
12+
dependencies {
13+
classpath("app.cash.burst:burst-gradle-plugin:${project.property("burstVersion")}")
14+
classpath(libs.kotlin.gradlePlugin)
15+
}
16+
}
17+
18+
allprojects {
19+
repositories {
20+
maven {
21+
url = file("$rootDir/../../../../../build/testMaven").toURI()
22+
}
23+
mavenCentral()
24+
google()
25+
}
26+
27+
tasks.withType(JavaCompile::class.java).configureEach {
28+
sourceCompatibility = "1.8"
29+
targetCompatibility = "1.8"
30+
}
31+
32+
tasks.withType(KotlinJvmCompile::class.java).configureEach {
33+
compilerOptions {
34+
jvmTarget.set(JvmTarget.JVM_1_8)
35+
}
36+
}
37+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
plugins {
2+
kotlin("jvm")
3+
id("app.cash.burst")
4+
}
5+
6+
dependencies {
7+
testImplementation(kotlin("test"))
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package app.cash.burst.tests
2+
3+
import app.cash.burst.TestFunction
4+
import app.cash.burst.TestInterceptor
5+
6+
class BasicInterceptor(val name: String) : TestInterceptor {
7+
override fun intercept(testFunction: TestFunction) {
8+
println("intercepting $name ${testFunction.functionName}")
9+
testFunction()
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package app.cash.burst.tests
2+
3+
import app.cash.burst.Burst
4+
import app.cash.burst.InterceptTest
5+
import kotlin.test.Test
6+
7+
@Burst
8+
abstract class InterceptorAndBurstAbstractTest {
9+
abstract val name: String
10+
11+
@InterceptTest
12+
val interceptor = BasicInterceptor("abstract")
13+
14+
@Test
15+
fun test(condition: Boolean) {
16+
println("running $name $condition")
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package app.cash.burst.tests
2+
3+
import app.cash.burst.Burst
4+
import app.cash.burst.InterceptTest
5+
import kotlin.test.Test
6+
7+
@Burst
8+
class InterceptorAndBurstConstructorTest(
9+
val condition: Boolean,
10+
) {
11+
@InterceptTest
12+
val interceptor = BasicInterceptor("$condition")
13+
14+
@Test
15+
fun test() {
16+
println("running $condition")
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package app.cash.burst.tests
2+
3+
import app.cash.burst.Burst
4+
import app.cash.burst.InterceptTest
5+
import kotlin.test.Test
6+
7+
@Burst
8+
class InterceptorAndBurstFunctionTest {
9+
@InterceptTest
10+
val interceptor = BasicInterceptor("function")
11+
12+
@Test
13+
fun test(condition: Boolean) {
14+
println("running $condition")
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package app.cash.burst.tests
2+
3+
class InterceptorAndBurstSubclassTest : InterceptorAndBurstAbstractTest() {
4+
override val name = "subclass"
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dependencyResolutionManagement {
2+
versionCatalogs {
3+
create("libs") {
4+
from(files("../../../../../gradle/libs.versions.toml"))
5+
}
6+
}
7+
}
8+
9+
include(":lib")

burst-kotlin-plugin/src/main/kotlin/app/cash/burst/kotlin/FunctionSpecializer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package app.cash.burst.kotlin
1717

1818
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
19+
import org.jetbrains.kotlin.descriptors.Modality
1920
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
2021
import org.jetbrains.kotlin.ir.builders.declarations.buildReceiverParameter
2122
import org.jetbrains.kotlin.ir.builders.irCall
@@ -108,6 +109,7 @@ internal class FunctionSpecializer(
108109
): IrSimpleFunction {
109110
val result = original.factory.buildFun {
110111
initDefaults(original)
112+
modality = Modality.FINAL
111113
name = when {
112114
isDefaultSpecialization -> original.name
113115
else -> Name.identifier("${original.name.identifier}_${specialization.name}")

0 commit comments

Comments
 (0)