Implement tests exceptions fixation mechanism
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
CASES: 4
|
||||
java.lang.StackOverflowError
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
junit.framework.AssertionFailedError: Incomplete operation in parsed OK test, method getExpression in KtWhenConditionWithExpression returns null. Element text:
|
||||
@@ -6,6 +6,7 @@
|
||||
* SENTENCE: [1] Type test condition: type checking operator followed by type.
|
||||
* NUMBER: 2
|
||||
* DESCRIPTION: 'When' with bound value and 'when condition' with type checking operator and non-type value.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
*/
|
||||
|
||||
fun case_2() {
|
||||
|
||||
+13
-15
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.checkers
|
||||
|
||||
import org.jetbrains.kotlin.TestExceptionsComparator
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
@@ -12,12 +13,11 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.spec.models.AbstractSpecTest
|
||||
import org.jetbrains.kotlin.spec.SpecTestLinkedType
|
||||
import org.jetbrains.kotlin.spec.parsers.CommonParser
|
||||
import org.jetbrains.kotlin.spec.parsers.CommonPatterns.ls
|
||||
import org.jetbrains.kotlin.spec.validators.*
|
||||
import org.jetbrains.kotlin.test.*
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
|
||||
abstract class AbstractDiagnosticsTestSpec : AbstractDiagnosticsTest() {
|
||||
@@ -84,32 +84,30 @@ abstract class AbstractDiagnosticsTestSpec : AbstractDiagnosticsTest() {
|
||||
|
||||
enableDescriptorsGenerationIfNeeded(testFilePath)
|
||||
|
||||
CommonParser.parseSpecTest(testFilePath, files.associate { Pair(it.ktFile!!.name, it.clearText) }).apply {
|
||||
CommonParser.parseSpecTest(testFilePath, files.associate { Pair(it.fileName, it.clearText) }).apply {
|
||||
specTest = first
|
||||
testLinkedType = second
|
||||
}
|
||||
|
||||
println(specTest)
|
||||
|
||||
try {
|
||||
super.analyzeAndCheck(testDataFile, files)
|
||||
} catch (e: KotlinExceptionWithAttachments) {
|
||||
val matches = exceptionPattern.matcher(e.message)
|
||||
|
||||
if (!matches.find())
|
||||
Assert.fail(SpecTestValidationFailedReason.UNKNOWN_FRONTEND_EXCEPTION.description)
|
||||
val checkUnexpectedBehaviour: (Matcher?) -> Pair<Boolean, Set<Int>?> = l@{ matches ->
|
||||
if (specTest.unexpectedBehavior) return@l Pair(true, null)
|
||||
if (matches == null) return@l Pair(false, 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 exceptionPosition = fileContent.lines().subList(0, lineNumber).joinToString("\n").length + symbolNumber
|
||||
val testCases = specTest.cases.byRanges[filename]
|
||||
val isExpectedException = testCases!!.floorEntry(exceptionPosition).value.all { it.value.unexpectedBehavior }
|
||||
val testCasesWithSamePosition = testCases!!.floorEntry(exceptionPosition).value
|
||||
|
||||
if (!isExpectedException)
|
||||
Assert.fail()
|
||||
return@l Pair(testCasesWithSamePosition.all { it.value.unexpectedBehavior }, testCasesWithSamePosition.keys.toSet())
|
||||
}
|
||||
|
||||
TestExceptionsComparator(testDataFile).runAndCompareWithExpected(checkUnexpectedBehaviour) {
|
||||
super.analyzeAndCheck(testDataFile, files)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -6,11 +6,12 @@
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.TestExceptionsComparator
|
||||
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.test.InTextDirectivesUtils
|
||||
import java.io.File
|
||||
import java.io.*
|
||||
|
||||
abstract class AbstractBlackBoxCodegenTestSpec : AbstractBlackBoxCodegenTest() {
|
||||
companion object {
|
||||
@@ -55,6 +56,8 @@ abstract class AbstractBlackBoxCodegenTestSpec : AbstractBlackBoxCodegenTest() {
|
||||
|
||||
includeHelpers(wholeFile, files)
|
||||
|
||||
super.doMultiFileTest(wholeFile, files, javaFilesDir)
|
||||
TestExceptionsComparator(wholeFile).runAndCompareWithExpected {
|
||||
super.doMultiFileTest(wholeFile, files, javaFilesDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.parsing
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.TestExceptionsComparator
|
||||
import org.jetbrains.kotlin.spec.parsers.CommonParser
|
||||
import org.jetbrains.kotlin.spec.validators.*
|
||||
import org.junit.Assert
|
||||
@@ -13,22 +14,24 @@ 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(filePath), true))
|
||||
mapOf("main.kt" to FileUtil.loadFile(file, true))
|
||||
)
|
||||
|
||||
println(specTest)
|
||||
|
||||
super.doParsingTest(filePath, CommonParser::testInfoFilter)
|
||||
TestExceptionsComparator(file).runAndCompareWithExpected({ Pair(specTest.unexpectedBehavior, null) }) {
|
||||
super.doParsingTest(filePath, CommonParser::testInfoFilter)
|
||||
|
||||
val psiTestValidator = ParsingTestTypeValidator(myFile, File(filePath), specTest)
|
||||
|
||||
try {
|
||||
psiTestValidator.validatePathConsistency(testLinkedType)
|
||||
psiTestValidator.validateTestType()
|
||||
} catch (e: SpecTestValidationException) {
|
||||
Assert.fail(e.description)
|
||||
try {
|
||||
val psiTestValidator = ParsingTestTypeValidator(myFile, File(filePath), specTest)
|
||||
psiTestValidator.validatePathConsistency(testLinkedType)
|
||||
psiTestValidator.validateTestType()
|
||||
} catch (e: SpecTestValidationException) {
|
||||
Assert.fail(e.description)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user