[Spec tests] Actualize spec tests

This commit is contained in:
victor.petukhov
2019-10-24 16:57:09 +03:00
committed by Victor Petukhov
parent 2dbce2cc41
commit f62901d7d9
106 changed files with 776 additions and 458 deletions
@@ -3185,6 +3185,16 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/neg/11.1.kt");
}
@TestMetadata("11.2.kt")
public void test11_2() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/neg/11.2.kt");
}
@TestMetadata("12.1.kt")
public void test12_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/neg/12.1.kt");
}
@TestMetadata("1.1.kt")
public void test1_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/neg/1.1.kt");
@@ -3205,19 +3215,9 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/neg/3.2.kt");
}
@TestMetadata("6.1.kt")
public void test6_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/neg/6.1.kt");
}
@TestMetadata("9.1.kt")
public void test9_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/neg/9.1.kt");
}
@TestMetadata("9.2.kt")
public void test9_2() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/neg/9.2.kt");
@TestMetadata("7.1.kt")
public void test7_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/neg/7.1.kt");
}
public void testAllFilesPresentInNeg() throws Exception {
@@ -3233,9 +3233,19 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("11.1.kt")
public void test11_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/11.1.kt");
@TestMetadata("10.1.kt")
public void test10_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/10.1.kt");
}
@TestMetadata("10.2.kt")
public void test10_2() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/10.2.kt");
}
@TestMetadata("12.1.kt")
public void test12_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/12.1.kt");
}
@TestMetadata("1.1.kt")
@@ -3268,19 +3278,9 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/3.2.kt");
}
@TestMetadata("6.1.kt")
public void test6_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/6.1.kt");
}
@TestMetadata("9.1.kt")
public void test9_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/9.1.kt");
}
@TestMetadata("9.2.kt")
public void test9_2() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/9.2.kt");
@TestMetadata("7.1.kt")
public void test7_1() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/7.1.kt");
}
public void testAllFilesPresentInPos() throws Exception {
@@ -65,7 +65,7 @@ class SpecTestsConsistencyTest : TestCase() {
val paragraphForTestSentences =
specSentencesForCurrentTest[sectionsPath] ?: throw Exception("$sectionsPath not found")
if (paragraphForTestSentences.size < sentenceNumber) {
throw Exception("$sentenceNumber not found")
fail("Sentence #$sentenceNumber not found (${file.path})")
}
val expectedSentence = paragraphForTestSentences[sentenceNumber - 1]
val actualSentence = paragraphSentences[sentenceNumber - 1]
@@ -18,7 +18,7 @@ abstract class AbstractParsingTestSpec : AbstractParsingTest() {
override fun doParsingTest(filePath: String) {
val file = File(filePath)
val (specTest, testLinkedType) = CommonParser.parseSpecTest(
filePath,
file.canonicalPath,
mapOf("main.kt" to FileUtil.loadFile(file, true))
)
@@ -1150,9 +1150,9 @@ public class ParsingTestSpecGenerated extends AbstractParsingTestSpec {
KotlinTestUtils.runTest(this::doParsingTest, this, testDataFilePath);
}
@TestMetadata("11.1.kt")
public void test11_1() throws Exception {
runTest("compiler/tests-spec/testData/psi/linked/expressions/when-expression/p-6/neg/11.1.kt");
@TestMetadata("12.1.kt")
public void test12_1() throws Exception {
runTest("compiler/tests-spec/testData/psi/linked/expressions/when-expression/p-6/neg/12.1.kt");
}
@TestMetadata("1.1.kt")
@@ -1170,9 +1170,9 @@ public class ParsingTestSpecGenerated extends AbstractParsingTestSpec {
runTest("compiler/tests-spec/testData/psi/linked/expressions/when-expression/p-6/neg/3.1.kt");
}
@TestMetadata("8.1.kt")
public void test8_1() throws Exception {
runTest("compiler/tests-spec/testData/psi/linked/expressions/when-expression/p-6/neg/8.1.kt");
@TestMetadata("9.1.kt")
public void test9_1() throws Exception {
runTest("compiler/tests-spec/testData/psi/linked/expressions/when-expression/p-6/neg/9.1.kt");
}
public void testAllFilesPresentInNeg() throws Exception {
@@ -13,6 +13,7 @@ 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.CommonParser.parseImplementationTest
import org.jetbrains.kotlin.spec.utils.parsers.ImplementationTestPatterns
import java.io.File
@@ -20,8 +21,6 @@ object TestsJsonMapGenerator {
private const val LINKED_TESTS_PATH = "linked"
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)) {
add(key, T::class.java.newInstance())
@@ -50,7 +49,9 @@ object TestsJsonMapGenerator {
)
}
private fun collectInfoFromSpecTests() {
private fun collectInfoFromSpecTests(): JsonObject {
val testsMap = JsonObject()
TestArea.values().forEach { testArea ->
File("${GeneralConfiguration.SPEC_TESTDATA_PATH}/${testArea.testDataPath}/$LINKED_TESTS_PATH").walkTopDown()
.forEach testFiles@{ file ->
@@ -70,50 +71,41 @@ object TestsJsonMapGenerator {
}
}
}
return testsMap
}
private fun collectInfoFromImplementationTests() {
private fun collectInfoFromImplementationTests(): JsonObject {
val testsMap = JsonObject()
TestArea.values().forEach { testArea ->
File("${GeneralConfiguration.TESTDATA_PATH}/${testArea.testDataPath}").walkTopDown()
.forEach testFiles@{ file ->
if (!file.isFile || file.extension != "kt") return@testFiles
val files = File("${GeneralConfiguration.TESTDATA_PATH}/${testArea.testDataPath}").walkTopDown()
val matcher = ImplementationTestPatterns.testInfoPattern.matcher(file.readText())
for (file in files) {
if (!file.isFile || file.extension != "kt") continue
if (!matcher.find()) return@testFiles
val parserImplementationTest = parseImplementationTest(file, testArea)
val relevantPlaces = parserImplementationTest.relevantPlaces ?: listOf()
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
)
)
}
(relevantPlaces + parserImplementationTest.place).forEach { specPlace ->
testsMap.getOrCreateSpecTestObject(specPlace, testArea, parserImplementationTest.testType).add(
getTestInfo(parseImplementationTest(file, testArea), file)
)
}
}
}
return testsMap
}
operator fun JsonObject.plus(other: JsonObject) =
JsonObject().also { new ->
this.keySet().forEach { new.add(it, this.get(it)) }
other.keySet().forEach { new.add(it, other.get(it)) }
}
fun buildTestsMapPerSection() {
collectInfoFromSpecTests()
collectInfoFromImplementationTests()
val testsMap = collectInfoFromSpecTests() + collectInfoFromImplementationTests()
val gson = GsonBuilder().setPrettyPrinting().create()
testsMap.keySet().forEach { testPath ->
@@ -55,15 +55,15 @@ class LinkedSpecTest(
specVersion: String,
testArea: TestArea,
testType: TestType,
specPlace: SpecPlace,
specPlaces: List<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,
specVersion, testArea, testType, specPlaces.first(),
specPlaces.subList(1, specPlaces.size - 1), 0, description,
SpecTestCasesSet(mutableMapOf(), mutableMapOf(), mutableMapOf()),
unexpectedBehavior = false, unspecifiedBehavior = false, issues = setOf(), helpers = null, exception = null
)
@@ -5,10 +5,7 @@
package org.jetbrains.kotlin.spec.utils.parsers
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.*
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
@@ -47,6 +44,32 @@ object CommonParser {
throw SpecTestValidationException(SpecTestValidationFailedReason.FILENAME_NOT_VALID)
}
fun parseImplementationTest(file: File, testArea: TestArea): LinkedSpecTest {
val matcher = ImplementationTestPatterns.testInfoPattern.matcher(file.readText())
if (!matcher.find())
throw SpecTestValidationException(SpecTestValidationFailedReason.TESTINFO_NOT_VALID)
val testType = TestType.fromValue(matcher.group("testType"))
?: throw SpecTestValidationException(SpecTestValidationFailedReason.TESTINFO_NOT_VALID)
val specVersion = matcher.group("specVersion")
val testSpecSentenceList = matcher.group("testSpecSentenceList")
val specSentenceListMatcher = ImplementationTestPatterns.relevantSpecSentencesPattern.matcher(testSpecSentenceList)
val specPlaces = mutableListOf<SpecPlace>()
while (specSentenceListMatcher.find()) {
specPlaces.add(
SpecPlace(
sections = specSentenceListMatcher.group("specSections").split(Regex(""",\s*""")),
paragraphNumber = specSentenceListMatcher.group("specParagraph").toInt(),
sentenceNumber = specSentenceListMatcher.group("specSentence").toInt()
)
)
}
return LinkedSpecTest.getInstanceForImplementationTest(specVersion, testArea, testType, specPlaces, file.nameWithoutExtension)
}
private fun createSpecPlace(placeMatcher: Matcher, basePlaceMatcher: Matcher = placeMatcher) =
SpecPlace(
placeMatcher.group("sections")?.splitByComma() ?: basePlaceMatcher.group("sections").splitByComma(),