Add gradle task to print spec tests statistic by spec sections
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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<String, SpecTestsTypeStat>()
|
||||
override fun increment() {
|
||||
super.increment()
|
||||
section.increment()
|
||||
}
|
||||
}
|
||||
|
||||
class SpecTestsSectionStat(private val area: SpecTestsStatElement) : SpecTestsStatElement() {
|
||||
override val elements = sortedMapOf<Int, SpecTestsParagraphStat>()
|
||||
override fun increment() {
|
||||
super.increment()
|
||||
area.increment()
|
||||
}
|
||||
}
|
||||
|
||||
class SpecTestsAreaStat : SpecTestsStatElement() {
|
||||
override val elements = sortedMapOf<String, SpecTestsSectionStat>()
|
||||
}
|
||||
|
||||
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<TestArea, SpecTestsAreaStat> {
|
||||
val statistic = mutableMapOf<TestArea, SpecTestsAreaStat>()
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -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<String>) {
|
||||
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<String>()
|
||||
|
||||
for ((typeName, typeElement) in paragraphElement.elements) {
|
||||
testsStatByType.add("$typeName: ${typeElement.counter}")
|
||||
}
|
||||
|
||||
println(" PARAGRAPH $paragraphName: ${paragraphElement.counter} tests (${testsStatByType.joinToString(", ")})")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println("--------------------------------------------------")
|
||||
}
|
||||
Reference in New Issue
Block a user