From 7981cf8368b98497745c1e0bf81bb7a721f65b8b Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Wed, 1 Dec 2021 20:55:28 +0300 Subject: [PATCH] [Native][tests] Remove unnecesary common prefix in dynamic test names --- .../AbstractNativeBlackBoxTest.kt | 20 ++++++++++--------- .../blackboxtest/support/TestRunProvider.kt | 4 +++- .../blackboxtest/support/util/TreeNode.kt | 16 ++++++++++----- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeBlackBoxTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeBlackBoxTest.kt index 7c7b5ae1c60..207bcb48218 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeBlackBoxTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeBlackBoxTest.kt @@ -68,22 +68,24 @@ abstract class AbstractNativeBlackBoxTest { * This function should be called from a method annotated with [org.junit.jupiter.api.TestFactory]. */ internal fun dynamicTestCase(testCaseId: TestCaseId): Collection { - val rootTestRunNode = testRunProvider.getTestRuns(testCaseId) - return buildJUnitDynamicNodes(rootTestRunNode) + val testRunNodes = testRunProvider.getTestRuns(testCaseId) + return buildJUnitDynamicNodes(testRunNodes) } // We have to use planar (one-level) tree of JUnit5 dynamic nodes, because Gradle does not support yet rendering // tests with arbitrary nesting level in their test reports. As long as these reports are consumed by various CI (such as TeamCity) // we have almost no chance to display test results in CI properly. - private fun buildJUnitDynamicNodes(testRunNode: TreeNode): Collection = + private fun buildJUnitDynamicNodes(testRunNodes: Collection>): Collection = // This is the proper implementation that should be used instead: // buildList { -// testRunNode.items.mapTo(this) { testRun -> -// dynamicTest(testRun.displayName) { runTest(testRun) } -// } +// testRunNodes.forEach { testRunNode -> +// testRunNode.items.mapTo(this) { testRun -> +// dynamicTest(testRun.displayName) { runTest(testRun) } +// } // -// testRunNode.children.mapTo(this) { childTestRunNode -> -// dynamicContainer(childTestRunNode.packageSegment, buildJUnitDynamicNodes(childTestRunNode)) +// testRunNode.children.mapTo(this) { childTestRunNode -> +// dynamicContainer(childTestRunNode.packageSegment, buildJUnitDynamicNodes(childTestRunNode)) +// } // } // } buildList { @@ -97,7 +99,7 @@ abstract class AbstractNativeBlackBoxTest { children.forEach { it.processItems(ownPackageSegment) } } - testRunNode.processItems("") + testRunNodes.forEach { testRunNode -> testRunNode.processItems("") } } private fun performTestRun(testRun: TestRun) { diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestRunProvider.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestRunProvider.kt index 9cb97636dba..ad2ceb1b819 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestRunProvider.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestRunProvider.kt @@ -98,7 +98,9 @@ internal class TestRunProvider( * } * } */ - fun getTestRuns(testCaseId: TestCaseId): TreeNode = withTestExecutable(testCaseId) { testCase, executable, cacheKey -> + fun getTestRuns( + testCaseId: TestCaseId + ): Collection> = withTestExecutable(testCaseId) { testCase, executable, cacheKey -> fun createTestRun(testRunName: String, testFunction: TestFunction?): TestRun { val runParameters = getRunParameters(testCase, testFunction) return TestRun(testRunName, executable, runParameters, testCase.id) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TreeNode.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TreeNode.kt index bd1aa07a440..a197640af00 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TreeNode.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TreeNode.kt @@ -15,15 +15,15 @@ internal interface TreeNode { companion object { fun oneLevel(vararg items: T) = oneLevel(listOf(*items)) - fun oneLevel(items: Iterable) = object : TreeNode { + fun oneLevel(items: Iterable): List> = listOf(object : TreeNode { override val packageSegment get() = "" override val items = items.toList() override val children get() = emptyList>() - } + }) } } -internal fun Collection.buildTree(extractPackageName: (T) -> PackageFQN, transform: (T) -> R): TreeNode { +internal fun Collection.buildTree(extractPackageName: (T) -> PackageFQN, transform: (T) -> R): Collection> { val groupedItems: Map> = groupBy(extractPackageName).mapValues { (_, items) -> items.map(transform) } // Fast pass. @@ -44,8 +44,14 @@ internal fun Collection.buildTree(extractPackageName: (T) -> PackageFQ node.items += items } - // Skip meaningless nodes starting from the root. Compress the resulting tree. - return root.skipMeaninglessNodes().apply { compress() } + // Skip meaningless nodes starting from the root. + val meaningfulNode = root.skipMeaninglessNodes().apply { compress() } + + // Compress the resulting tree. + return if (meaningfulNode.items.isNotEmpty() || meaningfulNode.childrenMap.isEmpty()) + listOf(meaningfulNode) + else + meaningfulNode.childrenMap.values } private class TreeBuilder(override var packageSegment: String) : TreeNode {