[Gradle] Implement test - multiplatform - with K2 - source filter on compile task is respected
KT-58466
This commit is contained in:
committed by
Space Team
parent
86b54fadcc
commit
543ab6c390
+53
-2
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.util.assertNotNull
|
||||
import org.jetbrains.kotlin.gradle.util.buildProjectWithJvm
|
||||
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
|
||||
import org.jetbrains.kotlin.gradle.util.main
|
||||
import kotlin.reflect.full.findAnnotation
|
||||
import kotlin.test.*
|
||||
|
||||
@@ -103,8 +104,58 @@ class KotlinCompileArgumentsTest {
|
||||
val jvmMainCompileTask = jvmMainCompilation.compileTaskProvider.get() as KotlinCompile
|
||||
val arguments = jvmMainCompileTask.createCompilerArguments(lenient)
|
||||
|
||||
arguments.assertNotNull(CommonCompilerArguments::fragments).let { fragments ->
|
||||
assertEquals(setOf("commonMain", "jvmMain"), fragments.toSet())
|
||||
assertEquals(
|
||||
setOf("commonMain", "jvmMain"),
|
||||
arguments.assertNotNull(CommonCompilerArguments::fragments).toSet()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test - multiplatform - with K2 - source filter on compile task is respected`() {
|
||||
val project = buildProjectWithMPP()
|
||||
val kotlin = project.multiplatformExtension
|
||||
kotlin.jvm()
|
||||
val compilation = kotlin.jvm().compilations.main
|
||||
compilation.compilerOptions.options.languageVersion.set(KotlinVersion.KOTLIN_2_0)
|
||||
val compileTask = compilation.compileTaskProvider.get() as KotlinCompile
|
||||
|
||||
/*
|
||||
Create Source Files
|
||||
*/
|
||||
val aKt = project.file("src/jvmMain/kotlin/A.kt")
|
||||
val bKt = project.file("src/jvmMain/kotlin/B.kt")
|
||||
val cTxt = project.file("src/jvmMain/kotlin/C.txt")
|
||||
|
||||
listOf(aKt, bKt, cTxt).forEach { file ->
|
||||
file.parentFile.mkdirs()
|
||||
file.writeText("Stub")
|
||||
}
|
||||
|
||||
/* Expect cTxt being filtered by default by the compile task */
|
||||
assertEquals(
|
||||
setOf(
|
||||
"jvmMain:${aKt.absolutePath}",
|
||||
"jvmMain:${bKt.absolutePath}",
|
||||
),
|
||||
compileTask.createCompilerArguments(lenient).fragmentSources.orEmpty().toSet()
|
||||
)
|
||||
|
||||
/* Explicitly include the txt file */
|
||||
compileTask.include("**.txt")
|
||||
assertEquals(
|
||||
setOf(
|
||||
"jvmMain:${aKt.absolutePath}",
|
||||
"jvmMain:${bKt.absolutePath}",
|
||||
"jvmMain:${cTxt.absolutePath}",
|
||||
),
|
||||
compileTask.createCompilerArguments(lenient).fragmentSources.orEmpty().toSet()
|
||||
)
|
||||
|
||||
/* Exclude B.kt and C.txt explicitly */
|
||||
compileTask.exclude { it.file in setOf(bKt, cTxt) }
|
||||
assertEquals(
|
||||
setOf("jvmMain:${aKt.absolutePath}"),
|
||||
compileTask.createCompilerArguments(lenient).fragmentSources.orEmpty().toSet()
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user