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

Enable both KSP1 and KSP2 in gradle plugin tests #2200

Merged
merged 1 commit into from
Nov 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,25 @@ import org.junit.Assume
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized::class)
class GradleCompilationTest(val useKSP2: Boolean) {

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}

class GradleCompilationTest {
@Rule
@JvmField
val tmpDir = TemporaryFolder()

@Rule
@JvmField
val testRule = KspIntegrationTestRule(tmpDir)
val testRule = KspIntegrationTestRule(tmpDir, useKSP2)

@Test
fun errorMessageFailsCompilation() {
Expand Down Expand Up @@ -239,8 +249,8 @@ class GradleCompilationTest {
)
testRule.appModule.dependencies.addAll(
listOf(
artifact(configuration = "ksp", "androidx.room:room-compiler:2.4.2"),
artifact(configuration = "implementation", "androidx.room:room-runtime:2.4.2")
artifact(configuration = "ksp", "androidx.room:room-compiler:2.6.1"),
artifact(configuration = "implementation", "androidx.room:room-runtime:2.6.1")
)
)
testRule.appModule.buildFileAdditions.add(
Expand All @@ -267,6 +277,13 @@ class GradleCompilationTest {
}
}
}
tasks.withType<com.google.devtools.ksp.gradle.KspAATask>().configureEach {
doFirst {
kspConfig.processorOptions.get().forEach { (key, value) ->
println("apoption=${'$'}key=${'$'}value")
}
}
}

""".trimIndent()
)
Expand Down Expand Up @@ -312,6 +329,7 @@ class GradleCompilationTest {
@Test
fun commandLineArgumentIsIncludedInApoptionsWhenAddedInKspTask() {
Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true))
Assume.assumeFalse(useKSP2)
testRule.setupAppAsAndroidApp()
testRule.appModule.dependencies.addAll(
listOf(
Expand Down Expand Up @@ -366,6 +384,11 @@ class GradleCompilationTest {
println("HAS LIBRARY: ${'$'}{it.path}")
}
}
tasks.withType<com.google.devtools.ksp.gradle.KspAATask>().configureEach {
kspConfig.libraries.files.forEach {
println("HAS LIBRARY: ${'$'}{it.path}")
}
}
}
""".trimIndent()
)
Expand All @@ -389,6 +412,7 @@ class GradleCompilationTest {

@Test
fun changingKsp2AtRuntime() {
Assume.assumeFalse(useKSP2)
testRule.setupAppAsJvmApp()
testRule.appModule.buildFileAdditions.add(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,25 @@ import com.google.devtools.ksp.gradle.testing.KspIntegrationTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized::class)
class ProcessorClasspathConfigurationsTest(val useKSP2: Boolean) {

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}

class ProcessorClasspathConfigurationsTest {
@Rule
@JvmField
val tmpDir = TemporaryFolder()

@Rule
@JvmField
val testRule = KspIntegrationTestRule(tmpDir)
val testRule = KspIntegrationTestRule(tmpDir, useKSP2)

private val kspConfigs by lazy {
"""configurations.matching { it.name.startsWith("ksp") && !it.name.endsWith("ProcessorClasspath") }"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,26 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.io.File

class SourceSetConfigurationsTest {
@RunWith(Parameterized::class)
class SourceSetConfigurationsTest(val useKSP2: Boolean) {

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}

@Rule
@JvmField
val tmpDir = TemporaryFolder()

@Rule
@JvmField
val testRule = KspIntegrationTestRule(tmpDir)
val testRule = KspIntegrationTestRule(tmpDir, useKSP2)

@Test
fun configurationsForJvmApp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import kotlin.reflect.KClass
* Test must call [setupAppAsAndroidApp] or [setupAppAsJvmApp] before using the [runner].
*/
class KspIntegrationTestRule(
private val tmpFolder: TemporaryFolder
private val tmpFolder: TemporaryFolder,
private val useKSP2: Boolean
) : TestWatcher() {
/**
* Initialized when the test starts.
Expand Down Expand Up @@ -144,7 +145,7 @@ class KspIntegrationTestRule(
"""
android {
namespace = "com.example.kspandroidtestapp"
compileSdk = 31
compileSdk = 34
defaultConfig {
minSdk = 24
}
Expand All @@ -168,6 +169,6 @@ class KspIntegrationTestRule(

override fun starting(description: Description) {
super.starting(description)
testProject = TestProject(tmpFolder.newFolder(), testConfig)
testProject = TestProject(tmpFolder.newFolder(), testConfig, useKSP2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import java.io.File
*/
class TestProject(
val rootDir: File,
val testConfig: TestConfig
val testConfig: TestConfig,
val useKSP2: Boolean,
) {
val processorModule = TestModule(
rootDir.resolve("processor")
Expand Down Expand Up @@ -59,6 +60,7 @@ class TestProject(
val contents = """
kotlin.jvm.target.validation.mode=warning
ksp.useKSP2=$useKSP2
""".trimIndent()
rootDir.resolve("gradle.properties").appendText(contents)
}
Expand Down
Loading