[Spec tests] Generate sections json map
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user