Fix OptionalExpectation in Gradle plugin (#2259)

This commit is contained in:
Ilya Matveev
2018-10-24 11:58:29 +07:00
committed by GitHub
parent ec9b057e5a
commit b32a73bbf1
5 changed files with 51 additions and 3 deletions
@@ -40,6 +40,12 @@ interface KotlinNativeBinary : ComponentWithDependencies, BuildableComponent, Co
/** Returns the source files of this binary. */
val sources: FileCollection
/**
* Returns common sources used to build this binary
* (both common for all native targets and avalable via expectedBy relation).
*/
val commonSources: FileCollection
/**
* Konan target the library is built for
*/
@@ -94,6 +94,9 @@ abstract class AbstractKotlinNativeBinary(
override val sources: FileCollection
get() = sourceSet.getAllSources(konanTarget)
override val commonSources: FileCollection
get() = sourceSet.getCommonMultiplatformSources() + sourceSet.getCommonNativeSources()
private val dependencies = objects.newInstance<DefaultComponentDependencies>(
DefaultComponentDependencies::class.java,
name + "Implementation"
@@ -60,6 +60,11 @@ open class KotlinNativeTestExecutableImpl @Inject constructor(
override val sources: FileCollection
get() = super.sources + mainSources.getAllSources(konanTarget)
override val commonSources: FileCollection
get() = super.commonSources +
mainSources.getCommonNativeSources() +
mainSources.getCommonMultiplatformSources()
override val outputRootName: String = "test-exe"
override val additionalCompilerOptions: Collection<String>
@@ -49,9 +49,7 @@ open class KotlinNativeCompile @Inject constructor(internal val binary: Abstract
override fun getSource(): FileTree = sources.asFileTree
private val commonSources: FileCollection
get() = with(binary.sourceSet) {
getCommonMultiplatformSources() + getCommonNativeSources()
}
get() = binary.commonSources
val libraries: Configuration
@InputFiles get() = binary.klibs
@@ -1036,4 +1036,40 @@ class ExperimentalPluginTests {
"Project property 'konan.home' is deprecated. Use 'org.jetbrains.kotlin.native.home' instead."
))
}
@Test
fun `Plugin should support OptionalExpectation`() {
val project = KonanProject.createEmpty(projectDirectory).apply {
buildFile.writeText("""
plugins {
id 'kotlin-native'
}
components.main.targets = ['host']
components.test.targets = ['host']
""".trimIndent())
generateSrcFile("main.kt", """
import kotlin.jvm.*
class A {
@JvmField
val a = "A.a"
}
fun foo() {
println(A().a)
}
""".trimIndent())
generateSrcFile(listOf("src", "test", "kotlin"), "test.kt", """
import kotlin.test.*
@Test
fun test() {
foo()
}
""".trimIndent())
}
val result = project.createRunner().withArguments("build").build()
assertTrue(result.output.contains("A.a"))
}
}