Group spec tests and accompanying functionality into to packages: org.jetbrains.kotlin.spec (tests only) and org.jetbrains.kotlin.spec.utils (accompanying functionality)

This commit is contained in:
victor.petukhov
2019-08-12 11:45:36 +03:00
parent cf692fb257
commit 0e439263ce
34 changed files with 2372 additions and 2771 deletions
@@ -0,0 +1,126 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.checkers
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.TestExceptionsComparator
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.spec.utils.SpecTestLinkedType
import org.jetbrains.kotlin.spec.utils.models.AbstractSpecTest
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser
import org.jetbrains.kotlin.spec.utils.validators.DiagnosticTestTypeValidator
import org.jetbrains.kotlin.spec.utils.validators.SpecTestValidationException
import org.jetbrains.kotlin.test.*
import org.junit.Assert
import java.io.File
import java.util.regex.Matcher
abstract class AbstractDiagnosticsTestSpec : org.jetbrains.kotlin.checkers.AbstractDiagnosticsTest() {
companion object {
private val withoutDescriptorsTestGroups = listOf(
"linked/when-expression"
)
private const val MODULE_PATH = "compiler/tests-spec"
private const val DIAGNOSTICS_TESTDATA_PATH = "$MODULE_PATH/testData/diagnostics"
private const val HELPERS_PATH = "$DIAGNOSTICS_TESTDATA_PATH/helpers"
}
lateinit var specTest: AbstractSpecTest
lateinit var testLinkedType: SpecTestLinkedType
private var skipDescriptors = true
private fun checkDirective(directive: String, testFiles: List<TestFile>) =
testFiles.any { it.directives.contains(directive) }
private fun enableDescriptorsGenerationIfNeeded(testFilePath: String) {
skipDescriptors = withoutDescriptorsTestGroups.any {
val testGroupAbsolutePath = File("$DIAGNOSTICS_TESTDATA_PATH/$it").absolutePath
testFilePath.startsWith(testGroupAbsolutePath)
}
}
override fun getConfigurationKind() = ConfigurationKind.ALL
override fun skipDescriptorsValidation() = skipDescriptors
override fun getKtFiles(testFiles: List<TestFile>, includeExtras: Boolean): List<KtFile> {
val ktFiles = super.getKtFiles(testFiles, includeExtras) as ArrayList
if (specTest.helpers == null) return ktFiles
specTest.helpers?.forEach {
val filename = "$it.kt"
val helperContent = FileUtil.loadFile(File("$HELPERS_PATH/$filename"), true)
ktFiles.add(
KotlinTestUtils.createFile(filename, helperContent, project)
)
}
return ktFiles
}
override fun analyzeAndCheck(testDataFile: File, files: List<TestFile>) {
val testFilePath = testDataFile.canonicalPath
enableDescriptorsGenerationIfNeeded(testFilePath)
CommonParser.parseSpecTest(testFilePath, files.associate { Pair(it.fileName, it.clearText) }).apply {
specTest = first
testLinkedType = second
}
println(specTest)
val computeExceptionPoint: (Matcher?) -> Set<Int>? = l@{ matches ->
if (matches == null) return@l null
val lineNumber = matches.group("lineNumber").toInt()
val symbolNumber = matches.group("symbolNumber").toInt()
val filename = matches.group("filename")
val fileContent = files.find { it.ktFile?.name == filename }!!.clearText
val exceptionPosition = fileContent.lines().subList(0, lineNumber).joinToString("\n").length + symbolNumber
val testCases = specTest.cases.byRanges[filename]
val testCasesWithSamePosition = testCases!!.floorEntry(exceptionPosition).value
return@l testCasesWithSamePosition.keys.toSet()
}
val exceptionsInCases = specTest.cases.byNumbers.entries.associate { it.key to it.value.exception }
TestExceptionsComparator(testDataFile).run(specTest.exception, exceptionsInCases, computeExceptionPoint) {
super.analyzeAndCheck(testDataFile, files)
}
}
override fun performAdditionalChecksAfterDiagnostics(
testDataFile: File,
testFiles: List<TestFile>,
moduleFiles: Map<TestModule?, List<TestFile>>,
moduleDescriptors: Map<TestModule?, ModuleDescriptorImpl>,
moduleBindings: Map<TestModule?, BindingContext>,
languageVersionSettingsByModule: Map<TestModule?, LanguageVersionSettings>
) {
val diagnosticValidator = try {
DiagnosticTestTypeValidator(testFiles, testDataFile, specTest)
} catch (e: SpecTestValidationException) {
Assert.fail(e.description)
return
}
try {
diagnosticValidator.validatePathConsistency(testLinkedType)
diagnosticValidator.validateTestType()
} catch (e: SpecTestValidationException) {
Assert.fail(e.description)
} finally {
diagnosticValidator.printDiagnosticStatistic()
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,72 @@
/*
* Copyright 2010-2018 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.codegen
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.TestExceptionsComparator
import org.jetbrains.kotlin.spec.models.AbstractSpecTest
import org.jetbrains.kotlin.spec.parsers.CommonParser
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.packagePattern
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
import org.jetbrains.kotlin.spec.validators.BlackBoxTestTypeValidator
import org.jetbrains.kotlin.spec.validators.SpecTestValidationException
import org.junit.Assert
import java.io.File
abstract class AbstractBlackBoxCodegenTestSpec : AbstractBlackBoxCodegenTest() {
companion object {
private const val CODEGEN_BOX_TESTDATA_PATH = "$TESTDATA_PATH/codegen/box"
private const val HELPERS_PATH = "$CODEGEN_BOX_TESTDATA_PATH/helpers"
private const val HELPERS_PACKAGE_VARIABLE = "<!PACKAGE!>"
}
private fun addPackageDirectiveToHelperFile(helperContent: String, packageName: String?) =
helperContent.replace(HELPERS_PACKAGE_VARIABLE, if (packageName == null) "" else "package $packageName")
private fun includeHelpers(wholeFile: File, files: MutableList<TestFile>, specTest: AbstractSpecTest) {
if (specTest.helpers == null) return
val fileContent = FileUtil.loadFile(wholeFile, true)
val packageName = packagePattern.matcher(fileContent).let {
if (it.find()) it.group("packageName") else null
}
specTest.helpers.forEach {
val filename = "$it.kt"
val helperContent = FileUtil.loadFile(File("$HELPERS_PATH/$filename"), true)
files.add(
TestFile(filename, addPackageDirectiveToHelperFile(helperContent, packageName))
)
}
}
override fun doMultiFileTest(wholeFile: File, files: MutableList<TestFile>) {
val (specTest, testLinkedType) = CommonParser.parseSpecTest(
wholeFile.canonicalPath,
mapOf("main.kt" to FileUtil.loadFile(wholeFile, true))
)
val validator = BlackBoxTestTypeValidator(wholeFile, specTest)
try {
validator.validatePathConsistency(testLinkedType)
} catch (e: SpecTestValidationException) {
Assert.fail(e.description)
}
println(specTest)
includeHelpers(wholeFile, files, specTest)
if (specTest.exception == null) {
super.doMultiFileTest(wholeFile, files)
} else {
TestExceptionsComparator(wholeFile).run(specTest.exception) {
super.doMultiFileTest(wholeFile, files)
}
}
}
}
@@ -0,0 +1,43 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.parsing
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.TestExceptionsComparator
import org.jetbrains.kotlin.parsing.AbstractParsingTest
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser
import org.jetbrains.kotlin.spec.utils.validators.ParsingTestTypeValidator
import org.jetbrains.kotlin.spec.utils.validators.SpecTestValidationException
import org.junit.Assert
import java.io.File
abstract class AbstractParsingTestSpec : AbstractParsingTest() {
override fun doParsingTest(filePath: String) {
val file = File(filePath)
val (specTest, testLinkedType) = CommonParser.parseSpecTest(
filePath,
mapOf("main.kt" to FileUtil.loadFile(file, true))
)
println(specTest)
if (specTest.exception == null) {
super.doParsingTest(filePath, CommonParser::testInfoFilter)
} else {
TestExceptionsComparator(file).run(specTest.exception) {
super.doParsingTest(filePath, CommonParser::testInfoFilter)
}
}
try {
val psiTestValidator = ParsingTestTypeValidator(myFile, File(filePath), specTest)
psiTestValidator.validatePathConsistency(testLinkedType)
psiTestValidator.validateTestType()
} catch (e: SpecTestValidationException) {
Assert.fail(e.description)
}
}
}
File diff suppressed because it is too large Load Diff
@@ -1,33 +0,0 @@
/*
* Copyright 2010-2018 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.tasks
import com.google.gson.JsonObject
import org.jetbrains.kotlin.spec.models.LinkedSpecTest
import org.jetbrains.kotlin.spec.parsers.CommonParser
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 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())
}
@@ -1,136 +0,0 @@
/*
* Copyright 2010-2018 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.tasks
import org.jetbrains.kotlin.checkers.AbstractDiagnosticsTestSpec
import org.jetbrains.kotlin.codegen.AbstractBlackBoxCodegenTestSpec
import org.jetbrains.kotlin.generators.tests.generator.testGroup
import org.jetbrains.kotlin.parsing.AbstractParsingTestSpec
import org.jetbrains.kotlin.spec.models.LinkedSpecTest
import org.jetbrains.kotlin.spec.parsers.CommonParser
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TEST_PATH
import java.io.File
import java.lang.StringBuilder
private data class TestReferences(var testsRelevant: MutableSet<String>? = null, var testNumber: Int = 0)
private typealias TestsBySections = MutableMap<String, TestsByParagraph>
private typealias TestsByParagraph = MutableMap<Int, TestsByType>
private typealias TestsByType = MutableMap<String, TestsBySentence>
private typealias TestsBySentence = MutableMap<Int, TestReferences>
private object TestsMapGenerator {
private const val TESTS_MAP_FILE_HEADER = """/*
* This file is generated by {@link org.jetbrains.kotlin.spec.tasks.generateTests}. DO NOT MODIFY MANUALLY.
* This file is used in the HTML version of the Kotlin Specification (https://kotlin.github.io/kotlin-spec) to show tests coverage for sentences.
*
* Content format:
*
* {paragraphNumber}
* {testType: neg|pos}: {sentenceNumber}-{numberOfTests|testPathToAnotherSection}, ...
*/
"""
private const val LINKED_TESTS_PATH = "$TESTDATA_PATH/diagnostics/linked"
private const val TESTS_MAP_FILENAME = "testsMap.txt"
private val lineBreak = System.lineSeparator()
private fun createObjectsPath(specTest: LinkedSpecTest, testsMap: TestsBySections): TestReferences {
val sections = specTest.place.sections.joinToString("/")
val testsBySection = testsMap.getOrPut(sections) { mutableMapOf() }
val testsByParagraph = testsBySection.getOrPut(specTest.place.paragraphNumber) { mutableMapOf() }
val testsByType = testsByParagraph.getOrPut(specTest.testType.type) { mutableMapOf() }
return testsByType.getOrPut(specTest.place.sentenceNumber) { TestReferences() }
}
private fun appendRelevantTests(specTest: LinkedSpecTest, testsMap: TestsBySections) {
if (specTest.relevantPlaces == null) return
specTest.relevantPlaces.forEach {
val sections = it.sections.joinToString("/")
val testsBySection = testsMap.getOrPut(sections) { mutableMapOf() }
val testsByParagraph = testsBySection.getOrPut(it.paragraphNumber) { mutableMapOf() }
val testsByType = testsByParagraph.getOrPut(specTest.testType.type) { mutableMapOf() }
val testReferences = testsByType.getOrPut(it.sentenceNumber) { TestReferences() }
if (testReferences.testsRelevant == null) {
testReferences.testsRelevant = mutableSetOf()
}
testReferences.testsRelevant!!.add(
"${specTest.sections.joinToString("/")}/${specTest.place.paragraphNumber}/${specTest.testType.type}/${specTest.place.sentenceNumber}.${specTest.testNumber}.kt"
)
}
}
private fun buildTestsMapAsText(testsMap: TestsByParagraph): String {
val testsMapAsText = StringBuilder()
testsMap.forEach { (paragraphNumber, testsByType) ->
testsMapAsText.append("$paragraphNumber$lineBreak")
testsByType.forEach { (testType, testsBySentence) ->
val sentenceTests = mutableListOf<String>()
testsMapAsText.append(" $testType: ")
testsBySentence.forEach { (sentenceNumber, tests) ->
if (tests.testNumber != 0) {
sentenceTests.add("$sentenceNumber-${tests.testNumber}")
}
if (tests.testsRelevant != null) {
tests.testsRelevant!!.forEach {
sentenceTests.add("$sentenceNumber-$it")
}
}
}
testsMapAsText.append(sentenceTests.joinToString(", ") + lineBreak)
}
}
return testsMapAsText.toString()
}
fun buildTestsMapPerSection() {
val testsMap: TestsBySections = mutableMapOf()
File(LINKED_TESTS_PATH).walkTopDown().forEach {
if (!it.isFile || it.extension != "kt") return@forEach
val (specTest, _) = CommonParser.parseSpecTest(it.canonicalPath, mapOf("main.kt" to it.readText()))
if (specTest is LinkedSpecTest) {
val testReferences = createObjectsPath(specTest, testsMap)
testReferences.testNumber++
appendRelevantTests(specTest, testsMap)
}
}
testsMap.forEach { (sections, testsByParagraph) ->
val testsMapFile = File("$LINKED_TESTS_PATH/$sections/$TESTS_MAP_FILENAME")
val testsMapAsText = buildTestsMapAsText(testsByParagraph)
testsMapFile.writeText(TESTS_MAP_FILE_HEADER + lineBreak + testsMapAsText)
}
}
}
private fun generateTests() {
testGroup(TEST_PATH, TESTDATA_PATH) {
testClass<AbstractDiagnosticsTestSpec> {
model("diagnostics", excludeDirs = listOf("helpers"))
}
testClass<AbstractParsingTestSpec> {
model("psi", testMethod = "doParsingTest", excludeDirs = listOf("helpers", "templates"))
}
testClass<AbstractBlackBoxCodegenTestSpec> {
model("codegen/box", excludeDirs = listOf("helpers", "templates"))
}
}
}
fun main() {
TestsMapGenerator.buildTestsMapPerSection()
generateTests()
}
@@ -1,17 +1,17 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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
package org.jetbrains.kotlin.spec.utils
import org.jetbrains.kotlin.TestsExceptionType
import org.jetbrains.kotlin.spec.models.LinkedSpecTestFileInfoElementType
import org.jetbrains.kotlin.spec.models.NotLinkedSpecTestFileInfoElementType
import org.jetbrains.kotlin.spec.parsers.BasePatterns
import org.jetbrains.kotlin.spec.parsers.LinkedSpecTestPatterns
import org.jetbrains.kotlin.spec.parsers.NotLinkedSpecTestPatterns
import org.jetbrains.kotlin.spec.parsers.CommonParser.withSpaces
import org.jetbrains.kotlin.spec.utils.models.LinkedSpecTestFileInfoElementType
import org.jetbrains.kotlin.spec.utils.models.NotLinkedSpecTestFileInfoElementType
import org.jetbrains.kotlin.spec.utils.parsers.BasePatterns
import org.jetbrains.kotlin.spec.utils.parsers.LinkedSpecTestPatterns
import org.jetbrains.kotlin.spec.utils.parsers.NotLinkedSpecTestPatterns
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.withSpaces
import java.util.*
import java.util.regex.Matcher
import java.util.regex.Pattern
@@ -1,6 +1,6 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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
@@ -1,15 +1,13 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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 org.jetbrains.kotlin.spec.SpecTestLinkedType
import org.jetbrains.kotlin.spec.TestArea
import org.jetbrains.kotlin.spec.models.AbstractSpecTest
import org.jetbrains.kotlin.spec.parsers.CommonParser
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
import org.jetbrains.kotlin.spec.utils.models.AbstractSpecTest
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser
import java.io.File
open class SpecTestsStatElement(val type: SpecTestsStatElementType) {
@@ -47,7 +45,8 @@ object TestsStatisticCollector {
for (specTestArea in TestArea.values()) {
val specTestsPath = "$TESTDATA_PATH/${specTestArea.name.toLowerCase().replace("_", "/")}/${testLinkedType.testDataPath}"
statistic[specTestArea] = SpecTestsStatElement(SpecTestsStatElementType.AREA)
statistic[specTestArea] =
SpecTestsStatElement(SpecTestsStatElementType.AREA)
File(specTestsPath).walkTopDown().forEach areaTests@{
if (!it.isFile || it.extension != "kt") return@areaTests
@@ -1,9 +1,9 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.generators.templates
package org.jetbrains.kotlin.spec.utils.generators.templates
enum class Feature(val config: FeatureTemplatesConfig) {
IDENTIFIERS(
@@ -1,9 +1,9 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.generators.templates
package org.jetbrains.kotlin.spec.utils.generators.templates
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
import java.io.File
@@ -1,12 +1,12 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.generators.templates
package org.jetbrains.kotlin.spec.utils.generators.templates
import org.jetbrains.kotlin.spec.TestArea
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
import org.jetbrains.kotlin.spec.utils.TestArea
import java.io.File
enum class FeatureTemplatesType {
@@ -43,7 +43,9 @@ class FeatureTemplatesConfig(
private fun getTemplatesIterator() = lazy { getTemplates(testArea).value.iterator() }
fun resetTemplatesIterator() { currentTemplatesIterator = getTemplatesIterator() }
fun resetTemplatesIterator() {
currentTemplatesIterator = getTemplatesIterator()
}
fun getNextWithRepeat() = let {
takeUnless { it.currentTemplatesIterator.value.hasNext() }?.resetTemplatesIterator()
@@ -1,13 +1,13 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.generators.templates
package org.jetbrains.kotlin.spec.utils.generators.templates
import org.jetbrains.kotlin.spec.SpecTestLinkedType
import org.jetbrains.kotlin.spec.TestArea
import org.jetbrains.kotlin.spec.TestType
import org.jetbrains.kotlin.spec.utils.SpecTestLinkedType
import org.jetbrains.kotlin.spec.utils.TestArea
import org.jetbrains.kotlin.spec.utils.TestType
enum class SubstitutionTag(val passType: SubstitutionPassType = SubstitutionPassType.FIRST) {
DIRECTIVES,
@@ -40,7 +40,7 @@ abstract class GenerationSpecTestDataConfig {
lateinit var testArea: TestArea
protected val baseSubstitutions = mapOf<SubstitutionTag, (SubstitutionRule) -> String>(
SubstitutionTag.TEST_TYPE to { _ -> testType.toString() },
SubstitutionTag.TEST_TYPE to { testType.toString() },
SubstitutionTag.TEST_NUMBER to { rule -> rule.testNumber.toString() },
SubstitutionTag.TEST_DESCRIPTION to { rule -> testDescription.format(rule.filename) },
SubstitutionTag.ELEMENT to { rule ->
@@ -104,10 +104,10 @@ class GenerationLinkedSpecTestDataConfig : GenerationSpecTestDataConfig() {
override val layoutFilename = "linkedTestsLayout.kt"
override val substitutions = mutableMapOf<SubstitutionTag, (SubstitutionRule) -> String>(
SubstitutionTag.SECTIONS to { _ -> sections.joinToString(", ") },
SubstitutionTag.PARAGRAPH_NUMBER to { _ -> paragraphNumber.toString() },
SubstitutionTag.SENTENCE_NUMBER to { _ -> sentenceNumber.toString() },
SubstitutionTag.SENTENCE to { _ -> sentence },
SubstitutionTag.SECTIONS to { sections.joinToString(", ") },
SubstitutionTag.PARAGRAPH_NUMBER to { paragraphNumber.toString() },
SubstitutionTag.SENTENCE_NUMBER to { sentenceNumber.toString() },
SubstitutionTag.SENTENCE to { sentence },
SubstitutionTag.CLASS_OF_FILE to { rule -> "_${sentenceNumber}_${rule.testNumber}Kt" }
).apply { putAll(baseSubstitutions) }
@@ -120,7 +120,7 @@ class GenerationNotLinkedSpecTestDataConfig : GenerationSpecTestDataConfig() {
override val layoutFilename = "notLinkedTestsLayout.kt"
override val substitutions = mutableMapOf<SubstitutionTag, (SubstitutionRule) -> String>(
SubstitutionTag.CATEGORIES to { _ -> categories.joinToString(", ") },
SubstitutionTag.CATEGORIES to { categories.joinToString(", ") },
SubstitutionTag.CLASS_OF_FILE to { rule -> "_${rule.testNumber}Kt" }
).apply { putAll(baseSubstitutions) }
@@ -1,11 +1,11 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.generators.templates
package org.jetbrains.kotlin.spec.utils.generators.templates
import org.jetbrains.kotlin.spec.tasks.generateTests
import org.jetbrains.kotlin.spec.utils.tasks.generateTests
fun generationSpecTestDataConfigGroup(regenerateTests: Boolean = false, body: () -> Unit) {
body()
@@ -1,9 +1,9 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.generators.templates
package org.jetbrains.kotlin.spec.utils.generators.templates
enum class TemplateValidationTransformerType {
TRIM_BACKTICKS
@@ -1,16 +1,16 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.models
package org.jetbrains.kotlin.spec.utils.models
import org.jetbrains.kotlin.TestsExceptionType
import org.jetbrains.kotlin.spec.*
import org.jetbrains.kotlin.spec.parsers.CommonPatterns
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.issuesPattern
import org.jetbrains.kotlin.spec.parsers.LinkedSpecTestPatterns.relevantPlacesPattern
import org.jetbrains.kotlin.spec.parsers.TestCasePatterns.testCaseNumberPattern
import org.jetbrains.kotlin.spec.utils.*
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.issuesPattern
import org.jetbrains.kotlin.spec.utils.parsers.LinkedSpecTestPatterns.relevantPlacesPattern
import org.jetbrains.kotlin.spec.utils.parsers.TestCasePatterns.testCaseNumberPattern
import java.util.regex.Matcher
import java.util.regex.Pattern
@@ -1,21 +1,21 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.models
package org.jetbrains.kotlin.spec.utils.models
import org.jetbrains.kotlin.TestsExceptionType
import org.jetbrains.kotlin.spec.SpecTestCasesSet
import org.jetbrains.kotlin.spec.SpecTestInfoElementType
import org.jetbrains.kotlin.spec.TestArea
import org.jetbrains.kotlin.spec.TestType
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.ls
import org.jetbrains.kotlin.spec.parsers.CommonParser.withUnderscores
import org.jetbrains.kotlin.spec.parsers.CommonParser.splitByPathSeparator
import org.jetbrains.kotlin.spec.parsers.CommonParser.withSpaces
import org.jetbrains.kotlin.spec.parsers.LinkedSpecTestPatterns.placePattern
import org.jetbrains.kotlin.spec.parsers.LinkedSpecTestPatterns.relevantPlacesPattern
import org.jetbrains.kotlin.spec.utils.SpecTestCasesSet
import org.jetbrains.kotlin.spec.utils.SpecTestInfoElementType
import org.jetbrains.kotlin.spec.utils.TestArea
import org.jetbrains.kotlin.spec.utils.TestType
import org.jetbrains.kotlin.spec.utils.parsers.LinkedSpecTestPatterns.placePattern
import org.jetbrains.kotlin.spec.utils.parsers.LinkedSpecTestPatterns.relevantPlacesPattern
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.withSpaces
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.withUnderscores
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.splitByPathSeparator
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.ls
import java.util.regex.Matcher
import java.util.regex.Pattern
@@ -36,7 +36,7 @@ data class SpecPlace(
)
class LinkedSpecTest(
private val specVersion: String,
val specVersion: String,
testArea: TestArea,
testType: TestType,
val place: SpecPlace,
@@ -1,20 +1,20 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.models
package org.jetbrains.kotlin.spec.utils.models
import org.jetbrains.kotlin.TestsExceptionType
import org.jetbrains.kotlin.spec.SpecTestCasesSet
import org.jetbrains.kotlin.spec.SpecTestInfoElementType
import org.jetbrains.kotlin.spec.TestArea
import org.jetbrains.kotlin.spec.TestType
import org.jetbrains.kotlin.spec.parsers.CommonParser.splitByPathSeparator
import org.jetbrains.kotlin.spec.parsers.CommonParser.withUnderscores
import org.jetbrains.kotlin.spec.parsers.CommonParser.withSpaces
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.ls
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.sectionsInFilePattern
import org.jetbrains.kotlin.spec.utils.SpecTestCasesSet
import org.jetbrains.kotlin.spec.utils.SpecTestInfoElementType
import org.jetbrains.kotlin.spec.utils.TestArea
import org.jetbrains.kotlin.spec.utils.TestType
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.sectionsInFilePattern
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.withSpaces
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.withUnderscores
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.splitByPathSeparator
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.ls
import java.util.regex.Matcher
import java.util.regex.Pattern
@@ -1,19 +1,21 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.parsers
package org.jetbrains.kotlin.spec.utils.parsers
import org.jetbrains.kotlin.spec.*
import org.jetbrains.kotlin.spec.SpecTestInfoElementContent
import org.jetbrains.kotlin.spec.SpecTestLinkedType
import org.jetbrains.kotlin.spec.models.*
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.testInfoElementPattern
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.testPathBaseRegexTemplate
import org.jetbrains.kotlin.spec.parsers.LinkedSpecTestPatterns.testInfoPattern
import org.jetbrains.kotlin.spec.parsers.TestCasePatterns.testCaseInfoPattern
import org.jetbrains.kotlin.spec.validators.*
import org.jetbrains.kotlin.spec.utils.SpecTestInfoElementContent
import org.jetbrains.kotlin.spec.utils.SpecTestInfoElementType
import org.jetbrains.kotlin.spec.utils.SpecTestLinkedType
import org.jetbrains.kotlin.spec.utils.TestFiles
import org.jetbrains.kotlin.spec.utils.models.*
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.testInfoElementPattern
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.testPathBaseRegexTemplate
import org.jetbrains.kotlin.spec.utils.parsers.LinkedSpecTestPatterns.testInfoPattern
import org.jetbrains.kotlin.spec.utils.parsers.TestCasePatterns.testCaseInfoPattern
import org.jetbrains.kotlin.spec.utils.validators.SpecTestValidationException
import org.jetbrains.kotlin.spec.utils.validators.SpecTestValidationFailedReason
import java.io.File
import java.util.regex.Matcher
import java.util.regex.Pattern
@@ -52,7 +54,7 @@ object CommonParser {
placeMatcher.group("sentenceNumber").toInt()
)
private fun parseLinkedSpecTest(testFilePath: String, testFiles: TestFiles): LinkedSpecTest {
fun parseLinkedSpecTest(testFilePath: String, testFiles: TestFiles): LinkedSpecTest {
val parsedTestFile = parseTestInfo(testFilePath, testFiles, SpecTestLinkedType.LINKED)
val testInfoElements = parsedTestFile.testInfoElements
val placeMatcher = testInfoElements[LinkedSpecTestFileInfoElementType.PLACE]!!.additionalMatcher!!
@@ -1,26 +1,26 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.parsers
package org.jetbrains.kotlin.spec.utils.parsers
import org.jetbrains.kotlin.spec.models.SpecTestCaseInfoElementType
import org.jetbrains.kotlin.spec.SpecTestLinkedType
import org.jetbrains.kotlin.spec.TestArea
import org.jetbrains.kotlin.spec.TestType
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.INTEGER_REGEX
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.SINGLE_LINE_COMMENT_REGEX
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.ASTERISK_REGEX
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.directiveRegex
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.MULTILINE_COMMENT_REGEX
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.ps
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.testAreaRegex
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.testPathRegexTemplate
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.testTypeRegex
import org.jetbrains.kotlin.spec.parsers.CommonParser.withSpaces
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.SECTIONS_IN_FILE_REGEX
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.sectionsInPathRegex
import org.jetbrains.kotlin.spec.utils.SpecTestLinkedType
import org.jetbrains.kotlin.spec.utils.TestArea
import org.jetbrains.kotlin.spec.utils.TestType
import org.jetbrains.kotlin.spec.utils.models.SpecTestCaseInfoElementType
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.ASTERISK_REGEX
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.INTEGER_REGEX
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.MULTILINE_COMMENT_REGEX
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.SECTIONS_IN_FILE_REGEX
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.SINGLE_LINE_COMMENT_REGEX
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.directiveRegex
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.ps
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.sectionsInPathRegex
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.testAreaRegex
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.withSpaces
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.testPathRegexTemplate
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.testTypeRegex
import java.io.File
import java.util.regex.Pattern
@@ -29,7 +29,7 @@ object CommonPatterns {
const val INTEGER_REGEX = """[1-9]\d*"""
const val SINGLE_LINE_COMMENT_REGEX = """\/\/\s*%s"""
const val ASTERISK_REGEX = """\*"""
const val SECTIONS_IN_FILE_REGEX = """[\w-]+(,\s+[\w-]+)*"""
const val SECTIONS_IN_FILE_REGEX = """[\w-\.]+(,\s+[\w-\.]+)*"""
const val MULTILINE_COMMENT_REGEX = """\/\*\s+?%s\s+\*\/(?:\n)*"""
val ls: String = System.lineSeparator()
@@ -44,7 +44,7 @@ object CommonPatterns {
val testPathRegexTemplate = """$testPathBaseRegexTemplate$ps(?<testType>pos|neg)$ps%s$"""
val issuesPattern: Pattern = Pattern.compile("""(KT-[1-9]\d*)(,\s*KT-[1-9]\d*)*""")
val sectionsInFilePattern: Pattern = Pattern.compile("""(?<sections>$SECTIONS_IN_FILE_REGEX)""")
val sectionsInPathRegex = """(?<sections>(?:[\w-]+)(?:$ps[\w-]+)*?)"""
val sectionsInPathRegex = """(?<sections>(?:[\w-\.]+)(?:$ps[\w-\.]+)*?)"""
val packagePattern: Pattern = Pattern.compile("""(?:^|\n)package (?<packageName>.*?)(?:;|\n)""")
}
@@ -1,18 +1,18 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.parsers
package org.jetbrains.kotlin.spec.utils.parsers
import org.jetbrains.kotlin.TestsExceptionType
import org.jetbrains.kotlin.spec.*
import org.jetbrains.kotlin.spec.models.CommonInfoElementType
import org.jetbrains.kotlin.spec.models.LinkedSpecTestFileInfoElementType
import org.jetbrains.kotlin.spec.models.SpecTestCaseInfoElementType
import org.jetbrains.kotlin.spec.models.SpecTestInfoElements
import org.jetbrains.kotlin.spec.parsers.CommonParser.splitByComma
import org.jetbrains.kotlin.spec.parsers.TestCasePatterns.testCaseInfoPattern
import org.jetbrains.kotlin.spec.utils.*
import org.jetbrains.kotlin.spec.utils.models.CommonInfoElementType
import org.jetbrains.kotlin.spec.utils.models.LinkedSpecTestFileInfoElementType
import org.jetbrains.kotlin.spec.utils.models.SpecTestCaseInfoElementType
import org.jetbrains.kotlin.spec.utils.models.SpecTestInfoElements
import org.jetbrains.kotlin.spec.utils.parsers.TestCasePatterns.testCaseInfoPattern
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.splitByComma
import java.util.*
private operator fun SpecTestCase.plusAssign(addTestCase: SpecTestCase) {
@@ -47,11 +47,7 @@ private fun SpecTestCase.save(
}
fun parseTestCases(testFiles: TestFiles): SpecTestCasesSet {
val testCasesSet = SpecTestCasesSet(
mutableMapOf<String, TestCasesByNumbers>(),
mutableMapOf<String, NavigableMap<Int, TestCasesByNumbers>>(),
mutableMapOf<Int, SpecTestCase>()
)
val testCasesSet = SpecTestCasesSet(mutableMapOf(), mutableMapOf(), mutableMapOf())
var rangeOffset = 0
for ((filename, fileContent) in testFiles) {
@@ -59,8 +55,8 @@ fun parseTestCases(testFiles: TestFiles): SpecTestCasesSet {
var startFind = 0
if (!testCasesSet.byFiles.contains(filename)) {
testCasesSet.byFiles[filename] = mutableMapOf<Int, SpecTestCase>()
testCasesSet.byRanges[filename] = TreeMap<Int, TestCasesByNumbers>()
testCasesSet.byFiles[filename] = mutableMapOf()
testCasesSet.byRanges[filename] = TreeMap()
}
val testCasesOfFile = testCasesSet.byFiles[filename]!!
@@ -1,19 +1,20 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.parsers
package org.jetbrains.kotlin.spec.utils.parsers
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.TestsExceptionType
import org.jetbrains.kotlin.spec.*
import org.jetbrains.kotlin.spec.models.CommonInfoElementType
import org.jetbrains.kotlin.spec.models.CommonSpecTestFileInfoElementType
import org.jetbrains.kotlin.spec.models.SpecTestInfoElements
import org.jetbrains.kotlin.spec.parsers.CommonParser.withUnderscores
import org.jetbrains.kotlin.spec.parsers.CommonParser.splitByComma
import org.jetbrains.kotlin.spec.validators.*
import org.jetbrains.kotlin.spec.utils.*
import org.jetbrains.kotlin.spec.utils.models.CommonInfoElementType
import org.jetbrains.kotlin.spec.utils.models.CommonSpecTestFileInfoElementType
import org.jetbrains.kotlin.spec.utils.models.SpecTestInfoElements
import org.jetbrains.kotlin.spec.utils.validators.SpecTestValidationException
import org.jetbrains.kotlin.spec.utils.validators.SpecTestValidationFailedReason
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.splitByComma
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.withUnderscores
import java.io.File
data class ParsedTestFile(
@@ -1,22 +1,22 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.tasks
package org.jetbrains.kotlin.spec.utils.tasks
import org.jetbrains.kotlin.spec.TestArea
import org.jetbrains.kotlin.spec.TestType
import org.jetbrains.kotlin.spec.generators.templates.Feature
import org.jetbrains.kotlin.spec.generators.templates.generationLinkedSpecTestDataConfig
import org.jetbrains.kotlin.spec.generators.templates.generationSpecTestDataConfigGroup
import org.jetbrains.kotlin.spec.utils.TestArea
import org.jetbrains.kotlin.spec.utils.TestType
import org.jetbrains.kotlin.spec.utils.generators.templates.Feature
import org.jetbrains.kotlin.spec.utils.generators.templates.generationLinkedSpecTestDataConfig
import org.jetbrains.kotlin.spec.utils.generators.templates.generationSpecTestDataConfigGroup
fun main() {
generationSpecTestDataConfigGroup(regenerateTests = true) {
generationLinkedSpecTestDataConfig {
testArea = TestArea.PSI
testType = TestType.NEGATIVE
sections = listOf("constant-literals", "boolean-literals")
sections = listOf("expressions", "constant-literals", "boolean-literals")
paragraphNumber = 1
sentenceNumber = 2
sentence = "These are strong keywords which cannot be used as identifiers unless escaped."
@@ -27,7 +27,7 @@ fun main() {
generationLinkedSpecTestDataConfig {
testArea = TestArea.PSI
testType = TestType.POSITIVE
sections = listOf("constant-literals", "boolean-literals")
sections = listOf("expressions", "constant-literals", "boolean-literals")
paragraphNumber = 1
sentenceNumber = 2
sentence = "These are strong keywords which cannot be used as identifiers unless escaped."
@@ -38,7 +38,7 @@ fun main() {
generationLinkedSpecTestDataConfig {
testArea = TestArea.CODEGEN_BOX
testType = TestType.POSITIVE
sections = listOf("constant-literals", "boolean-literals")
sections = listOf("expressions", "constant-literals", "boolean-literals")
paragraphNumber = 1
sentenceNumber = 2
sentence = "These are strong keywords which cannot be used as identifiers unless escaped."
@@ -0,0 +1,102 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.GsonBuilder
import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import org.jetbrains.kotlin.generators.tests.generator.testGroup
import org.jetbrains.kotlin.spec.checkers.AbstractDiagnosticsTestSpec
import org.jetbrains.kotlin.spec.codegen.AbstractBlackBoxCodegenTestSpec
import org.jetbrains.kotlin.spec.parsing.AbstractParsingTestSpec
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TEST_PATH
import org.jetbrains.kotlin.spec.utils.TestArea
import org.jetbrains.kotlin.spec.utils.TestType
import org.jetbrains.kotlin.spec.utils.models.LinkedSpecTest
import org.jetbrains.kotlin.spec.utils.models.SpecPlace
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser
import java.io.File
private object TestsMapGenerator {
private const val LINKED_TESTS_PATH = "linked"
private const val TESTS_MAP_FILENAME = "testsMap.json"
private inline fun <reified T : JsonElement> JsonObject.getOrCreate(key: String): T {
if (!has(key)) {
add(key, T::class.java.newInstance())
}
return get(key) as T
}
private fun JsonObject.getOrCreateSpecTestObject(specPlace: SpecPlace, testArea: TestArea, testType: TestType): JsonArray {
val sections = "${testArea.testDataPath}/$LINKED_TESTS_PATH/${specPlace.sections.joinToString("/")}"
val testsBySection = getOrCreate<JsonObject>(sections)
val testsByParagraph = testsBySection.getOrCreate<JsonObject>(specPlace.paragraphNumber.toString())
val testsByType = testsByParagraph.getOrCreate<JsonObject>(testType.type)
return testsByType.getOrCreate(specPlace.sentenceNumber.toString())
}
private fun getTestInfo(test: LinkedSpecTest) =
JsonObject().apply {
addProperty("specVersion", test.specVersion)
addProperty("casesNumber", test.cases.byNumbers.size)
addProperty("description", test.description)
addProperty(
"unexpectedBehaviour",
test.unexpectedBehavior || test.cases.byNumbers.any { it.value.unexpectedBehavior }
)
}
fun buildTestsMapPerSection() {
val testsMap = JsonObject()
TestArea.values().forEach { testArea ->
File("$TESTDATA_PATH/${testArea.testDataPath}/$LINKED_TESTS_PATH").walkTopDown().forEach testFiles@ { file ->
if (!file.isFile || file.extension != "kt") return@testFiles
val (specTest, _) = CommonParser.parseSpecTest(file.canonicalPath, mapOf("main.kt" to file.readText()))
if (specTest is LinkedSpecTest) {
val testInfo = getTestInfo(specTest)
testsMap.getOrCreateSpecTestObject(specTest.place, specTest.testArea, specTest.testType).add(testInfo)
specTest.relevantPlaces?.forEach {
testsMap.getOrCreateSpecTestObject(it, specTest.testArea, specTest.testType).add(testInfo)
}
}
}
}
val gson = GsonBuilder().setPrettyPrinting().create()
testsMap.keySet().forEach { testPath ->
File("$TESTDATA_PATH/$testPath/$TESTS_MAP_FILENAME").writeText(gson.toJson(testsMap.get(testPath)))
}
}
}
fun generateTests() {
testGroup(TEST_PATH, TESTDATA_PATH) {
testClass<AbstractDiagnosticsTestSpec> {
model("diagnostics", excludeDirs = listOf("helpers"))
}
testClass<AbstractParsingTestSpec> {
model("psi", testMethod = "doParsingTest", excludeDirs = listOf("helpers", "templates"))
}
testClass<AbstractBlackBoxCodegenTestSpec> {
model("codegen/box", excludeDirs = listOf("helpers", "templates"))
}
}
}
fun main() {
TestsMapGenerator.buildTestsMapPerSection()
generateTests()
}
@@ -1,11 +1,11 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.tasks
package org.jetbrains.kotlin.spec.utils.tasks
import org.jetbrains.kotlin.spec.SpecTestLinkedType
import org.jetbrains.kotlin.spec.utils.SpecTestLinkedType
import org.jetbrains.kotlin.spec.utils.SpecTestsStatElement
import org.jetbrains.kotlin.spec.utils.SpecTestsStatElementType
import org.jetbrains.kotlin.spec.utils.TestsStatisticCollector
@@ -1,14 +1,14 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.validators
package org.jetbrains.kotlin.spec.utils.validators
import org.jetbrains.kotlin.spec.models.AbstractSpecTest
import org.jetbrains.kotlin.spec.SpecTestLinkedType
import org.jetbrains.kotlin.spec.TestType
import org.jetbrains.kotlin.spec.parsers.CommonPatterns
import org.jetbrains.kotlin.spec.utils.SpecTestLinkedType
import org.jetbrains.kotlin.spec.utils.TestType
import org.jetbrains.kotlin.spec.utils.models.AbstractSpecTest
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns
import java.io.File
enum class SpecTestValidationFailedReason(val description: String) {
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.validators
import org.jetbrains.kotlin.spec.utils.models.AbstractSpecTest
import java.io.File
class BlackBoxTestTypeValidator(
testDataFile: File,
private val testInfo: AbstractSpecTest
) : AbstractTestValidator(testInfo, testDataFile) {
override fun computeTestTypes() = mapOf(1 to testInfo.testType)
}
@@ -1,16 +1,16 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.validators
package org.jetbrains.kotlin.spec.utils.validators
import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.spec.models.AbstractSpecTest
import org.jetbrains.kotlin.spec.TestCasesByNumbers
import org.jetbrains.kotlin.spec.TestType
import org.jetbrains.kotlin.spec.utils.TestCasesByNumbers
import org.jetbrains.kotlin.spec.utils.TestType
import org.jetbrains.kotlin.spec.utils.models.AbstractSpecTest
import java.io.File
class DiagnosticTestTypeValidator(
@@ -1,15 +1,15 @@
/*
* Copyright 2010-2018 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.
* Copyright 2010-2019 JetBrains s.r.o. 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.validators
package org.jetbrains.kotlin.spec.utils.validators
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiErrorElement
import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.spec.TestType
import org.jetbrains.kotlin.spec.models.AbstractSpecTest
import org.jetbrains.kotlin.spec.utils.TestType
import org.jetbrains.kotlin.spec.utils.models.AbstractSpecTest
import java.io.File
class ParsingTestTypeValidator(
@@ -1,16 +0,0 @@
/*
* Copyright 2010-2018 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.validators
import org.jetbrains.kotlin.spec.models.AbstractSpecTest
import java.io.File
class BlackBoxTestTypeValidator(
testDataFile: File,
private val testInfo: AbstractSpecTest
) : AbstractTestValidator(testInfo, testDataFile) {
override fun computeTestTypes() = mapOf(1 to testInfo.testType)
}