How do I test the behavior of the code my plugin a...
# compiler
l
How do I test the behavior of the code my plugin alters? My plugin makes changes to the code which I can test if run the code. I (or rather AI) came up with the following configuration that seems to be working well at applying the plugin to the test files (forgoing the Gradle plugin part, which I'm fine with). This allows for some rather straight-forward tests. Is there a reason why I shouldn't be doing this, or is there a better way?
Copy code
// in compiler-plugin/build.gradle.kts
tasks.named<KotlinCompile>("compileTestKotlin") {
    pluginClasspath.from(tasks.named("jar"))
    pluginClasspath.from(configurations.runtimeClasspath)

    compilerOptions {
        freeCompilerArgs.addAll("-P", "plugin:myPlugin:myRequiredOption=true")
    }
}
y
I'd recommend the
internal-test-framework
. The setup is kinda hefty, but you can copy it from the template!
Realistically, if it works for you, it's probably fine. The passed config looks right to me But the internal-test-framework has a lot of useful testing beyond just "run code and check its results" (it has it too as "box tests"), including checking diagnostics, FIR and IR dumps, etc
l
Aha, thanks. My configuration is definitely non-standard but so far I have had no issues with it. Regarding the
internal-test-framework
, I definitely looked at it but I don't quite understand why I would want to use it. Isn't behavior the one thing I'd want to test? (As long as I don't do any checking)
..Perhaps there could be a more official way to test behavior, too?
y
I mean, another way to test behavior is to have an included build that uses your Gradle plugin and such.
internal-test-framework
lets you test behavior and diagnostics (which isn't as applicable to IR plugins). It also lets you dump the IR, which means you can check the exact code that your plugin is producing and find out when it changes. It also lets you do JS, Wasm, and Native tests, with IR dumps and such