kotlin-compile-testing: compilation errors are hidden when KSP is used
Not sure what happened yet but between 20201106 and 20201023 versions of KSP, it started having a side effect where no kotlin compilation error is reported.
@Test
fun badCodeFailsCompilation() {
val src = SourceFile.kotlin("Foo.kt", """
class Foo {
val x:NonExistingType = TODO()
}
""".trimIndent())
val instance = mock<SymbolProcessor>()
val result = KotlinCompilation().apply {
sources = listOf(src)
symbolProcessors = listOf(instance)
}.compile()
assertThat(result.exitCode).isEqualTo(ExitCode.COMPILATION_ERROR)
}
Removing symbolProcessors = listOf(instance) line fixes the test.
Recently, KSP re-implemented its plugin so this might be related to https://github.com/google/ksp/commit/328706164554f3036dba08333cdac6d52e8d0ab3.
Notice that the error is not from KSP processor, it simply drops the error in kotlin source code.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 2
- Comments: 27 (24 by maintainers)
Hi @yigit, @tschuchortdev. I’m interested in this rewrite. I think with the introduction of ksp the separation of kapt from the core components makes a lot of sense. What’s the current state of things? Is anyone working on this? Can I help?
@tschuchortdev @yigit Cannot say whether it is helpful, but here is the (extremely suboptimal) code for the approach @mvdbos mentioned
Sorry, I took steps can edit KotlinCompile as they can add sources, which would have an impact on later steps / compile calls. Restricting them to report such extra changes in a well defined interface avoids these problems (kind of scopes it).
I’m not sure if we have that case but we can basically add it to the IntermediateResult as a parameter too then core compilation would merge them.
I’ll try to prototype the thing i’ve mentioned above. (separate user defined configuration/data from intermediate ones). I’ll ignore the current API of KotlinCompile (I think i got too attached to it). I should be possible to keep that api based on the new infra, at the least. I’ll try to prototype something and get back to you.