Refactoring: change assertion signature, proper source set copying way

This commit is contained in:
yaroslav.chernyshev
2021-02-03 11:34:33 +03:00
committed by Yaroslav.Chernyshev
parent b2017a9c9c
commit b32db1ac02
5 changed files with 23 additions and 19 deletions
@@ -444,7 +444,7 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
targetPlatform(jvm, js)
}
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) {
module("my-app") {
diagnostics(OrphanSourceSetsImportingDiagnostic::class.java to 3)
assertDiagnosticsCount<OrphanSourceSetsImportingDiagnostic>(3)
}
// (jvm, js, native) is highly undesirable
@@ -277,17 +277,14 @@ class ModuleInfo(
}
@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 diagnostics = moduleNode!!.kotlinImportingDiagnosticsContainer!!
expectedByType.forEach { (expectedClazz, expectedCount) ->
val typedDiagnostics = diagnostics.filterIsInstance(expectedClazz)
if (typedDiagnostics.size != expectedCount) {
val actualCount = typedDiagnostics.size
projectInfo.messageCollector.report(
"Expected number of ${expectedClazz.simpleName} diagnostics $expectedCount doesn't match the actual one: $actualCount"
)
}
val typedDiagnostics = diagnostics.filterIsInstance<T>()
if (typedDiagnostics.size != count) {
projectInfo.messageCollector.report(
"Expected number of ${T::class.java.simpleName} diagnostics $count doesn't match the actual one: ${typedDiagnostics.size}"
)
}
}