forked from google/ksp
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a test that repro google#2072 by using kotlin-inject
- Loading branch information
Showing
7 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
integration-tests/src/test/kotlin/com/google/devtools/ksp/test/KotlinInjectIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
integration-tests/src/test/resources/kotlin-inject/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/") | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
integration-tests/src/test/resources/kotlin-inject/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
27 changes: 27 additions & 0 deletions
27
integration-tests/src/test/resources/kotlin-inject/workload/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
8 changes: 8 additions & 0 deletions
8
...ion-tests/src/test/resources/kotlin-inject/workload/src/commonMain/kotlin/AppComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
1 change: 1 addition & 0 deletions
1
...ation-tests/src/test/resources/kotlin-inject/workload/src/commonMain/kotlin/CommonMain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class CommonMain |
1 change: 1 addition & 0 deletions
1
integration-tests/src/test/resources/kotlin-inject/workload/src/jvmMain/kotlin/JvmMain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class JvmMain |