[Spec tests] Fix mistakes during parsing compiler tests to extract spec links

This commit is contained in:
Victor Petukhov
2020-03-30 15:55:14 +03:00
parent d1fc6ff6ee
commit c8206c4666
5 changed files with 24 additions and 34 deletions
@@ -25,7 +25,7 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes
} }
public void testAllFilesPresentInBox() throws Exception { public void testAllFilesPresentInBox() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, true, "helpers", "templates", "linked/overload-resolution/building-the-overload-candidate-set-ocs/call-with-an-explicit-receiver"); KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, true, "helpers", "templates", "linked/type-inference", "linked/expressions/when-expression/exhaustive-when-expressions", "linked/overload-resolution/building-the-overload-candidate-set-ocs/call-with-an-explicit-receiver");
} }
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked") @TestMetadata("compiler/tests-spec/testData/codegen/box/linked")
@@ -37,7 +37,7 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes
} }
public void testAllFilesPresentInLinked() throws Exception { public void testAllFilesPresentInLinked() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked"), Pattern.compile("^(.+)\\.kt$"), null, true, "overload-resolution/building-the-overload-candidate-set-ocs/call-with-an-explicit-receiver"); KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked"), Pattern.compile("^(.+)\\.kt$"), null, true, "type-inference", "expressions/when-expression/exhaustive-when-expressions", "overload-resolution/building-the-overload-candidate-set-ocs/call-with-an-explicit-receiver");
} }
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions") @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions")
@@ -49,7 +49,7 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes
} }
public void testAllFilesPresentInExpressions() throws Exception { public void testAllFilesPresentInExpressions() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions"), Pattern.compile("^(.+)\\.kt$"), null, true); KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions"), Pattern.compile("^(.+)\\.kt$"), null, true, "when-expression/exhaustive-when-expressions");
} }
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/additive-expression") @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/additive-expression")
@@ -3160,7 +3160,7 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes
} }
public void testAllFilesPresentInWhen_expression() throws Exception { public void testAllFilesPresentInWhen_expression() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/when-expression"), Pattern.compile("^(.+)\\.kt$"), null, true); KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/when-expression"), Pattern.compile("^(.+)\\.kt$"), null, true, "exhaustive-when-expressions");
} }
@TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/when-expression/p-4") @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/when-expression/p-4")
@@ -25,7 +25,7 @@ public class ParsingTestSpecGenerated extends AbstractParsingTestSpec {
} }
public void testAllFilesPresentInPsi() throws Exception { public void testAllFilesPresentInPsi() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/psi"), Pattern.compile("^(.+)\\.kt$"), null, true, "helpers", "templates"); KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/psi"), Pattern.compile("^(.+)\\.kt$"), null, true, "helpers", "templates", "linked/type-inference", "linked/expressions/when-expression/exhaustive-when-expressions");
} }
@TestMetadata("compiler/tests-spec/testData/psi/linked") @TestMetadata("compiler/tests-spec/testData/psi/linked")
@@ -37,7 +37,7 @@ public class ParsingTestSpecGenerated extends AbstractParsingTestSpec {
} }
public void testAllFilesPresentInLinked() throws Exception { public void testAllFilesPresentInLinked() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/psi/linked"), Pattern.compile("^(.+)\\.kt$"), null, true); KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/psi/linked"), Pattern.compile("^(.+)\\.kt$"), null, true, "type-inference", "expressions/when-expression/exhaustive-when-expressions");
} }
@TestMetadata("compiler/tests-spec/testData/psi/linked/expressions") @TestMetadata("compiler/tests-spec/testData/psi/linked/expressions")
@@ -49,7 +49,7 @@ public class ParsingTestSpecGenerated extends AbstractParsingTestSpec {
} }
public void testAllFilesPresentInExpressions() throws Exception { public void testAllFilesPresentInExpressions() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/psi/linked/expressions"), Pattern.compile("^(.+)\\.kt$"), null, true); KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/psi/linked/expressions"), Pattern.compile("^(.+)\\.kt$"), null, true, "when-expression/exhaustive-when-expressions");
} }
@TestMetadata("compiler/tests-spec/testData/psi/linked/expressions/constant-literals") @TestMetadata("compiler/tests-spec/testData/psi/linked/expressions/constant-literals")
@@ -981,7 +981,7 @@ public class ParsingTestSpecGenerated extends AbstractParsingTestSpec {
} }
public void testAllFilesPresentInWhen_expression() throws Exception { public void testAllFilesPresentInWhen_expression() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/psi/linked/expressions/when-expression"), Pattern.compile("^(.+)\\.kt$"), null, true); KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/psi/linked/expressions/when-expression"), Pattern.compile("^(.+)\\.kt$"), null, true, "exhaustive-when-expressions");
} }
@TestMetadata("compiler/tests-spec/testData/psi/linked/expressions/when-expression/p-1") @TestMetadata("compiler/tests-spec/testData/psi/linked/expressions/when-expression/p-1")
@@ -10,11 +10,9 @@ import com.google.gson.JsonArray
import com.google.gson.JsonElement import com.google.gson.JsonElement
import com.google.gson.JsonObject import com.google.gson.JsonObject
import org.jetbrains.kotlin.spec.utils.models.LinkedSpecTest 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.models.SpecPlace
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser import org.jetbrains.kotlin.spec.utils.parsers.CommonParser
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.parseImplementationTest import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.parseImplementationTest
import org.jetbrains.kotlin.spec.utils.parsers.ImplementationTestPatterns
import java.io.File import java.io.File
object TestsJsonMapGenerator { object TestsJsonMapGenerator {
@@ -49,9 +47,7 @@ object TestsJsonMapGenerator {
) )
} }
private fun collectInfoFromSpecTests(): JsonObject { private fun collectInfoFromSpecTests(testsMap: JsonObject) {
val testsMap = JsonObject()
TestArea.values().forEach { testArea -> TestArea.values().forEach { testArea ->
File("${GeneralConfiguration.SPEC_TESTDATA_PATH}/${testArea.testDataPath}/$LINKED_TESTS_PATH").walkTopDown() File("${GeneralConfiguration.SPEC_TESTDATA_PATH}/${testArea.testDataPath}/$LINKED_TESTS_PATH").walkTopDown()
.forEach testFiles@{ file -> .forEach testFiles@{ file ->
@@ -71,41 +67,35 @@ object TestsJsonMapGenerator {
} }
} }
} }
return testsMap
} }
private fun collectInfoFromImplementationTests(): JsonObject { private fun collectInfoFromImplementationTests(testsMap: JsonObject) {
val testsMap = JsonObject()
TestArea.values().forEach { testArea -> TestArea.values().forEach { testArea ->
val files = File("${GeneralConfiguration.TESTDATA_PATH}/${testArea.testDataPath}").walkTopDown() val files = File("${GeneralConfiguration.TESTDATA_PATH}/${testArea.testDataPath}").walkTopDown()
for (file in files) { for (file in files) {
if (!file.isFile || file.extension != "kt") continue if (!file.isFile || file.extension != "kt") continue
val parserImplementationTest = parseImplementationTest(file, testArea) val parsedImplementationTest = parseImplementationTest(file, testArea) ?: continue
val relevantPlaces = parserImplementationTest.relevantPlaces ?: listOf() val relevantPlaces = parsedImplementationTest.relevantPlaces ?: listOf()
(relevantPlaces + parserImplementationTest.place).forEach { specPlace -> (relevantPlaces + parsedImplementationTest.place).forEach specPlaces@ { specPlace ->
testsMap.getOrCreateSpecTestObject(specPlace, testArea, parserImplementationTest.testType).add( val parsedAdditionalImplementationTest = parseImplementationTest(file, testArea) ?: return@specPlaces
getTestInfo(parseImplementationTest(file, testArea), file)
testsMap.getOrCreateSpecTestObject(specPlace, testArea, parsedImplementationTest.testType).add(
getTestInfo(parsedAdditionalImplementationTest, file)
) )
} }
} }
} }
return testsMap
} }
operator fun JsonObject.plus(other: JsonObject) = fun buildTestsMapPerSection() {
JsonObject().also { new -> val testsMap = JsonObject().apply {
this.keySet().forEach { new.add(it, this.get(it)) } collectInfoFromSpecTests(this)
other.keySet().forEach { new.add(it, other.get(it)) } collectInfoFromImplementationTests(this)
} }
fun buildTestsMapPerSection() {
val testsMap = collectInfoFromSpecTests() + collectInfoFromImplementationTests()
val gson = GsonBuilder().setPrettyPrinting().create() val gson = GsonBuilder().setPrettyPrinting().create()
testsMap.keySet().forEach { testPath -> testsMap.keySet().forEach { testPath ->
@@ -63,7 +63,7 @@ class LinkedSpecTest(
return LinkedSpecTest( return LinkedSpecTest(
specVersion, testArea, testType, specPlaces.first(), specVersion, testArea, testType, specPlaces.first(),
specPlaces.subList(1, specPlaces.size - 1), 0, description, if (specPlaces.size > 1) specPlaces.subList(1, specPlaces.size) else null, 0, description,
SpecTestCasesSet(mutableMapOf(), mutableMapOf(), mutableMapOf()), SpecTestCasesSet(mutableMapOf(), mutableMapOf(), mutableMapOf()),
unexpectedBehavior = false, unspecifiedBehavior = false, issues = setOf(), helpers = null, exception = null unexpectedBehavior = false, unspecifiedBehavior = false, issues = setOf(), helpers = null, exception = null
) )
@@ -44,11 +44,11 @@ object CommonParser {
throw SpecTestValidationException(SpecTestValidationFailedReason.FILENAME_NOT_VALID) throw SpecTestValidationException(SpecTestValidationFailedReason.FILENAME_NOT_VALID)
} }
fun parseImplementationTest(file: File, testArea: TestArea): LinkedSpecTest { fun parseImplementationTest(file: File, testArea: TestArea): LinkedSpecTest? {
val matcher = ImplementationTestPatterns.testInfoPattern.matcher(file.readText()) val matcher = ImplementationTestPatterns.testInfoPattern.matcher(file.readText())
if (!matcher.find()) if (!matcher.find())
throw SpecTestValidationException(SpecTestValidationFailedReason.TESTINFO_NOT_VALID) return null
val testType = TestType.fromValue(matcher.group("testType")) val testType = TestType.fromValue(matcher.group("testType"))
?: throw SpecTestValidationException(SpecTestValidationFailedReason.TESTINFO_NOT_VALID) ?: throw SpecTestValidationException(SpecTestValidationFailedReason.TESTINFO_NOT_VALID)