in 2.3.x it seems it's no longer safe to call `tes...
# compiler
z
in 2.3.x it seems it's no longer safe to call
testServices.sourceFileProvider.getContentOfSourceFile(testFile)
in
AdditionalSourceProvider.produceAdditionalFiles()
because it calls through to
testServices.moduleStructure
under the hood, and seems that's no longer available at that time. I can just call
testFile.originalContent
directly but that skips other preprocessors. Worth filing an issue or is there a different API we should be using for this?
Copy code
java.lang.IllegalStateException: No 'org.jetbrains.kotlin.test.services.TestModuleStructure'(19) in array owner: org.jetbrains.kotlin.test.services.TestServices@7af2910e
	at org.jetbrains.kotlin.util.ArrayMapAccessor.getValue(ArrayMapOwner.kt:53)
	at org.jetbrains.kotlin.test.services.TestModuleStructureKt.getModuleStructure(TestModuleStructure.kt:22)
	at org.jetbrains.kotlin.test.preprocessors.JvmInlineSourceTransformer.process(JvmInlineSourceTransformer.kt:42)
	at org.jetbrains.kotlin.test.services.SourceFileProviderImpl.getContentOfSourceFile(SourceFileProvider.kt:63)
	at dev.zacsweers.metro.compiler.interop.Ksp2AdditionalSourceProvider.produceAdditionalFiles(Ksp2AdditionalSourceProvider.kt:55)
d
seems that's no longer available at that time
It was always illegal at this time. The thing is that
JvmInlineSourceTransformer
is new service which I introduced just recently.
JvmInlineSourceTransformer
is very kotlin project specific and the best solution is just don't register it for tests in plugins. But to understand what is the best way to do it I need to know how exactly you setup your tests, what is the base classes for your test runners? Is it
AbstractKotlinCompilerTest
or you extend more specific runners from the test framework?
z
Tbh I’m not sure exactly how this part wires in to kotlin test framework APIs, it was contributed by @bnorm to support KSP2 source gen before compilation :)
I can try to write up more details tomorrow if need be
d
You can point me to your test class, which is used as a base for
...Generated
tests.
b
I set up the KSP integration as an
AdditionalSourceProvider
originally, as I thought it made the most sense. Thinking it might need to be a separate step now? All 4 of the base tests in the project use it, but not every test needs it. I believe they all extend
AbstractKotlinCompilerTest
in some way. Here's the diagnostic base test and where the KSP integration gets registered.
d
The easiest and fastest way to fix this problem would be the following: • change
MetroDirectives.enableDaggerKsp(module.directives)
check to
MetroDirectives.enableDaggerKsp(globalDirectives)
• extract tests with
ENABLE_DAGGER_KSP
into a separate directory(es) • remove the directive
// ENABLE_DAGGER_KSP
from test data files • register it in the testrunner itself
Copy code
forTestsMatching("path/to/these/files/*") {
    defaultDirectives {
        +ENABLE_DAGGER_KSP
    }
}
👀 1