Skip to content

Commit f5b4b29

Browse files
ting-yuanKSP Auto Pick
authored andcommitted
Enable both KSP1 and KSP2 in gradle plugin tests
(cherry picked from commit c00cad1)
1 parent f9460ee commit f5b4b29

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/GradleCompilationTest.kt

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,25 @@ import org.junit.Assume
3232
import org.junit.Rule
3333
import org.junit.Test
3434
import org.junit.rules.TemporaryFolder
35+
import org.junit.runner.RunWith
36+
import org.junit.runners.Parameterized
37+
38+
@RunWith(Parameterized::class)
39+
class GradleCompilationTest(val useKSP2: Boolean) {
40+
41+
companion object {
42+
@JvmStatic
43+
@Parameterized.Parameters(name = "KSP2={0}")
44+
fun params() = listOf(arrayOf(true), arrayOf(false))
45+
}
3546

36-
class GradleCompilationTest {
3747
@Rule
3848
@JvmField
3949
val tmpDir = TemporaryFolder()
4050

4151
@Rule
4252
@JvmField
43-
val testRule = KspIntegrationTestRule(tmpDir)
53+
val testRule = KspIntegrationTestRule(tmpDir, useKSP2)
4454

4555
@Test
4656
fun errorMessageFailsCompilation() {
@@ -239,8 +249,8 @@ class GradleCompilationTest {
239249
)
240250
testRule.appModule.dependencies.addAll(
241251
listOf(
242-
artifact(configuration = "ksp", "androidx.room:room-compiler:2.4.2"),
243-
artifact(configuration = "implementation", "androidx.room:room-runtime:2.4.2")
252+
artifact(configuration = "ksp", "androidx.room:room-compiler:2.6.1"),
253+
artifact(configuration = "implementation", "androidx.room:room-runtime:2.6.1")
244254
)
245255
)
246256
testRule.appModule.buildFileAdditions.add(
@@ -267,6 +277,13 @@ class GradleCompilationTest {
267277
}
268278
}
269279
}
280+
tasks.withType<com.google.devtools.ksp.gradle.KspAATask>().configureEach {
281+
doFirst {
282+
kspConfig.processorOptions.get().forEach { (key, value) ->
283+
println("apoption=${'$'}key=${'$'}value")
284+
}
285+
}
286+
}
270287
271288
""".trimIndent()
272289
)
@@ -312,6 +329,7 @@ class GradleCompilationTest {
312329
@Test
313330
fun commandLineArgumentIsIncludedInApoptionsWhenAddedInKspTask() {
314331
Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true))
332+
Assume.assumeFalse(useKSP2)
315333
testRule.setupAppAsAndroidApp()
316334
testRule.appModule.dependencies.addAll(
317335
listOf(
@@ -366,6 +384,11 @@ class GradleCompilationTest {
366384
println("HAS LIBRARY: ${'$'}{it.path}")
367385
}
368386
}
387+
tasks.withType<com.google.devtools.ksp.gradle.KspAATask>().configureEach {
388+
kspConfig.libraries.files.forEach {
389+
println("HAS LIBRARY: ${'$'}{it.path}")
390+
}
391+
}
369392
}
370393
""".trimIndent()
371394
)
@@ -389,6 +412,7 @@ class GradleCompilationTest {
389412

390413
@Test
391414
fun changingKsp2AtRuntime() {
415+
Assume.assumeFalse(useKSP2)
392416
testRule.setupAppAsJvmApp()
393417
testRule.appModule.buildFileAdditions.add(
394418
"""

gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/ProcessorClasspathConfigurationsTest.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,25 @@ import com.google.devtools.ksp.gradle.testing.KspIntegrationTestRule
2121
import org.junit.Rule
2222
import org.junit.Test
2323
import org.junit.rules.TemporaryFolder
24+
import org.junit.runner.RunWith
25+
import org.junit.runners.Parameterized
26+
27+
@RunWith(Parameterized::class)
28+
class ProcessorClasspathConfigurationsTest(val useKSP2: Boolean) {
29+
30+
companion object {
31+
@JvmStatic
32+
@Parameterized.Parameters(name = "KSP2={0}")
33+
fun params() = listOf(arrayOf(true), arrayOf(false))
34+
}
2435

25-
class ProcessorClasspathConfigurationsTest {
2636
@Rule
2737
@JvmField
2838
val tmpDir = TemporaryFolder()
2939

3040
@Rule
3141
@JvmField
32-
val testRule = KspIntegrationTestRule(tmpDir)
42+
val testRule = KspIntegrationTestRule(tmpDir, useKSP2)
3343

3444
private val kspConfigs by lazy {
3545
"""configurations.matching { it.name.startsWith("ksp") && !it.name.endsWith("ProcessorClasspath") }"""

gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/SourceSetConfigurationsTest.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,26 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration
3030
import org.junit.Rule
3131
import org.junit.Test
3232
import org.junit.rules.TemporaryFolder
33+
import org.junit.runner.RunWith
34+
import org.junit.runners.Parameterized
3335
import java.io.File
3436

35-
class SourceSetConfigurationsTest {
37+
@RunWith(Parameterized::class)
38+
class SourceSetConfigurationsTest(val useKSP2: Boolean) {
39+
40+
companion object {
41+
@JvmStatic
42+
@Parameterized.Parameters(name = "KSP2={0}")
43+
fun params() = listOf(arrayOf(true), arrayOf(false))
44+
}
45+
3646
@Rule
3747
@JvmField
3848
val tmpDir = TemporaryFolder()
3949

4050
@Rule
4151
@JvmField
42-
val testRule = KspIntegrationTestRule(tmpDir)
52+
val testRule = KspIntegrationTestRule(tmpDir, useKSP2)
4353

4454
@Test
4555
fun configurationsForJvmApp() {

gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/testing/KspIntegrationTestRule.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import kotlin.reflect.KClass
2929
* Test must call [setupAppAsAndroidApp] or [setupAppAsJvmApp] before using the [runner].
3030
*/
3131
class KspIntegrationTestRule(
32-
private val tmpFolder: TemporaryFolder
32+
private val tmpFolder: TemporaryFolder,
33+
private val useKSP2: Boolean
3334
) : TestWatcher() {
3435
/**
3536
* Initialized when the test starts.
@@ -144,7 +145,7 @@ class KspIntegrationTestRule(
144145
"""
145146
android {
146147
namespace = "com.example.kspandroidtestapp"
147-
compileSdk = 31
148+
compileSdk = 34
148149
defaultConfig {
149150
minSdk = 24
150151
}
@@ -168,6 +169,6 @@ class KspIntegrationTestRule(
168169

169170
override fun starting(description: Description) {
170171
super.starting(description)
171-
testProject = TestProject(tmpFolder.newFolder(), testConfig)
172+
testProject = TestProject(tmpFolder.newFolder(), testConfig, useKSP2)
172173
}
173174
}

gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/testing/TestProject.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import java.io.File
2323
*/
2424
class TestProject(
2525
val rootDir: File,
26-
val testConfig: TestConfig
26+
val testConfig: TestConfig,
27+
val useKSP2: Boolean,
2728
) {
2829
val processorModule = TestModule(
2930
rootDir.resolve("processor")
@@ -59,6 +60,7 @@ class TestProject(
5960
val contents = """
6061
6162
kotlin.jvm.target.validation.mode=warning
63+
ksp.useKSP2=$useKSP2
6264
""".trimIndent()
6365
rootDir.resolve("gradle.properties").appendText(contents)
6466
}

0 commit comments

Comments
 (0)