Add codegen box spec tests support
This commit is contained in:
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.codegen
|
||||
|
||||
import org.jetbrains.kotlin.spec.utils.GeneralConfiguration.TESTDATA_PATH
|
||||
import java.io.File
|
||||
import org.jetbrains.kotlin.spec.validators.AbstractSpecTestValidator
|
||||
import org.jetbrains.kotlin.spec.validators.SpecTestValidationException
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.junit.Assert
|
||||
import java.util.regex.Pattern
|
||||
|
||||
abstract class AbstractBlackBoxCodegenTestSpec : AbstractBlackBoxCodegenTest() {
|
||||
companion object {
|
||||
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 val packagePattern = Pattern.compile("""(?:^|\n)package (?<packageName>.*?)(?:;|\n)""")
|
||||
}
|
||||
|
||||
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>) {
|
||||
val fileContent = wholeFile.readText()
|
||||
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 = File("$HELPERS_PATH/${helperDirectives[it]}").readText()
|
||||
files.add(
|
||||
TestFile(helperDirectives[it]!!, addPackageDirectiveToHelperFile(helperContent, packageName))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun doMultiFileTest(wholeFile: File, files: MutableList<TestFile>, javaFilesDir: File?) {
|
||||
val testValidator = AbstractSpecTestValidator.getInstanceByType(wholeFile)
|
||||
|
||||
try {
|
||||
testValidator.parseTestInfo()
|
||||
} catch (e: SpecTestValidationException) {
|
||||
Assert.fail(e.description)
|
||||
}
|
||||
|
||||
testValidator.printTestInfo()
|
||||
|
||||
includeHelpers(wholeFile, files)
|
||||
|
||||
super.doMultiFileTest(wholeFile, files, javaFilesDir)
|
||||
}
|
||||
}
|
||||
+10
-13
@@ -19,15 +19,15 @@ enum class TestType(val type: String) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class TestArea {
|
||||
PSI,
|
||||
DIAGNOSTICS,
|
||||
CODEGEN
|
||||
enum class TestArea(val testDataPath: String) {
|
||||
PSI("psi"),
|
||||
DIAGNOSTICS("diagnostics"),
|
||||
CODEGEN_BOX("codegen/box")
|
||||
}
|
||||
|
||||
enum class SpecTestLinkedType {
|
||||
LINKED,
|
||||
NOT_LINKED
|
||||
enum class SpecTestLinkedType(val testDataPath: String) {
|
||||
LINKED("linked"),
|
||||
NOT_LINKED("notLinked")
|
||||
}
|
||||
|
||||
interface SpecTestInfoElementType {
|
||||
@@ -108,15 +108,12 @@ abstract class AbstractSpecTestValidator<T : AbstractSpecTest>(private val testD
|
||||
|
||||
val pathSeparator: String = Pattern.quote(File.separator)
|
||||
val lineSeparator: String = System.lineSeparator()
|
||||
val testAreaRegex = """(?<testArea>${TestArea.values().joinToString("|")})"""
|
||||
val testAreaRegex = """(?<testArea>${TestArea.values().joinToString("|").replace("_", " ")})"""
|
||||
val testTypeRegex = """(?<testType>${TestType.values().joinToString("|")})"""
|
||||
val dirsByLinkedType = mapOf(
|
||||
SpecTestLinkedType.LINKED to "linked",
|
||||
SpecTestLinkedType.NOT_LINKED to "notLinked"
|
||||
)
|
||||
private val testInfoElementPattern: Pattern = Pattern.compile("""\s*(?<name>[A-Z ]+?)(?::\s*(?<value>.*?))?$lineSeparator""")
|
||||
private val testCaseInfoRegex = """(?<infoElements>CASE DESCRIPTION:[\s\S]*?$lineSeparator)$lineSeparator*"""
|
||||
private val testPathBaseRegexTemplate = """^.*?$pathSeparator(?<testArea>diagnostics|psi|codegen)$pathSeparator%s"""
|
||||
private val testPathBaseRegexTemplate =
|
||||
"""^.*?$pathSeparator(?<testArea>diagnostics|psi|(?:codegen${pathSeparator}box))$pathSeparator%s"""
|
||||
val testPathRegexTemplate = """$testPathBaseRegexTemplate$pathSeparator(?<testType>pos|neg)/%s$"""
|
||||
val testCaseInfoSingleLinePattern: Pattern = Pattern.compile(SINGLELINE_COMMENT_REGEX.format(testCaseInfoRegex))
|
||||
val testCaseInfoMultilinePattern: Pattern = Pattern.compile(MULTILINE_COMMENT_REGEX.format(testCaseInfoRegex))
|
||||
|
||||
Reference in New Issue
Block a user