Skip to content

Commit

Permalink
add a test that repro google#2072 by using kotlin-inject
Browse files Browse the repository at this point in the history
  • Loading branch information
asapha authored and ting-yuan committed Oct 2, 2024
1 parent 117f0b4 commit ee09be1
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.google.devtools.ksp.test

import org.gradle.testkit.runner.GradleRunner
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.io.File

@RunWith(Parameterized::class)
class KotlinInjectIT(val useKSP2: Boolean) {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("kotlin-inject", useKSP2 = useKSP2)

@Test
fun triggerException() {
val gradleRunner = GradleRunner.create().withProjectDir(project.root)
val path = "workload/src/commonMain/kotlin/AppComponent.kt"
val file = File(project.root, path)

fun setup(shouldFail: Boolean) {
project.restore(path)

// kotlin-inject will complain that Component classes can't be private
if (shouldFail) {
file
.apply {
writeText(
file.readText()
.replace("abstract class AppComponent", "private abstract class AppComponent")
)
}
}
}

// Start the kotlin daemon?
setup(shouldFail = false)
gradleRunner.withArguments("compileKotlinJvm").build()

// Make a processor fail
setup(shouldFail = true)
gradleRunner.withArguments("compileKotlinJvm").buildAndFail()

// Triggers the caching issue
setup(shouldFail = false)
gradleRunner.withArguments("compileKotlinJvm")
.buildAndFail().let { result ->
println("OUTPUT START")
println(result.output)
Assert.assertTrue(result.output.contains("id-to-file.tab] is already registered"))
}
}

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
kotlin("multiplatform") apply false
}

val testRepo: String by project
allprojects {
repositories {
maven(testRepo)
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pluginManagement {
val kotlinVersion: String by settings
val kspVersion: String by settings

val testRepo: String by settings
plugins {
id("com.google.devtools.ksp") version kspVersion apply false
kotlin("multiplatform") version kotlinVersion apply false
}
repositories {
maven(testRepo)
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/")
}
}

rootProject.name = "hmpp"

include(":workload")
include(":test-processor")
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
kotlin("multiplatform")
id("com.google.devtools.ksp")
}

version = "1.0-SNAPSHOT"

kotlin {
jvm {
withJava()
}

sourceSets {
val commonMain by getting {
dependencies {
implementation("me.tatarka.inject:kotlin-inject-runtime:0.7.2")
}
}

val jvmMain by getting {
}
}
}

dependencies {
add("kspJvm", "me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.2")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@me.tatarka.inject.annotations.Component
abstract class AppComponent {
abstract val repo: Repository

}

@me.tatarka.inject.annotations.Inject
class Repository()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class CommonMain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class JvmMain

0 comments on commit ee09be1

Please sign in to comment.