diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/TestsStatisticCollector.kt b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/TestsStatisticCollector.kt index 3b096d118b4..071429991a5 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/TestsStatisticCollector.kt +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/TestsStatisticCollector.kt @@ -5,79 +5,82 @@ package org.jetbrains.kotlin.spec +import org.jetbrains.kotlin.spec.validators.* import java.io.File -abstract class SpecTestsStatElement { - var counter = 0 - abstract val elements: MutableMap<*, out SpecTestsStatElement>? - open fun increment() { - counter++ +open class SpecTestsStatElement(val type: SpecTestsStatElementType) { + val elements: MutableMap = mutableMapOf() + var number = 0 + fun increment() { + number++ } } -class SpecTestsTypeStat(private val paragraph: SpecTestsStatElement) : SpecTestsStatElement() { - override val elements = null - override fun increment() { - super.increment() - paragraph.increment() - } -} - -class SpecTestsParagraphStat(private val section: SpecTestsStatElement) : SpecTestsStatElement() { - override val elements = sortedMapOf() - override fun increment() { - super.increment() - section.increment() - } -} - -class SpecTestsSectionStat(private val area: SpecTestsStatElement) : SpecTestsStatElement() { - override val elements = sortedMapOf() - override fun increment() { - super.increment() - area.increment() - } -} - -class SpecTestsAreaStat : SpecTestsStatElement() { - override val elements = sortedMapOf() +enum class SpecTestsStatElementType { + TYPE, + CATEGORY, + PARAGRAPH, + SECTION, + AREA } object TestsStatisticCollector { private const val TEST_DATA_DIR = "./testData" - private fun incrementStatCounters(testAreaStats: SpecTestsAreaStat, sectionName: String, paragraphNumber: Int, testType: String) { - val section = testAreaStats.elements.computeIfAbsent(sectionName) { SpecTestsSectionStat(testAreaStats) } - val paragraph = section.elements.computeIfAbsent(paragraphNumber) { SpecTestsParagraphStat(section) } + private fun incrementStatCounters(baseStatElement: SpecTestsStatElement, elementTypes: List>) { + var currentStatElement = baseStatElement - paragraph.elements.computeIfAbsent(testType) { SpecTestsTypeStat(paragraph) }.increment() + baseStatElement.increment() + + for ((elementType, value) in elementTypes) { + currentStatElement = currentStatElement.run { + elements.computeIfAbsent(value) { SpecTestsStatElement(elementType) }.apply { increment() } + } + } } - fun collect(): Map { - val statistic = mutableMapOf() + fun collect(testLinkedType: SpecTestLinkedType): Map { + val statistic = mutableMapOf() for (specTestArea in TestArea.values()) { - val specTestsPath = "$TEST_DATA_DIR/${specTestArea.name.toLowerCase()}" + val specTestsPath = + "$TEST_DATA_DIR/${specTestArea.name.toLowerCase()}/${AbstractSpecTestValidator.dirsByLinkedType[testLinkedType]}" - statistic[specTestArea] = SpecTestsAreaStat() + statistic[specTestArea] = SpecTestsStatElement(SpecTestsStatElementType.AREA) File(specTestsPath).walkTopDown().forEach areaTests@{ if (!it.isFile || it.extension != "kt") return@areaTests - val testInfoMatcher = SpecTestValidator.testPathPattern.matcher(it.path) + val specTestsValidator = AbstractSpecTestValidator.getInstanceByType(it) - if (!testInfoMatcher.find()) return@areaTests + try { + specTestsValidator.parseTestInfo() + } catch (e: SpecTestValidationException) { + return@areaTests + } - val sectionNumber = testInfoMatcher.group("sectionNumber") - val sectionName = testInfoMatcher.group("sectionName") - val paragraphNumber = testInfoMatcher.group("paragraphNumber").toInt() - val testType = testInfoMatcher.group("testType") - val section = "$sectionNumber $sectionName" - - incrementStatCounters(statistic[specTestArea]!!, section, paragraphNumber, testType) + incrementStatCounters( + statistic[specTestArea]!!, + when (testLinkedType) { + SpecTestLinkedType.LINKED -> getStatElementsByLinkedTests(specTestsValidator.testInfo as LinkedSpecTest) + SpecTestLinkedType.NOT_LINKED -> getStatElementsByNotLinkedTests(specTestsValidator.testInfo as NotLinkedSpecTest) + } + ) } } return statistic } + + private fun getStatElementsByLinkedTests(testInfo: LinkedSpecTest) = listOf( + SpecTestsStatElementType.SECTION to testInfo.section, + SpecTestsStatElementType.PARAGRAPH to testInfo.paragraphNumber, + SpecTestsStatElementType.TYPE to testInfo.testType.type + ) + + private fun getStatElementsByNotLinkedTests(testInfo: NotLinkedSpecTest) = + mutableListOf(SpecTestsStatElementType.SECTION to testInfo.section).apply { + addAll(testInfo.categories.map { SpecTestsStatElementType.CATEGORY to it }) + add(SpecTestsStatElementType.TYPE to testInfo.testType.type) + } } \ No newline at end of file diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/tasks/PrintSpecTestsStatistic.kt b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/tasks/PrintSpecTestsStatistic.kt index 9e210bba0dc..c84e0c8dcee 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/tasks/PrintSpecTestsStatistic.kt +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/tasks/PrintSpecTestsStatistic.kt @@ -5,32 +5,68 @@ package org.jetbrains.kotlin.spec.tasks +import org.jetbrains.kotlin.spec.SpecTestsStatElement +import org.jetbrains.kotlin.spec.SpecTestsStatElementType import org.jetbrains.kotlin.spec.TestsStatisticCollector +import org.jetbrains.kotlin.spec.validators.SpecTestLinkedType -fun main(args: Array) { - val statistic = TestsStatisticCollector.collect() +const val PRINT_BASE_INDENT = " " - println("--------------------------------------------------") +fun linkedSpecTestsPrint() { println("SPEC TESTS STATISTIC") println("--------------------------------------------------") + val statistic = TestsStatisticCollector.collect(SpecTestLinkedType.LINKED) + for ((areaName, areaElement) in statistic) { - println("$areaName: ${areaElement.counter} tests") - + println("$areaName: ${areaElement.number} tests") for ((sectionName, sectionElement) in areaElement.elements) { - println(" ${sectionName.toUpperCase()}: ${sectionElement.counter} tests") - + println(" $sectionName: ${sectionElement.number} tests") for ((paragraphName, paragraphElement) in sectionElement.elements) { val testsStatByType = mutableListOf() - - for ((typeName, typeElement) in paragraphElement.elements) { - testsStatByType.add("$typeName: ${typeElement.counter}") - } - - println(" PARAGRAPH $paragraphName: ${paragraphElement.counter} tests (${testsStatByType.joinToString(", ")})") + for ((typeName, typeElement) in paragraphElement.elements) + testsStatByType.add(" [ $typeName: ${typeElement.number} ]") + print(PRINT_BASE_INDENT.repeat(2)) + println("PARAGRAPH $paragraphName: ${paragraphElement.number} tests${testsStatByType.joinToString("")}") } } } +} +fun notLinkedSpecTestsCategoriesPrint(elements: Map, level: Int = 1) { + for ((name, element) in elements) { + if (element.type == SpecTestsStatElementType.TYPE) { + print(" [ $name: ${element.number} ]") + continue + } + + println() + print("${PRINT_BASE_INDENT.repeat(level)}$name: ${element.number} tests") + + notLinkedSpecTestsCategoriesPrint(element.elements, level + 1) + } +} + +fun notLinkedSpecTestsPrint() { + println("NOT LINKED SPEC TESTS STATISTIC") println("--------------------------------------------------") + + val statistic = TestsStatisticCollector.collect(SpecTestLinkedType.NOT_LINKED) + + for ((areaName, areaElement) in statistic) { + println("$areaName: ${areaElement.number} tests") + for ((sectionName, sectionElement) in areaElement.elements) { + print(" $sectionName: ${sectionElement.number} tests") + notLinkedSpecTestsCategoriesPrint(sectionElement.elements) + println() + } + } +} + +fun main(args: Array) { + println("==================================================") + linkedSpecTestsPrint() + println("==================================================") + notLinkedSpecTestsPrint() + println("==================================================") } \ No newline at end of file