Add task to generate tests json map (is used for tool 'spec-tests-relinking recommender')
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2019 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.
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.spec.utils
|
||||
|
||||
import com.google.gson.*
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import org.jetbrains.kotlin.spec.models.LinkedSpecTest
|
||||
import org.jetbrains.kotlin.spec.utils.models.LinkedSpecTest
|
||||
|
||||
object TestsJsonMapBuilder {
|
||||
private val stringListType = object : TypeToken<List<String>>() {}.type
|
||||
@@ -20,9 +20,12 @@ object TestsJsonMapBuilder {
|
||||
|
||||
fun buildJsonElement(testInfo: LinkedSpecTest, testsMap: JsonObject) {
|
||||
val sectionElement = addJsonIfNotExist(testsMap, testInfo.sections[0])
|
||||
val paragraphElement = addJsonIfNotExist(sectionElement, testInfo.place.paragraphNumber)
|
||||
val sentenceElement = addJsonIfNotExist(paragraphElement, testInfo.place.sentenceNumber)
|
||||
val testAreaElement = addJsonIfNotExist(sentenceElement, testInfo.testArea.name.toLowerCase())
|
||||
val paragraphElement =
|
||||
addJsonIfNotExist(sectionElement, testInfo.place.paragraphNumber)
|
||||
val sentenceElement =
|
||||
addJsonIfNotExist(paragraphElement, testInfo.place.sentenceNumber)
|
||||
val testAreaElement =
|
||||
addJsonIfNotExist(sentenceElement, testInfo.testArea.name.toLowerCase())
|
||||
val testTypeElement = addJsonIfNotExist(testAreaElement, testInfo.testType.type)
|
||||
val testNumberElement = addJsonIfNotExist(testTypeElement, testInfo.testNumber)
|
||||
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.tasks
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.MODULE_PATH
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
|
||||
import org.jetbrains.kotlin.spec.utils.TestsJsonMapBuilder
|
||||
import org.jetbrains.kotlin.spec.utils.models.LinkedSpecTest
|
||||
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser
|
||||
import java.io.File
|
||||
|
||||
private const val OUT_DIR = "out"
|
||||
private const val OUT_FILENAME = "testsMap.json"
|
||||
|
||||
fun main() {
|
||||
val testsMap = JsonObject()
|
||||
|
||||
File(TESTDATA_PATH).walkTopDown().forEach {
|
||||
val (specTest, _) = CommonParser.parseSpecTest(it.canonicalPath, mapOf("main.kt" to it.readText()))
|
||||
|
||||
if (specTest is LinkedSpecTest)
|
||||
TestsJsonMapBuilder.buildJsonElement(specTest, testsMap)
|
||||
}
|
||||
|
||||
val outDir = "$MODULE_PATH/$OUT_DIR"
|
||||
|
||||
File(outDir).mkdir()
|
||||
File("$outDir/$OUT_FILENAME").writeText(testsMap.toString())
|
||||
}
|
||||
Reference in New Issue
Block a user