[Spec tests] Generate sections json map

This commit is contained in:
anastasiia.spaseeva
2020-09-08 16:47:04 +03:00
parent d02432cf93
commit 31de584d14
8 changed files with 275 additions and 5 deletions
@@ -0,0 +1,65 @@
{
"type-system": [
"type-kinds/built-in-types/kotlin.nothing",
"introduction-1"
],
"statements": [
"assignments/operator-assignments",
"assignments/simple-assignments",
"loop-statements/while-loop-statement",
"loop-statements/do-while-loop-statement",
"assignments"
],
"expressions": [
"not-null-assertion-expression",
"comparison-expressions",
"indexing-expressions",
"when-expression",
"constant-literals/real-literals",
"constant-literals/integer-literals/decimal-integer-literals",
"constant-literals/integer-literals/binary-integer-literals",
"constant-literals/integer-literals/hexadecimal-integer-literals",
"constant-literals/boolean-literals",
"constant-literals/character-literals",
"constant-literals/the-types-for-integer-literals",
"logical-disjunction-expression",
"logical-conjunction-expression",
"postfix-operator-expressions/postfix-increment-expression",
"prefix-expressions/prefix-increment-expression",
"postfix-operator-expressions/postfix-decrement-expression",
"prefix-expressions/prefix-decrement-expression",
"additive-expression",
"type-checking-and-containment-checking-expressions/type-checking-expression",
"type-checking-and-containment-checking-expressions/containment-checking-expression",
"try-expression",
"elvis-operator-expression",
"multiplicative-expression",
"range-expression",
"equality-expressions/value-equality-expressions",
"equality-expressions/reference-equality-expressions",
"jump-expressions/break-expression",
"jump-expressions/return-expressions",
"jump-expressions/continue-expression",
"conditional-expression",
"built-in-types-and-their-semantics/kotlin.nothing-1",
"built-in-types-and-their-semantics/kotlin.unit",
"cast-expression",
"prefix-expressions/unary-minus-expression",
"prefix-expressions/logical-not-expression",
"prefix-expressions/unary-plus-expression"
],
"overloadable-operators": [
""
],
"exceptions": [
"catching-exceptions"
],
"overload-resolution": [
"choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection",
"callables-and-invoke-convention",
"building-the-overload-candidate-set-ocs/infix-function-call",
"building-the-overload-candidate-set-ocs/operator-call",
"building-the-overload-candidate-set-ocs/call-with-an-explicit-receiver",
"receivers"
]
}
@@ -0,0 +1,111 @@
{
"type-inference": [
"smart-casts/smart-cast-sink-stability",
"local-type-inference",
"smart-casts/smart-cast-types"
],
"overload-resolution": [
"building-the-overload-candidate-set-ocs/operator-call",
"building-the-overload-candidate-set-ocs/call-with-an-explicit-receiver",
"choosing-the-most-specific-candidate-from-the-overload-candidate-set/rationale-1",
"choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection",
"callables-and-invoke-convention",
"building-the-overload-candidate-set-ocs/call-with-trailing-lambda-expressions",
"building-the-overload-candidate-set-ocs/call-with-named-parameters",
"building-the-overload-candidate-set-ocs/call-with-specified-type-parameters",
"building-the-overload-candidate-set-ocs/infix-function-call",
"determining-function-applicability-for-a-specific-call/description",
"building-the-overload-candidate-set-ocs/call-without-an-explicit-receiver",
"c-level-partition",
"receivers",
"building-the-overload-candidate-set-ocs/call-with-an-explicit-receiver/call-with-an-explicit-type-receiver",
"resolving-callable-references/bidirectional-resolution-for-callable-calls",
"resolving-callable-references/resolving-callable-references-not-used-as-arguments-to-a-call",
"resolving-callable-references",
"determining-function-applicability-for-a-specific-call/rationale"
],
"type-system": [
"type-kinds/built-in-types/kotlin.any",
"introduction-1",
"type-kinds/built-in-types/kotlin.nothing",
"subtyping/subtyping-rules",
"subtyping",
"subtyping/subtyping-for-intersection-types",
"type-contexts-and-scopes/inner-and-nested-type-contexts",
"subtyping/subtyping-for-nullable-types",
"type-kinds/type-parameters"
],
"declarations": [
"classifier-declaration/class-declaration/abstract-classes",
"classifier-declaration/class-declaration/constructor-declaration",
"classifier-declaration/class-declaration",
"classifier-declaration/data-class-declaration",
"classifier-declaration/class-declaration/nested-and-inner-classifiers",
"property-declaration/local-property-declaration",
"property-declaration/property-initialization",
"type-alias",
"classifier-declaration/classifier-initialization",
"function-declaration"
],
"inheritance": [
"overriding"
],
"statements": [
"assignments/operator-assignments",
"assignments",
"assignments/simple-assignments",
"loop-statements/while-loop-statement",
"loop-statements/do-while-loop-statement"
],
"expressions": [
"not-null-assertion-expression",
"comparison-expressions",
"when-expression",
"when-expression/exhaustive-when-expressions",
"constant-literals/real-literals",
"constant-literals/integer-literals/decimal-integer-literals",
"constant-literals/integer-literals/binary-integer-literals",
"constant-literals/integer-literals/hexadecimal-integer-literals",
"constant-literals/boolean-literals",
"constant-literals/character-literals",
"constant-literals/the-types-for-integer-literals",
"logical-disjunction-expression",
"logical-conjunction-expression",
"additive-expression",
"type-checking-and-containment-checking-expressions/type-checking-expression",
"type-checking-and-containment-checking-expressions/containment-checking-expression",
"try-expression",
"elvis-operator-expression",
"multiplicative-expression",
"range-expression",
"equality-expressions/value-equality-expressions",
"jump-expressions/break-expression",
"jump-expressions/return-expressions",
"jump-expressions/continue-expression",
"jump-expressions",
"conditional-expression",
"built-in-types-and-their-semantics/kotlin.nothing-1",
"built-in-types-and-their-semantics/kotlin.unit",
"prefix-expressions/unary-minus-expression",
"prefix-expressions/logical-not-expression",
"prefix-expressions/unary-plus-expression",
"prefix-expressions/prefix-increment-expression",
"prefix-expressions/prefix-decrement-expression",
"call-and-property-access-expressions/callable-references",
"call-and-property-access-expressions/navigation-operators",
"function-literals/lambda-literals"
],
"overloadable-operators": [
""
],
"built-in-types-and-their-semantics": [
"built-in-integer-types-1/integer-type-widening"
],
"control--and-data-flow-analysis": [
"control-flow-graph/expressions-1/conditional-expressions",
"performing-analysis-on-the-control-flow-graph/variable-initialization-analysis"
],
"annotations": [
"annotation-targets"
]
}
@@ -0,0 +1,10 @@
{
"expressions": [
"when-expression",
"constant-literals/real-literals",
"constant-literals/integer-literals/decimal-integer-literals",
"constant-literals/integer-literals/binary-integer-literals",
"constant-literals/integer-literals/hexadecimal-integer-literals",
"constant-literals/the-types-for-integer-literals"
]
}
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.spec.utils
import org.jetbrains.kotlin.TestsExceptionType
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.LINKED_TESTS_PATH
import org.jetbrains.kotlin.spec.utils.models.LinkedSpecTestFileInfoElementType
import org.jetbrains.kotlin.spec.utils.models.NotLinkedSpecTestFileInfoElementType
import org.jetbrains.kotlin.spec.utils.parsers.BasePatterns
@@ -35,7 +36,7 @@ enum class TestType(val type: String) {
enum class TestOrigin(private val testDataPath: String, private val testsPath: String? = null) {
IMPLEMENTATION(GeneralConfiguration.TESTDATA_PATH),
SPEC(GeneralConfiguration.SPEC_TESTDATA_PATH, TestsJsonMapGenerator.LINKED_TESTS_PATH);
SPEC(GeneralConfiguration.SPEC_TESTDATA_PATH, LINKED_TESTS_PATH);
fun getFilePath(testArea: TestArea) = buildString {
append("${testDataPath}/${testArea.testDataPath}")
@@ -10,4 +10,7 @@ object GeneralConfiguration {
const val SPEC_MODULE_PATH = "compiler/tests-spec"
const val SPEC_TESTDATA_PATH = "$SPEC_MODULE_PATH/testData"
const val SPEC_TEST_PATH = "$SPEC_MODULE_PATH/tests"
const val LINKED_TESTS_PATH = "linked"
const val TESTS_MAP_FILENAME = "testsMap.json"
const val SECTIONS_TESTS_MAP_FILENAME = "sectionsMap.json"
}
@@ -0,0 +1,78 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.utils
import com.google.gson.GsonBuilder
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.LINKED_TESTS_PATH
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.SECTIONS_TESTS_MAP_FILENAME
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.SPEC_TESTDATA_PATH
import java.io.File
object SectionsJsonMapGenerator {
val sectionsMapsByTestArea: MutableMap<TestArea, JsonObject> = mutableMapOf()
fun writeSectionsMapJsons() {
val gson = GsonBuilder().setPrettyPrinting().create()
sectionsMapsByTestArea.forEach { (testArea, json) ->
val sectionsMapFolder = "$SPEC_TESTDATA_PATH/${testArea.testDataPath}/$LINKED_TESTS_PATH"
File(sectionsMapFolder).mkdirs()
val sectionsMapFile = File("$sectionsMapFolder/$SECTIONS_TESTS_MAP_FILENAME")
sectionsMapFile.createNewFile()
sectionsMapFile.writeText(gson.toJson(json))
}
}
fun buildSectionsMap(testsMapPath: String) {
val sectionInfo = SectionInfo.parsePath(testsMapPath)
val testArea = sectionInfo.testArea
val testAreaSectionsMap = sectionsMapsByTestArea[testArea] ?: JsonObject()
addPathToTestAreaSectionsMap(testAreaSectionsMap, sectionInfo)
sectionsMapsByTestArea[testArea] = testAreaSectionsMap
}
private fun addPathToTestAreaSectionsMap(testAreaSectionsMap: JsonObject, sectionInfo: SectionInfo) {
if (!testAreaSectionsMap.has(sectionInfo.mainSection)) {
val subsectionsPathArray = JsonArray()
subsectionsPathArray.add(sectionInfo.subsectionsPath)
testAreaSectionsMap.add(sectionInfo.mainSection, subsectionsPathArray)
} else {
val subsectionsPathArray = testAreaSectionsMap.get(sectionInfo.mainSection) as? JsonArray
?: throw Exception("json element doesn't exist")
subsectionsPathArray.add(sectionInfo.subsectionsPath)
testAreaSectionsMap.add(sectionInfo.mainSection, subsectionsPathArray)
}
}
private class SectionInfo(
val testArea: TestArea,
val mainSection: String,
val subsectionsPath: String
) {
companion object {
private fun identifyTestArea(path: String): TestArea {
TestArea.values().forEach {
if (path.startsWith(it.testDataPath)) return it
}
throw IllegalArgumentException("testsMap path doesn't contain test area path")
}
fun parsePath(path: String): SectionInfo {
val testArea = identifyTestArea(path)
val fullSectionsPathList = path.subSequence(testArea.testDataPath.length + 1, path.length).toString().split("/")
if (fullSectionsPathList.first() != LINKED_TESTS_PATH)
throw IllegalArgumentException("testsMap path doesn't contain linked directory")
return SectionInfo(
testArea = testArea,
mainSection = fullSectionsPathList[1],
subsectionsPath = fullSectionsPathList.subList(2, fullSectionsPathList.size).joinToString("/")
)
}
}
}
}
@@ -9,6 +9,8 @@ import com.google.gson.GsonBuilder
import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.LINKED_TESTS_PATH
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTS_MAP_FILENAME
import org.jetbrains.kotlin.spec.utils.models.LinkedSpecTest
import org.jetbrains.kotlin.spec.utils.models.SpecPlace
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser
@@ -16,8 +18,6 @@ import org.jetbrains.kotlin.spec.utils.parsers.LinkedSpecTestPatterns
import java.io.File
object TestsJsonMapGenerator {
const val LINKED_TESTS_PATH = "linked"
const val TESTS_MAP_FILENAME = "testsMap.json"
private inline fun <reified T : JsonElement> JsonObject.getOrCreate(key: String): T {
if (!has(key)) {
@@ -113,6 +113,7 @@ object TestsJsonMapGenerator {
File(testMapFolder).mkdirs()
File("$testMapFolder/$TESTS_MAP_FILENAME").writeText(gson.toJson(testsMap.get(testPath)))
SectionsJsonMapGenerator.buildSectionsMap(testPath)
}
}
}
@@ -12,8 +12,9 @@ import org.jetbrains.kotlin.spec.codegen.AbstractBlackBoxCodegenTestSpec
import org.jetbrains.kotlin.spec.parsing.AbstractParsingTestSpec
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.SPEC_TESTDATA_PATH
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.SPEC_TEST_PATH
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTS_MAP_FILENAME
import org.jetbrains.kotlin.spec.utils.SectionsJsonMapGenerator
import org.jetbrains.kotlin.spec.utils.TestsJsonMapGenerator
import org.jetbrains.kotlin.spec.utils.TestsJsonMapGenerator.TESTS_MAP_FILENAME
import java.io.File
import java.nio.file.Files
@@ -72,6 +73,6 @@ fun generateTests() {
fun main() {
TestsJsonMapGenerator.buildTestsMapPerSection()
TestsJsonMapGenerator.buildTestsMapPerSection()
SectionsJsonMapGenerator.writeSectionsMapJsons()
generateTests()
}