11package com.tschuchort.compiletesting
22
33import com.tschuchort.compiletesting.KotlinCompilation.ExitCode
4+ import io.github.classgraph.ClassGraph
45import org.assertj.core.api.Assertions.assertThat
56import org.assertj.core.api.Assertions.fail
67import org.junit.Rule
78import org.junit.Test
89import org.junit.rules.TemporaryFolder
10+ import java.io.File
911import javax.annotation.processing.AbstractProcessor
1012import javax.annotation.processing.RoundEnvironment
1113import javax.lang.model.element.TypeElement
@@ -623,6 +625,28 @@ class KotlinCompilationTests {
623625 assertClassLoadable(result, " ${KotlinTestProcessor .GENERATED_PACKAGE } .${KotlinTestProcessor .GENERATED_JAVA_CLASS_NAME } " )
624626 }
625627
628+ @Test
629+ fun `detects the plugin provided for compilation via pluginClasspaths property` () {
630+ val result = defaultCompilerConfig().apply {
631+ sources = listOf (SourceFile .kotlin(" kSource.kt" , " class KSource" ))
632+ pluginClasspaths = listOf (classpathOf(" kotlin-scripting-compiler-1.3.50" ))
633+ }.compile()
634+
635+ assertThat(result.exitCode).isEqualTo(ExitCode .OK )
636+ assertThat(result.messages).contains(" provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar" )
637+ }
638+
639+ @Test
640+ fun `returns an internal error when adding a non existing plugin for compilation` () {
641+ val result = defaultCompilerConfig().apply {
642+ sources = listOf (SourceFile .kotlin(" kSource.kt" , " class KSource" ))
643+ pluginClasspaths = listOf (File (" ./non-existing-plugin.jar" ))
644+ }.compile()
645+
646+ assertThat(result.exitCode).isEqualTo(ExitCode .INTERNAL_ERROR )
647+ assertThat(result.messages).contains(" non-existing-plugin.jar not found" )
648+ }
649+
626650 private fun defaultCompilerConfig (): KotlinCompilation {
627651 return KotlinCompilation ().apply {
628652 workingDir = temporaryFolder.root
@@ -645,6 +669,16 @@ class KotlinCompilationTests {
645669 return fail<Nothing >(" Class $className could not be loaded" )
646670 }
647671 }
672+
673+ /* *
674+ * Returns the classpath for a dependency (format $name-$version).
675+ * This is necessary to know the actual location of a dependency
676+ * which has been included in test runtime (build.gradle).
677+ */
678+ private fun classpathOf (dependency : String ): File {
679+ val regex = Regex (" .*$dependency \\ .jar" )
680+ return ClassGraph ().classpathFiles.first { classpath -> classpath.name.matches(regex) }
681+ }
648682
649683 class InheritedClass {}
650684}
0 commit comments