[Spec tests] Link diagnostic tests for when expression with Kotlin specification
This commit is contained in:
committed by
Victor Petukhov
parent
c338fdd677
commit
2dbce2cc41
+2
-2
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.spec.codegen
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.TestExceptionsComparator
|
||||
import org.jetbrains.kotlin.codegen.AbstractBlackBoxCodegenTest
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.SPEC_TESTDATA_PATH
|
||||
import org.jetbrains.kotlin.spec.utils.models.AbstractSpecTest
|
||||
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser
|
||||
import org.jetbrains.kotlin.spec.utils.parsers.CommonPatterns.packagePattern
|
||||
@@ -19,7 +19,7 @@ import java.io.*
|
||||
|
||||
abstract class AbstractBlackBoxCodegenTestSpec : AbstractBlackBoxCodegenTest() {
|
||||
companion object {
|
||||
private const val CODEGEN_BOX_TESTDATA_PATH = "$TESTDATA_PATH/codegen/box"
|
||||
private const val CODEGEN_BOX_TESTDATA_PATH = "$SPEC_TESTDATA_PATH/codegen/box"
|
||||
private const val HELPERS_PATH = "$CODEGEN_BOX_TESTDATA_PATH/helpers"
|
||||
private const val HELPERS_PACKAGE_VARIABLE = "<!PACKAGE!>"
|
||||
}
|
||||
|
||||
+3
-3
@@ -37,11 +37,11 @@ class SpecTestsConsistencyTest : TestCase() {
|
||||
|
||||
TestArea.values().forEach { testArea ->
|
||||
val testDataPath =
|
||||
"${GeneralConfiguration.TESTDATA_PATH}/${testArea.testDataPath}/${SpecTestLinkedType.LINKED.testDataPath}"
|
||||
"${GeneralConfiguration.SPEC_TESTDATA_PATH}/${testArea.testDataPath}/${SpecTestLinkedType.LINKED.testDataPath}"
|
||||
|
||||
testFiles += File(testDataPath).let { testsDir ->
|
||||
testsDir.walkTopDown().filter { it.extension == "kt" }.map {
|
||||
arrayOf(it.relativeTo(File(GeneralConfiguration.TESTDATA_PATH)).path.replace("/", "$"))
|
||||
arrayOf(it.relativeTo(File(GeneralConfiguration.SPEC_TESTDATA_PATH)).path.replace("/", "$"))
|
||||
}.toList()
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class SpecTestsConsistencyTest : TestCase() {
|
||||
|
||||
@Test
|
||||
fun doTest() {
|
||||
val file = File("${GeneralConfiguration.TESTDATA_PATH}/${testFilePath.replace("$", "/")}")
|
||||
val file = File("${GeneralConfiguration.SPEC_TESTDATA_PATH}/${testFilePath.replace("$", "/")}")
|
||||
val specSentences = specSentencesStorage.getLatest() ?: return
|
||||
val test = parseLinkedSpecTest(file.canonicalPath, mapOf("main" to file.readText()))
|
||||
val sectionsPath = setOf(*test.place.sections.toTypedArray(), test.place.paragraphNumber).joinToString()
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
package org.jetbrains.kotlin.spec.utils
|
||||
|
||||
object GeneralConfiguration {
|
||||
const val MODULE_PATH = "compiler/tests-spec"
|
||||
const val TESTDATA_PATH = "$MODULE_PATH/testData"
|
||||
const val TEST_PATH = "$MODULE_PATH/tests"
|
||||
const val TESTDATA_PATH = "compiler/testData"
|
||||
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"
|
||||
}
|
||||
|
||||
@@ -10,13 +10,17 @@ import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import org.jetbrains.kotlin.spec.utils.models.LinkedSpecTest
|
||||
import org.jetbrains.kotlin.spec.utils.models.LinkedSpecTest.Companion.getInstanceForImplementationTest
|
||||
import org.jetbrains.kotlin.spec.utils.models.SpecPlace
|
||||
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser
|
||||
import org.jetbrains.kotlin.spec.utils.parsers.ImplementationTestPatterns
|
||||
import java.io.File
|
||||
|
||||
object TestsJsonMapGenerator {
|
||||
private const val LINKED_TESTS_PATH = "linked"
|
||||
private const val TESTS_MAP_FILENAME = "testsMap.json"
|
||||
const val TESTS_MAP_FILENAME = "testsMap.json"
|
||||
|
||||
private val testsMap = JsonObject()
|
||||
|
||||
private inline fun <reified T : JsonElement> JsonObject.getOrCreate(key: String): T {
|
||||
if (!has(key)) {
|
||||
@@ -46,11 +50,9 @@ object TestsJsonMapGenerator {
|
||||
)
|
||||
}
|
||||
|
||||
fun buildTestsMapPerSection() {
|
||||
val testsMap = JsonObject()
|
||||
|
||||
private fun collectInfoFromSpecTests() {
|
||||
TestArea.values().forEach { testArea ->
|
||||
File("${GeneralConfiguration.TESTDATA_PATH}/${testArea.testDataPath}/$LINKED_TESTS_PATH").walkTopDown()
|
||||
File("${GeneralConfiguration.SPEC_TESTDATA_PATH}/${testArea.testDataPath}/$LINKED_TESTS_PATH").walkTopDown()
|
||||
.forEach testFiles@{ file ->
|
||||
if (!file.isFile || file.extension != "kt") return@testFiles
|
||||
|
||||
@@ -68,11 +70,57 @@ object TestsJsonMapGenerator {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun collectInfoFromImplementationTests() {
|
||||
TestArea.values().forEach { testArea ->
|
||||
File("${GeneralConfiguration.TESTDATA_PATH}/${testArea.testDataPath}").walkTopDown()
|
||||
.forEach testFiles@{ file ->
|
||||
if (!file.isFile || file.extension != "kt") return@testFiles
|
||||
|
||||
val matcher = ImplementationTestPatterns.testInfoPattern.matcher(file.readText())
|
||||
|
||||
if (!matcher.find()) return@testFiles
|
||||
|
||||
val specVersion = matcher.group("specVersion")
|
||||
val testType = TestType.fromValue(matcher.group("testType"))!!
|
||||
val testSpecSentenceList = matcher.group("testSpecSentenceList")
|
||||
val specSentenceListMatcher = ImplementationTestPatterns.relevantSpecSentencesPattern.matcher(testSpecSentenceList)
|
||||
val specPlaces = mutableSetOf<SpecPlace>()
|
||||
|
||||
while (specSentenceListMatcher.find()) {
|
||||
specPlaces.add(
|
||||
SpecPlace(
|
||||
sections = specSentenceListMatcher.group("specSections").split(Regex(""",\s*""")),
|
||||
paragraphNumber = specSentenceListMatcher.group("specParagraph").toInt(),
|
||||
sentenceNumber = specSentenceListMatcher.group("specSentence").toInt()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
specPlaces.forEach { specPlace ->
|
||||
testsMap.getOrCreateSpecTestObject(specPlace, testArea, testType).add(
|
||||
getTestInfo(
|
||||
getInstanceForImplementationTest(specVersion, testArea, testType, specPlace, file.nameWithoutExtension),
|
||||
file
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun buildTestsMapPerSection() {
|
||||
collectInfoFromSpecTests()
|
||||
collectInfoFromImplementationTests()
|
||||
|
||||
val gson = GsonBuilder().setPrettyPrinting().create()
|
||||
|
||||
testsMap.keySet().forEach { testPath ->
|
||||
File("${GeneralConfiguration.TESTDATA_PATH}/$testPath/$TESTS_MAP_FILENAME").writeText(gson.toJson(testsMap.get(testPath)))
|
||||
val testMapFolder = "${GeneralConfiguration.SPEC_TESTDATA_PATH}/$testPath"
|
||||
|
||||
File(testMapFolder).mkdirs()
|
||||
File("$testMapFolder/$TESTS_MAP_FILENAME").writeText(gson.toJson(testsMap.get(testPath)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.spec.utils
|
||||
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.SPEC_TESTDATA_PATH
|
||||
import org.jetbrains.kotlin.spec.utils.models.AbstractSpecTest
|
||||
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser
|
||||
import java.io.File
|
||||
@@ -43,7 +43,7 @@ object TestsStatisticCollector {
|
||||
val statistic = mutableMapOf<TestArea, SpecTestsStatElement>()
|
||||
|
||||
for (specTestArea in TestArea.values()) {
|
||||
val specTestsPath = "$TESTDATA_PATH/${specTestArea.name.toLowerCase().replace("_", "/")}/${testLinkedType.testDataPath}"
|
||||
val specTestsPath = "$SPEC_TESTDATA_PATH/${specTestArea.name.toLowerCase().replace("_", "/")}/${testLinkedType.testDataPath}"
|
||||
|
||||
statistic[specTestArea] =
|
||||
SpecTestsStatElement(SpecTestsStatElementType.AREA)
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.spec.utils.generators.templates
|
||||
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.SPEC_TESTDATA_PATH
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -78,8 +78,8 @@ class FeatureInteractionTestDataGenerator(private val configuration: GenerationS
|
||||
|
||||
fun generate() {
|
||||
var testNumber = 1
|
||||
val testsPartPath = "$TESTDATA_PATH/${configuration.getTestsPartPath()}"
|
||||
val layoutTemplate = File("$TESTDATA_PATH/${configuration.getLayoutPath()}").readText()
|
||||
val testsPartPath = "$SPEC_TESTDATA_PATH/${configuration.getTestsPartPath()}"
|
||||
val layoutTemplate = File("$SPEC_TESTDATA_PATH/${configuration.getLayoutPath()}").readText()
|
||||
|
||||
File(testsPartPath).parentFile.mkdirs()
|
||||
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.spec.utils.generators.templates
|
||||
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.SPEC_TESTDATA_PATH
|
||||
import org.jetbrains.kotlin.spec.utils.TestArea
|
||||
import java.io.File
|
||||
|
||||
@@ -24,7 +24,7 @@ class FeatureTemplatesConfig(
|
||||
var currentTemplatesIterator = getTemplatesIterator()
|
||||
|
||||
private fun getTemplatesPath(testArea: TestArea) = buildString {
|
||||
append(TESTDATA_PATH)
|
||||
append(SPEC_TESTDATA_PATH)
|
||||
append("/${testArea.testDataPath}")
|
||||
append("/${FeatureInteractionTestDataGenerator.TEMPLATES_PATH}")
|
||||
append("/$templatesPath")
|
||||
|
||||
@@ -50,6 +50,26 @@ class LinkedSpecTest(
|
||||
helpers: Set<String>?,
|
||||
exception: TestsExceptionType?
|
||||
) : AbstractSpecTest(testArea, testType, place.sections, testNumber, description, cases, unexpectedBehavior, issues, helpers, exception) {
|
||||
companion object {
|
||||
fun getInstanceForImplementationTest(
|
||||
specVersion: String,
|
||||
testArea: TestArea,
|
||||
testType: TestType,
|
||||
specPlace: SpecPlace,
|
||||
filename: String
|
||||
): LinkedSpecTest {
|
||||
val description = filename[0].toUpperCase() +
|
||||
filename.substring(1).replace(Regex("""([A-Z])"""), " $1").toLowerCase()
|
||||
|
||||
return LinkedSpecTest(
|
||||
specVersion, testArea, testType, specPlace,
|
||||
null, 0, description,
|
||||
SpecTestCasesSet(mutableMapOf(), mutableMapOf(), mutableMapOf()),
|
||||
unexpectedBehavior = false, unspecifiedBehavior = false, issues = setOf(), helpers = null, exception = null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun checkPathConsistency(pathMatcher: Matcher) =
|
||||
testArea == TestArea.valueOf(pathMatcher.group("testArea").withUnderscores())
|
||||
&& testType == TestType.fromValue(pathMatcher.group("testType"))!!
|
||||
|
||||
@@ -65,7 +65,7 @@ object NotLinkedSpecTestPatterns : BasePatterns {
|
||||
}
|
||||
|
||||
object LinkedSpecTestPatterns : BasePatterns {
|
||||
const val FILENAME_REGEX = """(?<sentenceNumber>$INTEGER_REGEX)\.(?<testNumber>$INTEGER_REGEX)\.kt"""
|
||||
private const val FILENAME_REGEX = """(?<sentenceNumber>$INTEGER_REGEX)\.(?<testNumber>$INTEGER_REGEX)\.kt"""
|
||||
|
||||
override val pathPartRegex =
|
||||
"""${SpecTestLinkedType.LINKED.testDataPath}$ps$sectionsInPathRegex${ps}p-(?<paragraphNumber>$INTEGER_REGEX)"""
|
||||
@@ -98,3 +98,10 @@ object TestCasePatterns {
|
||||
val testCaseInfoPattern: Pattern = Pattern.compile("(?:$testCaseInfoSingleLineRegex)|(?:$testCaseInfoMultilineRegex)")
|
||||
val testCaseNumberPattern: Pattern = Pattern.compile("""([1-9]\d*)(,\s*[1-9]\d*)*""")
|
||||
}
|
||||
|
||||
object ImplementationTestPatterns {
|
||||
val testInfoPattern: Pattern =
|
||||
Pattern.compile(MULTILINE_COMMENT_REGEX.format("""\*\s+RELEVANT SPEC SENTENCES \(spec version: (?<specVersion>\d+\.[0-9]\d*\-[0-9]\d*), test type: (?<testType>pos|neg)\):(?<testSpecSentenceList>(\n\s+\*\s+-\s+.*?)+)"""))
|
||||
val relevantSpecSentencesPattern: Pattern =
|
||||
Pattern.compile("""\n\s+\*\s+-\s+(?<specSections>.*?) -> paragraph (?<specParagraph>[1-9]\d*) -> sentence (?<specSentence>[1-9]\d*)""")
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ object HtmlSpecLoader {
|
||||
private const val SPEC_DOCS_TC_CONFIGURATION_ID = "Kotlin_Spec_DocsMaster"
|
||||
private const val TC_URL = "https://teamcity.jetbrains.com"
|
||||
private const val TC_PATH_PREFIX = "guestAuth/app/rest/builds"
|
||||
private const val HTML_SPEC_PATH = "/web/kotlin-spec.html"
|
||||
private const val HTML_SPEC_PATH = "/html/kotlin-spec.html"
|
||||
private const val STABLE_BRANCH = "master"
|
||||
|
||||
private fun loadRawHtmlSpec(specVersion: String, buildNumber: String): String {
|
||||
|
||||
+31
-6
@@ -9,20 +9,45 @@ 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.GeneralConfiguration.SPEC_TESTDATA_PATH
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.SPEC_TEST_PATH
|
||||
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
|
||||
|
||||
fun detectDirsWithTestsMapFileOnly(dirName: String): List<String> {
|
||||
val excludedDirs = mutableListOf<String>()
|
||||
|
||||
File("$SPEC_TESTDATA_PATH/$dirName").walkTopDown().forEach { file ->
|
||||
val listFiles = Files.walk(file.toPath()).filter(Files::isRegularFile)
|
||||
|
||||
if (file.isDirectory && listFiles?.allMatch { it.endsWith(TESTS_MAP_FILENAME) } == true) {
|
||||
val relativePath = file.relativeTo(File("$SPEC_TESTDATA_PATH/$dirName")).path
|
||||
|
||||
if (!excludedDirs.any { relativePath.startsWith(it) }) {
|
||||
excludedDirs.add(relativePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return excludedDirs
|
||||
}
|
||||
|
||||
fun generateTests() {
|
||||
testGroup(TEST_PATH, TESTDATA_PATH) {
|
||||
testGroup(SPEC_TEST_PATH, SPEC_TESTDATA_PATH) {
|
||||
testClass<AbstractDiagnosticsTestSpec> {
|
||||
model("diagnostics", excludeDirs = listOf("helpers"))
|
||||
model("diagnostics", excludeDirs = listOf("helpers") + detectDirsWithTestsMapFileOnly("diagnostics"))
|
||||
}
|
||||
testClass<AbstractParsingTestSpec> {
|
||||
model("psi", testMethod = "doParsingTest", excludeDirs = listOf("helpers", "templates"))
|
||||
model(
|
||||
relativeRootPath = "psi",
|
||||
testMethod = "doParsingTest",
|
||||
excludeDirs = listOf("helpers", "templates") + detectDirsWithTestsMapFileOnly("psi")
|
||||
)
|
||||
}
|
||||
testClass<AbstractBlackBoxCodegenTestSpec> {
|
||||
model("codegen/box", excludeDirs = listOf("helpers", "templates"))
|
||||
model("codegen/box", excludeDirs = listOf("helpers", "templates") + detectDirsWithTestsMapFileOnly("codegen/box"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user