[Gradle] Add test for KT-51457
^KT-51457 In Progress
This commit is contained in:
+29
@@ -9,11 +9,15 @@ package org.jetbrains.kotlin.gradle
|
|||||||
|
|
||||||
import org.gradle.api.attributes.Category
|
import org.gradle.api.attributes.Category
|
||||||
import org.gradle.api.attributes.Usage
|
import org.gradle.api.attributes.Usage
|
||||||
|
import org.gradle.kotlin.dsl.withType
|
||||||
|
import org.jetbrains.kotlin.gradle.mpp.buildProjectWithMPP
|
||||||
|
import org.jetbrains.kotlin.gradle.mpp.kotlin
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
@@ -120,4 +124,29 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test js IR compilation dependencies`() {
|
||||||
|
val project = buildProjectWithMPP {
|
||||||
|
kotlin {
|
||||||
|
js(BOTH)
|
||||||
|
targets.withType<KotlinJsTarget> {
|
||||||
|
irTarget!!.compilations.getByName("main").dependencies {
|
||||||
|
api("test:compilation-dependency")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets.getByName("jsMain").apply {
|
||||||
|
dependencies {
|
||||||
|
api("test:source-set-dependency")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with(project.evaluate()) {
|
||||||
|
assertContainsDependencies("jsApi", "test:compilation-dependency", "test:source-set-dependency")
|
||||||
|
assertContainsDependencies("jsMainApi", "test:source-set-dependency")
|
||||||
|
assertNotContainsDependencies("jsMainApi", "test:compilation-dependency")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+46
@@ -7,8 +7,12 @@ package org.jetbrains.kotlin.gradle
|
|||||||
|
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
|
import org.gradle.api.artifacts.Configuration
|
||||||
|
import org.gradle.api.artifacts.Dependency
|
||||||
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
|
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.`is`
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertTrue
|
||||||
import kotlin.test.fail
|
import kotlin.test.fail
|
||||||
|
|
||||||
fun Task.isDependsOn(other: Task): Boolean {
|
fun Task.isDependsOn(other: Task): Boolean {
|
||||||
@@ -45,3 +49,45 @@ fun Project.assertContainsNoTaskWithName(taskName: String) {
|
|||||||
fail("Expected *no* task with name $taskName in project ${this.path}")
|
fail("Expected *no* task with name $taskName in project ${this.path}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Project.assertContainsDependencies(configurationName: String, vararg dependencyNotations: Any, exhaustive: Boolean = false) {
|
||||||
|
val configuration = configurations.getByName(configurationName)
|
||||||
|
val expectedDependencies = dependencyNotations.map { dependencies.create(it) }.toMutableSet()
|
||||||
|
val unexpectedDependencies = mutableSetOf<Dependency>()
|
||||||
|
|
||||||
|
for (dependency in configuration.allDependencies) {
|
||||||
|
if (!expectedDependencies.remove(dependency)) {
|
||||||
|
unexpectedDependencies.add(dependency)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exhaustive) {
|
||||||
|
assertTrue(
|
||||||
|
unexpectedDependencies.isEmpty(),
|
||||||
|
"Unexpected dependencies '$unexpectedDependencies' found in configuration '$configurationName'"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
expectedDependencies.isEmpty(),
|
||||||
|
"Expected dependencies '$expectedDependencies' not found in configuration '$configurationName'"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Project.assertNotContainsDependencies(configurationName: String, vararg dependencyNotations: Any) {
|
||||||
|
val configuration = configurations.getByName(configurationName)
|
||||||
|
val unexpectedDependencies = dependencyNotations.map { dependencies.create(it) }.toMutableSet()
|
||||||
|
|
||||||
|
val foundUnexpectedDependencies = mutableSetOf<Dependency>()
|
||||||
|
|
||||||
|
for (dependency in configuration.allDependencies) {
|
||||||
|
if (dependency in unexpectedDependencies) {
|
||||||
|
foundUnexpectedDependencies.add(dependency)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
foundUnexpectedDependencies.isEmpty(),
|
||||||
|
"Unexpected dependencies '$foundUnexpectedDependencies' found in configuration '$configurationName'"
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user