Add not linked spec tests support in printSpecTestStatistic gradle task

This commit is contained in:
victor.petukhov
2018-08-28 19:28:22 +03:00
parent 8d91e5998d
commit 88d8bb84ac
2 changed files with 100 additions and 61 deletions
@@ -5,79 +5,82 @@
package org.jetbrains.kotlin.spec package org.jetbrains.kotlin.spec
import org.jetbrains.kotlin.spec.validators.*
import java.io.File import java.io.File
abstract class SpecTestsStatElement { open class SpecTestsStatElement(val type: SpecTestsStatElementType) {
var counter = 0 val elements: MutableMap<Any, SpecTestsStatElement> = mutableMapOf()
abstract val elements: MutableMap<*, out SpecTestsStatElement>? var number = 0
open fun increment() { fun increment() {
counter++ number++
} }
} }
class SpecTestsTypeStat(private val paragraph: SpecTestsStatElement) : SpecTestsStatElement() { enum class SpecTestsStatElementType {
override val elements = null TYPE,
override fun increment() { CATEGORY,
super.increment() PARAGRAPH,
paragraph.increment() SECTION,
} AREA
}
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 { object TestsStatisticCollector {
private const val TEST_DATA_DIR = "./testData" private const val TEST_DATA_DIR = "./testData"
private fun incrementStatCounters(testAreaStats: SpecTestsAreaStat, sectionName: String, paragraphNumber: Int, testType: String) { private fun incrementStatCounters(baseStatElement: SpecTestsStatElement, elementTypes: List<Pair<SpecTestsStatElementType, Any>>) {
val section = testAreaStats.elements.computeIfAbsent(sectionName) { SpecTestsSectionStat(testAreaStats) } var currentStatElement = baseStatElement
val paragraph = section.elements.computeIfAbsent(paragraphNumber) { SpecTestsParagraphStat(section) }
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<TestArea, SpecTestsAreaStat> { fun collect(testLinkedType: SpecTestLinkedType): Map<TestArea, SpecTestsStatElement> {
val statistic = mutableMapOf<TestArea, SpecTestsAreaStat>() val statistic = mutableMapOf<TestArea, SpecTestsStatElement>()
for (specTestArea in TestArea.values()) { 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@{ File(specTestsPath).walkTopDown().forEach areaTests@{
if (!it.isFile || it.extension != "kt") return@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") incrementStatCounters(
val sectionName = testInfoMatcher.group("sectionName") statistic[specTestArea]!!,
val paragraphNumber = testInfoMatcher.group("paragraphNumber").toInt() when (testLinkedType) {
val testType = testInfoMatcher.group("testType") SpecTestLinkedType.LINKED -> getStatElementsByLinkedTests(specTestsValidator.testInfo as LinkedSpecTest)
val section = "$sectionNumber $sectionName" SpecTestLinkedType.NOT_LINKED -> getStatElementsByNotLinkedTests(specTestsValidator.testInfo as NotLinkedSpecTest)
}
incrementStatCounters(statistic[specTestArea]!!, section, paragraphNumber, testType) )
} }
} }
return statistic 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)
}
} }
@@ -5,32 +5,68 @@
package org.jetbrains.kotlin.spec.tasks 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.TestsStatisticCollector
import org.jetbrains.kotlin.spec.validators.SpecTestLinkedType
fun main(args: Array<String>) { const val PRINT_BASE_INDENT = " "
val statistic = TestsStatisticCollector.collect()
println("--------------------------------------------------") fun linkedSpecTestsPrint() {
println("SPEC TESTS STATISTIC") println("SPEC TESTS STATISTIC")
println("--------------------------------------------------") println("--------------------------------------------------")
val statistic = TestsStatisticCollector.collect(SpecTestLinkedType.LINKED)
for ((areaName, areaElement) in statistic) { for ((areaName, areaElement) in statistic) {
println("$areaName: ${areaElement.counter} tests") println("$areaName: ${areaElement.number} tests")
for ((sectionName, sectionElement) in areaElement.elements) { for ((sectionName, sectionElement) in areaElement.elements) {
println(" ${sectionName.toUpperCase()}: ${sectionElement.counter} tests") println(" $sectionName: ${sectionElement.number} tests")
for ((paragraphName, paragraphElement) in sectionElement.elements) { for ((paragraphName, paragraphElement) in sectionElement.elements) {
val testsStatByType = mutableListOf<String>() val testsStatByType = mutableListOf<String>()
for ((typeName, typeElement) in paragraphElement.elements)
for ((typeName, typeElement) in paragraphElement.elements) { testsStatByType.add(" [ $typeName: ${typeElement.number} ]")
testsStatByType.add("$typeName: ${typeElement.counter}") print(PRINT_BASE_INDENT.repeat(2))
} println("PARAGRAPH $paragraphName: ${paragraphElement.number} tests${testsStatByType.joinToString("")}")
println(" PARAGRAPH $paragraphName: ${paragraphElement.counter} tests (${testsStatByType.joinToString(", ")})")
} }
} }
} }
}
fun notLinkedSpecTestsCategoriesPrint(elements: Map<Any, SpecTestsStatElement>, 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("--------------------------------------------------") 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<String>) {
println("==================================================")
linkedSpecTestsPrint()
println("==================================================")
notLinkedSpecTestsPrint()
println("==================================================")
} }