-
Notifications
You must be signed in to change notification settings - Fork 63
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
Files generated through KSP not showing #129
Comments
I am able to reproduce your issue. Strictly speaking it's "working as intended". Unfortunately, the current implementation of |
I see, so not a bug but rather that it's not designed to fully support KSP at least just yet. Other than this kind of behavior, what else do you think would be necessary to extend KSP support, and do you intend to do it in the sorter term? |
Creates extensions that run the necessary lookup for KSP generated sources in order to enable tests to match outputs. Currently this is not a functionality supported by kotlin compile testing, but should eventually be. See: tschuchortdev/kotlin-compile-testing#129
I've been able to apply the following workaround: internal val KotlinCompilation.Result.workingDir: File get() =
outputDirectory.parentFile!!
val KotlinCompilation.Result.kspGeneratedSources: List<File> get() {
val kspWorkingDir = workingDir.resolve("ksp")
val kspGeneratedDir = kspWorkingDir.resolve("sources")
val kotlinGeneratedDir = kspGeneratedDir.resolve("kotlin")
val javaGeneratedDir = kspGeneratedDir.resolve("java")
return kotlinGeneratedDir.listFilesRecursively() +
javaGeneratedDir.listFilesRecursively()
} This allows me to test for what I want without problems. Perhaps a similar strategy could be adopted for the KSP extensions? I could open a PR if you'd believe it to be applicable. Here's how I'm testing this: assertThat(result.exitCode)
.isEqualTo(KotlinCompilation.ExitCode.OK)
val generated = if (backend == "ksp") {
assertThat(result.kspGeneratedSources)
.isNotEmpty
result.kspGeneratedSources
} else {
assertThat(result.sourcesGeneratedByAnnotationProcessor)
.isNotEmpty
result.sourcesGeneratedByAnnotationProcessor
} |
@gfreivasc Can you explain, where the I could not elaborate this, so I use val KotlinCompilation.Result.kspGeneratedSources: List<File> get() {
val kspWorkingDir = workingDir.resolve("ksp")
val kspGeneratedDir = kspWorkingDir.resolve("sources")
val kotlinGeneratedDir = kspGeneratedDir.resolve("kotlin")
val javaGeneratedDir = kspGeneratedDir.resolve("java")
return kotlinGeneratedDir.walkTopDown().toList() +
javaGeneratedDir.walkTopDown()
} |
@chausknecht I created this method, or got it from somewhere Idk it's been a while. I didn't include it in this excerpt for shortness sake but you can see it in this PR |
@gfreivasc Thx for answering :-) After looking at the handcrafted method, I tend to prefer the |
I'm having a problem with compiler testing. For some reason, it does not detect KSP generated files. They have been successfully generated and it's possible to browse to them through the file system, but they're not reported on the compilation result. It looks like it's looking for kapt generated stuff instead.
Here's how I'm running it:
The variable
result
won't contain no generated sources, all the propertiesgeneratedFiles
,generatedStubFiles
,sourcesGeneratedByAnnotationProcessor
andcompiledClassAndResourceFiles
return empty for my KSP round. Everything works just fine for my KAPT rounds.The text was updated successfully, but these errors were encountered: