diff --git a/compiler/tests-spec/build.gradle.kts b/compiler/tests-spec/build.gradle.kts index d73103b40dc..41cd25aefaa 100644 --- a/compiler/tests-spec/build.gradle.kts +++ b/compiler/tests-spec/build.gradle.kts @@ -17,3 +17,8 @@ projectTest { } val generateTests by generator("org.jetbrains.kotlin.generators.tests.GenerateCompilerSpecTestsKt") + +val printSpecTestsStatistic by smartJavaExec { + classpath = javaPluginConvention().sourceSets.getByName("test").runtimeClasspath + main = "org.jetbrains.kotlin.spec.tasks.PrintSpecTestsStatisticKt" +} diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/TestsStatisticCollector.kt b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/TestsStatisticCollector.kt new file mode 100644 index 00000000000..3b096d118b4 --- /dev/null +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/TestsStatisticCollector.kt @@ -0,0 +1,83 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. 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.spec + +import java.io.File + +abstract class SpecTestsStatElement { + var counter = 0 + abstract val elements: MutableMap<*, out SpecTestsStatElement>? + open fun increment() { + counter++ + } +} + +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() +} + +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) } + + paragraph.elements.computeIfAbsent(testType) { SpecTestsTypeStat(paragraph) }.increment() + } + + fun collect(): Map { + val statistic = mutableMapOf() + + for (specTestArea in TestArea.values()) { + val specTestsPath = "$TEST_DATA_DIR/${specTestArea.name.toLowerCase()}" + + statistic[specTestArea] = SpecTestsAreaStat() + + File(specTestsPath).walkTopDown().forEach areaTests@{ + if (!it.isFile || it.extension != "kt") return@areaTests + + val testInfoMatcher = SpecTestValidator.testPathPattern.matcher(it.path) + + if (!testInfoMatcher.find()) 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) + } + } + + return statistic + } +} \ 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 new file mode 100644 index 00000000000..9e210bba0dc --- /dev/null +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/tasks/PrintSpecTestsStatistic.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. 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.spec.tasks + +import org.jetbrains.kotlin.spec.TestsStatisticCollector + +fun main(args: Array) { + val statistic = TestsStatisticCollector.collect() + + println("--------------------------------------------------") + println("SPEC TESTS STATISTIC") + println("--------------------------------------------------") + + for ((areaName, areaElement) in statistic) { + println("$areaName: ${areaElement.counter} tests") + + for ((sectionName, sectionElement) in areaElement.elements) { + println(" ${sectionName.toUpperCase()}: ${sectionElement.counter} 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(", ")})") + } + } + } + + println("--------------------------------------------------") +} \ No newline at end of file