tschuchortdev / kotlin-compile-testing

A library for testing Kotlin and Java annotation processors, compiler plugins and code generation
Mozilla Public License 2.0
658 stars 63 forks source link

Cannot compile code with `expect` type #303

Closed micHar closed 2 years ago

micHar commented 2 years ago

I'm using your fantastic library to test my multiplatform annotation processor which uses common source code and generates ios source sets. The tests look sth like this.

Now everything works fine until I add expect modifier to the test code, e. g. expect interface InterfaceGenerationExample. There is a COMPILATION_ERROR and the error is e: /var/folders/8n/.../T/.../sources/interface1.kt: (7, 1): The feature "multi platform projects" is experimental and should be enabled explicitly. Right now the tests are run in jvmTest sourceSet, but I also tried running them in commonTest source set and the result is the same. For both kapt and ksp.

Is there any way to test code with expect / actual modifiers?

micHar commented 2 years ago

I tried adding kotlin.mpp.stability.nowarn=true as per these recommendations, but I have a feeling that this library compiles in a different context than the source set of the tests. Maybe there's a way to configure its compiler with such flags?

tschuchortdev commented 2 years ago

kotlincArguments = listOf("-Xmulti-platform") works. I found this through trial and error, since the compiler flags are mostly undocumented. A KotlinCompilation.multiplatform: Boolean option will be in the next release.