[Gradle] Add test for KT-53704

CInterop Task input should be modifiable through Cinterop DSL
This commit is contained in:
Anton Lakotka
2022-08-29 14:24:09 +02:00
committed by Space
parent 490382b77f
commit 45581c11fa
@@ -0,0 +1,68 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.plugin.mpp.DefaultCInteropSettings
import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
class CInteropTaskTest : MultiplatformExtensionTest() {
@BeforeTest
override fun setup() {
super.setup()
setupDefaultProjectWithCinterop()
}
private fun setupDefaultProjectWithCinterop() {
}
@Test
fun `cinterop properties can be changed after creating`() {
fun DefaultCInteropSettings.setDummyValues(prefix: String) {
dependencyFiles = project.files("${prefix}-dependencyFile")
defFile("${prefix}-defFile")
packageName = "${prefix}-packageName"
compilerOpts += "${prefix}-compilerOpts"
linkerOpts += "${prefix}-linkerOpts"
extraOpts = listOf("${prefix}-extraOpts")
header("${prefix}-header.h")
includeDirs {
allHeaders("${prefix}-allHeaders")
headerFilterOnly("${prefix}-headerFilterOnly")
}
}
val linuxX64 = kotlin.linuxX64().apply {
compilations.getByName("main").cinterops.create("dummy") {
it.setDummyValues(prefix = "default")
}
}
// Get task to make sure it is configured
val cinteropTask = project.tasks.getByName("cinteropDummyLinuxX64") as CInteropProcess
// Change cinterop properties
val cinterop = linuxX64.compilations.getByName("main").cinterops.getByName("dummy")
cinterop.setDummyValues("updated")
project.evaluate()
assertEquals("updated-dependencyFile", cinteropTask.libraries.files.single().name)
assertEquals("updated-defFile", cinteropTask.defFile.name)
assertEquals("updated-packageName", cinteropTask.packageName)
assertEquals(listOf("default-compilerOpts", "updated-compilerOpts"), cinteropTask.compilerOpts)
assertEquals(listOf("default-linkerOpts", "updated-linkerOpts"), cinteropTask.linkerOpts)
assertEquals(listOf("updated-extraOpts"), cinteropTask.extraOpts)
assertEquals(listOf("default-header.h", "updated-header.h"), cinteropTask.headers.files.map { it.name })
assertEquals(listOf("default-allHeaders", "updated-allHeaders"), cinteropTask.allHeadersDirs.map { it.name })
assertEquals(listOf("default-headerFilterOnly", "updated-headerFilterOnly"), cinteropTask.headerFilterDirs.map { it.name })
}
}