Add a test for native dependency propagation

This commit is contained in:
Ilya Matveev
2019-09-26 14:51:03 +07:00
parent 701e92ace2
commit becdd7a5e6
22 changed files with 167 additions and 19 deletions
@@ -26,7 +26,26 @@ import org.junit.Test
import org.junit.runners.Parameterized
import java.io.File
class GradleNativeLibrariesInIDENamingTest : GradleImportingTestCase() {
abstract class TestCaseWithFakeKotlinNative : GradleImportingTestCase() {
protected fun configureProject() {
configureByFiles()
// include data dir with fake Kotlin/Native libraries
val testSuiteDataDir = testDataDirectory().parentFile
val kotlinNativeHome = testSuiteDataDir.resolve(FAKE_KOTLIN_NATIVE_HOME_RELATIVE_PATH)
kotlinNativeHome.walkTopDown()
.filter { it.isFile }
.forEach { pathInTestSuite ->
// need to put copied file one directory upper than the project root, so adding ".." to the beginning of relative path
// reason: distribution KLIBs should not be appear in IDEA indexes, so they should be located outside of the project root
val relativePathInProject = DOUBLE_DOT_PATH.resolve(pathInTestSuite.relativeTo(testSuiteDataDir))
createProjectSubFile(relativePathInProject.toString(), pathInTestSuite.readText())
}
}
}
class GradleNativeLibrariesInIDENamingTest : TestCaseWithFakeKotlinNative() {
// Test naming of Kotlin/Native libraries in projects with Gradle plugin 1.3.21+
@Test
@@ -50,23 +69,6 @@ class GradleNativeLibrariesInIDENamingTest : GradleImportingTestCase() {
override fun testDataDirName() = "nativeLibraries"
private fun configureProject() {
configureByFiles()
// include data dir with fake Kotlin/Native libraries
val testSuiteDataDir = testDataDirectory().parentFile
val kotlinNativeHome = testSuiteDataDir.resolve(FAKE_KOTLIN_NATIVE_HOME_RELATIVE_PATH)
kotlinNativeHome.walkTopDown()
.filter { it.isFile }
.forEach { pathInTestSuite ->
// need to put copied file one directory upper than the project root, so adding ".." to the beginning of relative path
// reason: distribution KLIBs should not be appear in IDEA indexes, so they should be located outside of the project root
val relativePathInProject = DOUBLE_DOT_PATH.resolve(pathInTestSuite.relativeTo(testSuiteDataDir))
createProjectSubFile(relativePathInProject.toString(), pathInTestSuite.readText())
}
}
companion object {
@Parameterized.Parameters(name = "{index}: with Gradle-{0}")
@Throws(Throwable::class)
@@ -116,7 +118,7 @@ private fun assertValidModule(module: Module, projectRoot: String) {
nativeLibraries.forEach { assertValidNativeLibrary(it, projectRoot) }
val kotlinVersion = requireNotNull(module.externalCompilerVersion) {
"External compiler version shoul not be null"
"External compiler version should not be null"
}
val expectedNativeLibraryNames = when {
@@ -0,0 +1,86 @@
/*
* Copyright 2010-2019 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.ide.konan.gradle
import com.intellij.openapi.roots.DependencyScope
import org.jetbrains.kotlin.gradle.ModuleInfo
import org.jetbrains.kotlin.gradle.checkProjectStructure
import org.jetbrains.kotlin.idea.codeInsight.gradle.GradleImportingTestCase
import org.jetbrains.kotlin.idea.configuration.externalCompilerVersion
import org.jetbrains.plugins.gradle.util.GradleConstants
import org.junit.Test
import org.junit.runners.Parameterized
class GradleNativeLibrariesPropagationTest : TestCaseWithFakeKotlinNative() {
override fun getExternalSystemConfigFileName() = GradleConstants.KOTLIN_DSL_SCRIPT_NAME
override fun testDataDirName() = "nativeLibraries"
private val testedTargets = setOf("ios_arm64", "ios_x64", "watchos_arm32", "watchos_x86")
@Test
fun testCommonIOS() {
configureProject()
importProject()
checkProjectStructure(
myProject,
projectPath,
exhaustiveModuleList = false,
exhaustiveSourceSourceRootList = false,
exhaustiveDependencyList = false,
exhaustiveTestsList = false
) {
// No platform libraries should be propagated to commonMain since we have a JVM target.
module("project_commonMain") {
noPlatformLibrary("Foundation")
noPlatformLibrary("CFNetwork")
noPlatformLibrary("WatchKit")
}
module("project_appleMain") {
// Common iOS/watchOS libraries are propagated.
hasPlatformLibrary("Foundation", "watchos_arm32")
// iOS- and watchOS-specific libraries are not propagated.
noPlatformLibrary("CFNetwork")
noPlatformLibrary("WatchKit")
}
module("project_iosMain") {
// iOS libraries are propagated.
hasPlatformLibrary("Foundation", "ios_arm64")
hasPlatformLibrary("CFNetwork", "ios_arm64")
// WatchKit is unavailable for iOS and shouldn't be propagated.
noPlatformLibrary("WatchKit")
}
}
}
private val ModuleInfo.kotlinVersion: String
get() = requireNotNull(module.externalCompilerVersion) { "External compiler version should not be null" }
private fun ModuleInfo.noPlatformLibrary(libraryName: String, targets: Collection<String> = testedTargets) {
targets.forEach { target ->
assertNoDepForModule(module.name,"Kotlin/Native $kotlinVersion - $libraryName [$target]")
}
}
private fun ModuleInfo.hasPlatformLibrary(libraryName: String, target: String) {
libraryDependency("Kotlin/Native $kotlinVersion - $libraryName [$target]", DependencyScope.PROVIDED)
noPlatformLibrary(libraryName, testedTargets - target)
}
companion object {
@Parameterized.Parameters(name = "{index}: with Gradle-{0}")
@Throws(Throwable::class)
@JvmStatic
fun data() = listOf(arrayOf("4.10.2"))
}
}