Refactoring: change assertion signature, proper source set copying way
This commit is contained in:
committed by
Yaroslav.Chernyshev
parent
b2017a9c9c
commit
b32db1ac02
+2
-2
@@ -444,7 +444,7 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
|
|||||||
targetPlatform(jvm, js)
|
targetPlatform(jvm, js)
|
||||||
}
|
}
|
||||||
module("my-app") {
|
module("my-app") {
|
||||||
diagnostics(OrphanSourceSetsImportingDiagnostic::class.java to 1)
|
assertDiagnosticsCount<OrphanSourceSetsImportingDiagnostic>(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -536,7 +536,7 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
|
|||||||
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
|
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
|
||||||
|
|
||||||
module("my-app") {
|
module("my-app") {
|
||||||
diagnostics(OrphanSourceSetsImportingDiagnostic::class.java to 3)
|
assertDiagnosticsCount<OrphanSourceSetsImportingDiagnostic>(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
// (jvm, js, native) is highly undesirable
|
// (jvm, js, native) is highly undesirable
|
||||||
|
|||||||
@@ -277,17 +277,14 @@ class ModuleInfo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnstableApiUsage")
|
@Suppress("UnstableApiUsage")
|
||||||
fun diagnostics(vararg expectedByType: Pair<Class<out KotlinImportingDiagnostic>, Int>) {
|
internal inline fun <reified T : KotlinImportingDiagnostic> assertDiagnosticsCount(count: Int) {
|
||||||
val moduleNode = GradleUtil.findGradleModuleData(module)
|
val moduleNode = GradleUtil.findGradleModuleData(module)
|
||||||
val diagnostics = moduleNode!!.kotlinImportingDiagnosticsContainer!!
|
val diagnostics = moduleNode!!.kotlinImportingDiagnosticsContainer!!
|
||||||
expectedByType.forEach { (expectedClazz, expectedCount) ->
|
val typedDiagnostics = diagnostics.filterIsInstance<T>()
|
||||||
val typedDiagnostics = diagnostics.filterIsInstance(expectedClazz)
|
if (typedDiagnostics.size != count) {
|
||||||
if (typedDiagnostics.size != expectedCount) {
|
projectInfo.messageCollector.report(
|
||||||
val actualCount = typedDiagnostics.size
|
"Expected number of ${T::class.java.simpleName} diagnostics $count doesn't match the actual one: ${typedDiagnostics.size}"
|
||||||
projectInfo.messageCollector.report(
|
)
|
||||||
"Expected number of ${expectedClazz.simpleName} diagnostics $expectedCount doesn't match the actual one: $actualCount"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,18 @@ package org.jetbrains.kotlin.gradle
|
|||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
|
|
||||||
interface KotlinImportingDiagnostic : Serializable
|
interface KotlinImportingDiagnostic : Serializable {
|
||||||
|
fun deepCopy(cache: MutableMap<Any, Any>): KotlinImportingDiagnostic
|
||||||
|
}
|
||||||
|
|
||||||
|
typealias KotlinImportingDiagnosticsContainer = MutableSet<KotlinImportingDiagnostic>
|
||||||
|
|
||||||
interface KotlinSourceSetImportingDiagnostic : KotlinImportingDiagnostic {
|
interface KotlinSourceSetImportingDiagnostic : KotlinImportingDiagnostic {
|
||||||
val kotlinSourceSet: KotlinSourceSet
|
val kotlinSourceSet: KotlinSourceSet
|
||||||
}
|
}
|
||||||
|
|
||||||
typealias KotlinImportingDiagnosticsContainer = MutableSet<KotlinImportingDiagnostic>
|
data class OrphanSourceSetsImportingDiagnostic(override val kotlinSourceSet: KotlinSourceSet) : KotlinSourceSetImportingDiagnostic {
|
||||||
|
override fun deepCopy(cache: MutableMap<Any, Any>): OrphanSourceSetsImportingDiagnostic =
|
||||||
data class OrphanSourceSetsImportingDiagnostic(override val kotlinSourceSet: KotlinSourceSet) : KotlinSourceSetImportingDiagnostic
|
(cache[kotlinSourceSet] as? KotlinSourceSet)?.let { OrphanSourceSetsImportingDiagnostic(it) }
|
||||||
|
?: OrphanSourceSetsImportingDiagnostic(KotlinSourceSetImpl(kotlinSourceSet, cache).apply { cache[kotlinSourceSet] = this })
|
||||||
|
}
|
||||||
@@ -266,7 +266,7 @@ data class KotlinMPPGradleModelImpl(
|
|||||||
),
|
),
|
||||||
mppModel.kotlinNativeHome,
|
mppModel.kotlinNativeHome,
|
||||||
mppModel.dependencyMap.map { it.key to it.value.deepCopy(cloningCache) }.toMap(),
|
mppModel.dependencyMap.map { it.key to it.value.deepCopy(cloningCache) }.toMap(),
|
||||||
mppModel.kotlinImportingDiagnostics.toMutableSet()
|
mppModel.kotlinImportingDiagnostics.mapTo(mutableSetOf()) { it.deepCopy(cloningCache) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ internal object OrphanSourceSetImportingChecker : MultiplatformModelImportingChe
|
|||||||
model: KotlinMPPGradleModel,
|
model: KotlinMPPGradleModel,
|
||||||
reportTo: KotlinImportingDiagnosticsContainer,
|
reportTo: KotlinImportingDiagnosticsContainer,
|
||||||
context: MultiplatformModelImportingContext
|
context: MultiplatformModelImportingContext
|
||||||
) = model.sourceSets.values.filter { context.isOrphanSourceSet(it) }
|
) {
|
||||||
.map { OrphanSourceSetsImportingDiagnostic(it) }
|
model.sourceSets.values.filter { context.isOrphanSourceSet(it) }
|
||||||
.forEach { reportTo += it }
|
.mapTo(reportTo) { OrphanSourceSetsImportingDiagnostic(it) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user