diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/TestsJsonMapBuilder.kt b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/TestsJsonMapBuilder.kt index 9388ee2288a..5fc5e618b8f 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/TestsJsonMapBuilder.kt +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/TestsJsonMapBuilder.kt @@ -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>() {}.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) diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/tasks/GenerateJsonTestsMap.kt b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/tasks/GenerateJsonTestsMap.kt new file mode 100644 index 00000000000..1d7f7a38edc --- /dev/null +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/tasks/GenerateJsonTestsMap.kt @@ -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()) +} \ No newline at end of file