Add parsing spec tests support
This commit is contained in:
+6
-1
@@ -7,11 +7,16 @@ package org.jetbrains.kotlin.generators.tests
|
||||
|
||||
import org.jetbrains.kotlin.generators.tests.generator.testGroup
|
||||
import org.jetbrains.kotlin.checkers.AbstractDiagnosticsTestSpec
|
||||
import org.jetbrains.kotlin.parsing.AbstractParsingTestSpec
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
testGroup("compiler/tests-spec/tests", "compiler/tests-spec/testData") {
|
||||
testClass<AbstractDiagnosticsTestSpec> {
|
||||
model("diagnostics", excludeDirs = listOf("helpers"))
|
||||
}
|
||||
|
||||
testClass<AbstractParsingTestSpec> {
|
||||
model("psi", testMethod = "doParsingTest", excludeDirs = listOf("helpers"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.parsing
|
||||
|
||||
import org.jetbrains.kotlin.spec.validators.*
|
||||
import org.junit.Assert
|
||||
|
||||
abstract class AbstractParsingTestSpec : AbstractParsingTest() {
|
||||
private lateinit var testValidator: AbstractSpecTestValidator<out AbstractSpecTest>
|
||||
|
||||
override fun doParsingTest(filePath: String) {
|
||||
testValidator = AbstractSpecTestValidator.getInstanceByType(filePath)
|
||||
|
||||
try {
|
||||
testValidator.parseTestInfo()
|
||||
} catch (e: SpecTestValidationException) {
|
||||
Assert.fail(e.description)
|
||||
}
|
||||
|
||||
testValidator.printTestInfo()
|
||||
|
||||
super.doParsingTest(filePath, testValidator::testInfoFilter)
|
||||
|
||||
try {
|
||||
testValidator.validateTestType(computedTestType = ParsingTestTypeValidator.computeTestType(myFile))
|
||||
} catch (e: SpecTestValidationException) {
|
||||
Assert.fail(e.description)
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.spec.validators
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiErrorElement
|
||||
import com.intellij.psi.PsiFile
|
||||
|
||||
object ParsingTestTypeValidator {
|
||||
private fun checkErrorElement(psi: PsiElement): Boolean =
|
||||
psi.children.any { it is PsiErrorElement || checkErrorElement(it) }
|
||||
|
||||
fun computeTestType(psiFile: PsiFile) =
|
||||
if (checkErrorElement(psiFile)) TestType.NEGATIVE else TestType.POSITIVE
|
||||
}
|
||||
Reference in New Issue
Block a user