Alphabetical sort wrapped intersection types for rendered diagnostics
This commit is contained in:
+9
-22
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.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
|
||||
@@ -18,22 +19,9 @@ import org.jetbrains.kotlin.test.*
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
|
||||
abstract class AbstractDiagnosticsTestSpec : AbstractDiagnosticsTest() {
|
||||
companion object {
|
||||
// map of pairs: source helper filename - target helper filename
|
||||
private val directives = mapOf(
|
||||
"WITH_BASIC_TYPES" to "basicTypes.kt",
|
||||
"WITH_CLASSES" to "classes.kt",
|
||||
"WITH_ENUM_CLASSES" to "enumClasses.kt",
|
||||
"WITH_SEALED_CLASSES" to "sealedClasses.kt",
|
||||
"WITH_FUNCTIONS" to "functions.kt",
|
||||
"WITH_OBJECTS" to "objects.kt",
|
||||
"WITH_TYPEALIASES" to "typeAliases.kt",
|
||||
"WITH_CONTRACT_FUNCTIONS" to "contractFunctions.kt"
|
||||
)
|
||||
|
||||
private val withoutDescriptorsTestGroups = listOf(
|
||||
"linked/when-expression"
|
||||
)
|
||||
@@ -41,8 +29,6 @@ abstract class AbstractDiagnosticsTestSpec : AbstractDiagnosticsTest() {
|
||||
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"
|
||||
private val exceptionPattern =
|
||||
Pattern.compile("""Exception while analyzing expression at \((?<lineNumber>\d+),(?<symbolNumber>\d+)\) in /(?<filename>.*?)$""")
|
||||
}
|
||||
|
||||
lateinit var specTest: AbstractSpecTest
|
||||
@@ -67,13 +53,14 @@ abstract class AbstractDiagnosticsTestSpec : AbstractDiagnosticsTest() {
|
||||
override fun getKtFiles(testFiles: List<TestFile>, includeExtras: Boolean): List<KtFile> {
|
||||
val ktFiles = super.getKtFiles(testFiles, includeExtras) as ArrayList
|
||||
|
||||
if (includeExtras) {
|
||||
for ((name, filename) in directives) {
|
||||
if (checkDirective(name, testFiles)) {
|
||||
val declarations = File("$HELPERS_PATH/$filename").readText()
|
||||
ktFiles.add(KotlinTestUtils.createFile(filename, declarations, project))
|
||||
}
|
||||
}
|
||||
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
|
||||
|
||||
+11
-17
@@ -7,12 +7,12 @@ 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.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.junit.Assert
|
||||
import java.io.*
|
||||
|
||||
@@ -21,31 +21,25 @@ abstract class AbstractBlackBoxCodegenTestSpec : AbstractBlackBoxCodegenTest() {
|
||||
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 const val HELPERS_DIRECTIVE = "// HELPERS:"
|
||||
|
||||
// map of pairs: source helper filename - target helper filename
|
||||
private val helperDirectives = mapOf(
|
||||
"REFLECT" to "reflect.kt"
|
||||
)
|
||||
}
|
||||
|
||||
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>) {
|
||||
private fun includeHelpers(wholeFile: File, files: MutableList<TestFile>, specTest: AbstractSpecTest) {
|
||||
if (specTest.helpers == null) return
|
||||
|
||||
val fileContent = FileUtil.loadFile(wholeFile, true)
|
||||
val helpersSpecified = InTextDirectivesUtils.findListWithPrefixes(fileContent, HELPERS_DIRECTIVE)
|
||||
val packageName = packagePattern.matcher(fileContent).let {
|
||||
if (it.find()) it.group("packageName") else null
|
||||
}
|
||||
|
||||
helpersSpecified.forEach {
|
||||
if (helperDirectives.contains(it)) {
|
||||
val helperContent = FileUtil.loadFile(File("$HELPERS_PATH/${helperDirectives[it]}"), true)
|
||||
files.add(
|
||||
TestFile(helperDirectives[it]!!, addPackageDirectiveToHelperFile(helperContent, packageName))
|
||||
)
|
||||
}
|
||||
specTest.helpers.forEach {
|
||||
val filename = "$it.kt"
|
||||
val helperContent = FileUtil.loadFile(File("$HELPERS_PATH/$filename"), true)
|
||||
files.add(
|
||||
TestFile(filename, addPackageDirectiveToHelperFile(helperContent, packageName))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +59,7 @@ abstract class AbstractBlackBoxCodegenTestSpec : AbstractBlackBoxCodegenTest() {
|
||||
|
||||
println(specTest)
|
||||
|
||||
includeHelpers(wholeFile, files)
|
||||
includeHelpers(wholeFile, files, specTest)
|
||||
|
||||
TestExceptionsComparator(wholeFile).runAndCompareWithExpected {
|
||||
super.doMultiFileTest(wholeFile, files, javaFilesDir)
|
||||
|
||||
@@ -30,7 +30,8 @@ enum class CommonSpecTestFileInfoElementType(
|
||||
override val required: Boolean = false
|
||||
) : SpecTestInfoElementType {
|
||||
NUMBER(required = true),
|
||||
DESCRIPTION(required = true)
|
||||
DESCRIPTION(required = true),
|
||||
HELPERS
|
||||
}
|
||||
|
||||
enum class SpecTestCaseInfoElementType(
|
||||
@@ -49,7 +50,8 @@ abstract class AbstractSpecTest(
|
||||
val description: String,
|
||||
val cases: SpecTestCasesSet,
|
||||
val unexpectedBehavior: Boolean,
|
||||
val issues: Set<String>
|
||||
val issues: Set<String>,
|
||||
val helpers: Set<String>?
|
||||
) {
|
||||
companion object {
|
||||
private fun issuesToString(issues: Set<String>) = issues.joinToString(", ") { CommonPatterns.ISSUE_TRACKER + it }
|
||||
|
||||
@@ -43,8 +43,9 @@ class LinkedSpecTest(
|
||||
description: String,
|
||||
cases: SpecTestCasesSet,
|
||||
unexpectedBehavior: Boolean,
|
||||
issues: Set<String>
|
||||
) : AbstractSpecTest(testArea, testType, place.sections, testNumber, description, cases, unexpectedBehavior, issues) {
|
||||
issues: Set<String>,
|
||||
helpers: Set<String>?
|
||||
) : AbstractSpecTest(testArea, testType, place.sections, testNumber, description, cases, unexpectedBehavior, issues, helpers) {
|
||||
override fun checkPathConsistency(pathMatcher: Matcher) =
|
||||
testArea == TestArea.valueOf(pathMatcher.group("testArea").withUnderscores())
|
||||
&& testType == TestType.fromValue(pathMatcher.group("testType"))!!
|
||||
|
||||
@@ -32,8 +32,9 @@ class NotLinkedSpecTest(
|
||||
description: String,
|
||||
cases: SpecTestCasesSet,
|
||||
unexpectedBehavior: Boolean,
|
||||
issues: Set<String>
|
||||
) : AbstractSpecTest(testArea, testType, sections, testNumber, description, cases, unexpectedBehavior, issues) {
|
||||
issues: Set<String>,
|
||||
helpers: Set<String>?
|
||||
) : AbstractSpecTest(testArea, testType, sections, testNumber, description, cases, unexpectedBehavior, issues, helpers) {
|
||||
override fun checkPathConsistency(pathMatcher: Matcher) =
|
||||
testArea == TestArea.valueOf(pathMatcher.group("testArea").withUnderscores())
|
||||
&& testType == TestType.fromValue(pathMatcher.group("testType"))!!
|
||||
|
||||
@@ -70,7 +70,8 @@ object CommonParser {
|
||||
parsedTestFile.testDescription,
|
||||
parsedTestFile.testCasesSet,
|
||||
parsedTestFile.unexpectedBehavior,
|
||||
parsedTestFile.issues
|
||||
parsedTestFile.issues,
|
||||
parsedTestFile.helpers
|
||||
)
|
||||
}
|
||||
|
||||
@@ -87,7 +88,8 @@ object CommonParser {
|
||||
parsedTestFile.testDescription,
|
||||
parsedTestFile.testCasesSet,
|
||||
parsedTestFile.unexpectedBehavior,
|
||||
parsedTestFile.issues
|
||||
parsedTestFile.issues,
|
||||
parsedTestFile.helpers
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ data class ParsedTestFile(
|
||||
val testInfoElements: SpecTestInfoElements<SpecTestInfoElementType>,
|
||||
val testCasesSet: SpecTestCasesSet,
|
||||
val unexpectedBehavior: Boolean,
|
||||
val issues: Set<String>
|
||||
val issues: Set<String>,
|
||||
val helpers: Set<String>?
|
||||
)
|
||||
|
||||
fun parseTestInfo(testFilePath: String, testFiles: TestFiles, linkedTestType: SpecTestLinkedType): ParsedTestFile {
|
||||
@@ -42,6 +43,7 @@ fun parseTestInfo(testFilePath: String, testFiles: TestFiles, linkedTestType: Sp
|
||||
arrayOf(*CommonInfoElementType.values(), *CommonSpecTestFileInfoElementType.values(), *linkedTestType.infoElements.value),
|
||||
testInfoByContentMatcher.group("infoElements")
|
||||
)
|
||||
val helpers = testInfoElements[CommonSpecTestFileInfoElementType.HELPERS]?.content?.splitByComma()?.toSet()
|
||||
|
||||
return ParsedTestFile(
|
||||
testArea = TestArea.valueOf(testInfoByContentMatcher.group("testArea").withUnderscores()),
|
||||
@@ -51,6 +53,7 @@ fun parseTestInfo(testFilePath: String, testFiles: TestFiles, linkedTestType: Sp
|
||||
testInfoElements = testInfoElements,
|
||||
testCasesSet = parseTestCases(testFiles),
|
||||
unexpectedBehavior = testInfoElements.contains(CommonInfoElementType.UNEXPECTED_BEHAVIOUR),
|
||||
issues = CommonParser.parseIssues(testInfoElements[CommonInfoElementType.ISSUES])
|
||||
issues = CommonParser.parseIssues(testInfoElements[CommonInfoElementType.ISSUES]),
|
||||
helpers = helpers
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user