[Commonizer] Implement SingleTargetPropagationTest to cover KT-46248

^KT-46248
This commit is contained in:
sebastian.sellmair
2021-04-22 15:11:30 +02:00
committed by Space
parent 965e328766
commit 7c1520a424
2 changed files with 34 additions and 2 deletions

View File

@@ -160,8 +160,8 @@ abstract class AbstractInlineSourcesCommonizationTest : KtInlineSourceCommonizer
if (dependencies.isEmpty()) null
else MockModulesProvider.create(dependencies)
},
targetProviders = TargetDependent(targets.map { it.target }) { commonizerTarget ->
val target = targets.single { it.target == commonizerTarget }
targetProviders = TargetDependent(outputTarget.allLeaves()) { commonizerTarget ->
val target = targets.singleOrNull { it.target == commonizerTarget } ?: return@TargetDependent null
TargetProvider(
target = commonizerTarget,
modulesProvider = MockModulesProvider.create(target.modules.map { createModuleDescriptor(it) })

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2010-2021 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.commonizer.hierarchical
import org.jetbrains.kotlin.commonizer.AbstractInlineSourcesCommonizationTest
import org.jetbrains.kotlin.commonizer.assertCommonized
import org.junit.Test
/**
* Related https://youtrack.jetbrains.com/issue/KT-46248
*/
class SingleTargetPropagationTest : AbstractInlineSourcesCommonizationTest() {
/**
* Following the simple design principle:
* Absent/Unsupported targets shall result in the same output as a request only mentioning supported targets
*/
@Test
fun `test single native target in hierarchy`() {
val result = commonize {
outputTarget("((a, b), (c, d))")
simpleSingleSourceTarget("a", """class A""")
}
result.assertCommonized("a", "class A")
result.assertCommonized("(a,b)", "expect class A expect constructor()")
result.assertCommonized("((a, b), (c, d))", "expect class A expect constructor()")
}
}