Skip to content

Instantly share code, notes, and snippets.

@bnorm
Created November 21, 2020 19:39
Show Gist options
  • Save bnorm/3d0011b8ef0610f4849b82e252384647 to your computer and use it in GitHub Desktop.
Save bnorm/3d0011b8ef0610f4849b82e252384647 to your computer and use it in GitHub Desktop.
class IrPluginTest {
@Test
fun `IR plugin success`() {
val result = compile(
sourceFile = SourceFile.kotlin(
"main.kt", """
fun main() {
println(debug())
}
fun debug() = "Hello, World!"
"""
)
)
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode)
}
}
fun compile(
sourceFiles: List<SourceFile>,
plugin: ComponentRegistrar = TemplateComponentRegistrar(),
): KotlinCompilation.Result {
return KotlinCompilation().apply {
sources = sourceFiles
useIR = true
compilerPlugins = listOf(plugin)
inheritClassPath = true
}.compile()
}
fun compile(
sourceFile: SourceFile,
plugin: ComponentRegistrar = TemplateComponentRegistrar(),
): KotlinCompilation.Result {
return compile(listOf(sourceFile), plugin)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment