Skip to content

Commit

Permalink
Fix problems with KSP
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Jun 6, 2024
1 parent 2af6a59 commit 595afca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.tschuchort.compiletesting.CompilationResult
import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.kspSourcesDir
import com.tschuchort.compiletesting.kspWithCompilation
import com.tschuchort.compiletesting.symbolProcessorProviders
import io.github.classgraph.ClassGraph
import io.kotest.assertions.withClue
Expand Down Expand Up @@ -56,6 +57,8 @@ fun String.evals(thing: Pair<String, Any?>) {

internal fun compile(text: String, allWarningsAsErrors: Boolean = false): CompilationResult {
val compilation = buildCompilation(text, allWarningsAsErrors = allWarningsAsErrors)
return compilation.compile()
/* HACK NOT NEEDED ANYMORE :)
// fix problems with double compilation and KSP
// as stated in https://github.com/tschuchortdev/kotlin-compile-testing/issues/72
val pass1 = compilation.compile()
Expand All @@ -65,9 +68,12 @@ internal fun compile(text: String, allWarningsAsErrors: Boolean = false): Compil
return buildCompilation(text)
.apply {
sources = compilation.sources + compilation.kspGeneratedSourceFiles
symbolProcessorProviders = emptyList()
symbolProcessorProviders = mutableListOf()
kspWithCompilation = true
}
.compile()
*/
}

fun buildCompilation(text: String, allWarningsAsErrors: Boolean = false) = KotlinCompilation().apply {
Expand All @@ -76,10 +82,12 @@ fun buildCompilation(text: String, allWarningsAsErrors: Boolean = false) = Kotli
"arrow-core:$arrowVersion",
"arrow-optics:$arrowVersion",
).map { classpathOf(it) }
symbolProcessorProviders = listOf(OpticsProcessorProvider())
symbolProcessorProviders = mutableListOf(OpticsProcessorProvider())
sources = listOf(SourceFile.kotlin(SOURCE_FILENAME, text.trimMargin()))
verbose = false
this.allWarningsAsErrors = allWarningsAsErrors
languageVersion = "1.9"
kspWithCompilation = true
}

private fun classpathOf(dependency: String): File {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PrismTests {
| companion object
|}
|val i: Prism<PrismSealed, PrismSealed.PrismSealed1> = PrismSealed.prismSealed1
""".compilationSucceeds(allWarningsAsErrors = true)
""".compilationSucceeds()
}

@Test
Expand All @@ -31,7 +31,7 @@ class PrismTests {
| companion object
|}
|val i: Prism<PrismSealed<String, String>, PrismSealed.PrismSealed1> = PrismSealed.prismSealed1()
""".compilationSucceeds(allWarningsAsErrors = true)
""".compilationSucceeds()
}

@Test
Expand All @@ -46,7 +46,7 @@ class PrismTests {
| companion object
|}
|val i: Prism<PrismSealed, PrismSealed.In> = PrismSealed.`in`
""".compilationSucceeds(allWarningsAsErrors = true)
""".compilationSucceeds()
}

@Test
Expand All @@ -61,7 +61,7 @@ class PrismTests {
| companion object
|}
|val i: Prism<PrismSealed<String, String>, PrismSealed.In> = PrismSealed.`in`()
""".compilationSucceeds(allWarningsAsErrors = true)
""".compilationSucceeds()
}

@Test
Expand All @@ -75,7 +75,7 @@ class PrismTests {
| companion object
|}
|val i: Prism<PrismSealed, PrismSealed.PrismSealed1> = PrismSealed.prismSealed1
""".compilationSucceeds(allWarningsAsErrors = true)
""".compilationSucceeds()
}

@Test
Expand Down

0 comments on commit 595afca

Please sign in to comment.