Fix path separators for Windows in spec test validator
This commit is contained in:
+2
-1
@@ -24,7 +24,8 @@ abstract class AbstractBlackBoxCodegenTestSpec : AbstractBlackBoxCodegenTest() {
|
|||||||
private val helperDirectives = mapOf(
|
private val helperDirectives = mapOf(
|
||||||
"REFLECT" to "reflect.kt"
|
"REFLECT" to "reflect.kt"
|
||||||
)
|
)
|
||||||
private val packagePattern = Pattern.compile("""(?:^|\n)package (?<packageName>.*?)(?:;|\n)""")
|
private val packagePattern =
|
||||||
|
Pattern.compile("""(?:^|${AbstractSpecTestValidator.lineSeparator})package (?<packageName>.*?)(?:;|${AbstractSpecTestValidator.lineSeparator})""")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addPackageDirectiveToHelperFile(helperContent: String, packageName: String?) =
|
private fun addPackageDirectiveToHelperFile(helperContent: String, packageName: String?) =
|
||||||
|
|||||||
+8
-8
@@ -103,25 +103,25 @@ abstract class AbstractSpecTestValidator<T : AbstractSpecTest>(private val testD
|
|||||||
companion object {
|
companion object {
|
||||||
const val ISSUE_TRACKER = "https://youtrack.jetbrains.com/issue/"
|
const val ISSUE_TRACKER = "https://youtrack.jetbrains.com/issue/"
|
||||||
const val INTEGER_REGEX = """[1-9]\d*"""
|
const val INTEGER_REGEX = """[1-9]\d*"""
|
||||||
const val MULTILINE_COMMENT_REGEX = """\/\*\s*%s\s+\*\/\n*"""
|
|
||||||
private const val SINGLELINE_COMMENT_REGEX = """\/\/\s*%s\n*"""
|
|
||||||
|
|
||||||
val pathSeparator: String = Pattern.quote(File.separator)
|
val pathSeparator: String = Pattern.quote(File.separator)
|
||||||
val lineSeparator: String = System.lineSeparator()
|
val lineSeparator: String = System.lineSeparator()
|
||||||
val testAreaRegex = """(?<testArea>${TestArea.values().joinToString("|").replace("_", " ")})"""
|
val testAreaRegex = """(?<testArea>${TestArea.values().joinToString("|").replace("_", " ")})"""
|
||||||
val testTypeRegex = """(?<testType>${TestType.values().joinToString("|")})"""
|
val testTypeRegex = """(?<testType>${TestType.values().joinToString("|")})"""
|
||||||
|
val multilineCommentRegex = """\/\*\s*%s\s+\*\/(?:$lineSeparator)*"""
|
||||||
|
private val singlelineCommentRegex = """\/\/\s*%s(?:$lineSeparator)*"""
|
||||||
private val testInfoElementPattern: Pattern = Pattern.compile("""\s*(?<name>[A-Z ]+?)(?::\s*(?<value>.*?))?$lineSeparator""")
|
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 testCaseInfoRegex = """(?<infoElements>CASE DESCRIPTION:[\s\S]*?$lineSeparator)(?:$lineSeparator)*"""
|
||||||
private val testPathBaseRegexTemplate =
|
private val testPathBaseRegexTemplate =
|
||||||
"""^.*?$pathSeparator(?<testArea>diagnostics|psi|(?:codegen${pathSeparator}box))$pathSeparator%s"""
|
"""^.*?$pathSeparator(?<testArea>diagnostics|psi|(?:codegen${pathSeparator}box))$pathSeparator%s"""
|
||||||
val testPathRegexTemplate = """$testPathBaseRegexTemplate$pathSeparator(?<testType>pos|neg)/%s$"""
|
val testPathRegexTemplate = """$testPathBaseRegexTemplate$pathSeparator(?<testType>pos|neg)$pathSeparator%s$"""
|
||||||
val testCaseInfoSingleLinePattern: Pattern = Pattern.compile(SINGLELINE_COMMENT_REGEX.format(testCaseInfoRegex))
|
val testCaseInfoSingleLinePattern: Pattern = Pattern.compile(singlelineCommentRegex.format(testCaseInfoRegex))
|
||||||
val testCaseInfoMultilinePattern: Pattern = Pattern.compile(MULTILINE_COMMENT_REGEX.format(testCaseInfoRegex))
|
val testCaseInfoMultilinePattern: Pattern = Pattern.compile(multilineCommentRegex.format(testCaseInfoRegex))
|
||||||
|
|
||||||
fun getInstanceByType(testFile: File) = when {
|
fun getInstanceByType(testFile: File) = when {
|
||||||
Pattern.compile(testPathBaseRegexTemplate.format(LinkedSpecTestValidator.pathPartRegex)).matcher(testFile.absolutePath).find() ->
|
Pattern.compile(testPathBaseRegexTemplate.format(LinkedSpecTestValidator.pathPartRegex)).matcher(testFile.canonicalPath).find() ->
|
||||||
LinkedSpecTestValidator(testFile)
|
LinkedSpecTestValidator(testFile)
|
||||||
Pattern.compile(testPathBaseRegexTemplate.format(NotLinkedSpecTestValidator.pathPartRegex)).matcher(testFile.absolutePath).find() ->
|
Pattern.compile(testPathBaseRegexTemplate.format(NotLinkedSpecTestValidator.pathPartRegex)).matcher(testFile.canonicalPath).find() ->
|
||||||
NotLinkedSpecTestValidator(testFile)
|
NotLinkedSpecTestValidator(testFile)
|
||||||
else -> throw SpecTestValidationException(SpecTestValidationFailedReason.FILENAME_NOT_VALID)
|
else -> throw SpecTestValidationException(SpecTestValidationFailedReason.FILENAME_NOT_VALID)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -56,11 +56,11 @@ class LinkedSpecTest(
|
|||||||
class LinkedSpecTestValidator(testDataFile: File) : AbstractSpecTestValidator<LinkedSpecTest>(testDataFile) {
|
class LinkedSpecTestValidator(testDataFile: File) : AbstractSpecTestValidator<LinkedSpecTest>(testDataFile) {
|
||||||
override val testPathPattern = getPathPattern()
|
override val testPathPattern = getPathPattern()
|
||||||
override val testInfoPattern: Pattern =
|
override val testInfoPattern: Pattern =
|
||||||
Pattern.compile(MULTILINE_COMMENT_REGEX.format("""KOTLIN $testAreaRegex SPEC TEST \($testTypeRegex\)$lineSeparator(?<infoElements>[\s\S]*?$lineSeparator)"""))
|
Pattern.compile(multilineCommentRegex.format("""KOTLIN $testAreaRegex SPEC TEST \($testTypeRegex\)$lineSeparator(?<infoElements>[\s\S]*?$lineSeparator)"""))
|
||||||
|
|
||||||
companion object : SpecTestValidatorHelperObject {
|
companion object : SpecTestValidatorHelperObject {
|
||||||
override val pathPartRegex =
|
override val pathPartRegex =
|
||||||
"""${SpecTestLinkedType.LINKED.testDataPath}$pathSeparator(?<sections>(?:[\w-]+)(?:/[\w-]+)*?)${pathSeparator}p-(?<paragraphNumber>$INTEGER_REGEX)"""
|
"""${SpecTestLinkedType.LINKED.testDataPath}$pathSeparator(?<sections>(?:[\w-]+)(?:$pathSeparator[\w-]+)*?)${pathSeparator}p-(?<paragraphNumber>$INTEGER_REGEX)"""
|
||||||
override val filenameRegex = """(?<sentenceNumber>$INTEGER_REGEX)\.(?<testNumber>$INTEGER_REGEX)\.kt"""
|
override val filenameRegex = """(?<sentenceNumber>$INTEGER_REGEX)\.(?<testNumber>$INTEGER_REGEX)\.kt"""
|
||||||
override fun getPathPattern(): Pattern = Pattern.compile(testPathRegexTemplate.format(pathPartRegex, filenameRegex))
|
override fun getPathPattern(): Pattern = Pattern.compile(testPathRegexTemplate.format(pathPartRegex, filenameRegex))
|
||||||
}
|
}
|
||||||
@@ -91,9 +91,9 @@ class LinkedSpecTestValidator(testDataFile: File) : AbstractSpecTestValidator<Li
|
|||||||
|
|
||||||
override fun getTestInfo(testInfoMatcher: Matcher) =
|
override fun getTestInfo(testInfoMatcher: Matcher) =
|
||||||
LinkedSpecTest(
|
LinkedSpecTest(
|
||||||
TestArea.valueOf(testInfoMatcher.group("testArea").replace("/", "_").toUpperCase()),
|
TestArea.valueOf(testInfoMatcher.group("testArea").replace(File.separator, "_").toUpperCase()),
|
||||||
TestType.fromValue(testInfoMatcher.group("testType"))!!,
|
TestType.fromValue(testInfoMatcher.group("testType"))!!,
|
||||||
testInfoMatcher.group("sections").split("/"),
|
testInfoMatcher.group("sections").split(File.separator),
|
||||||
testInfoMatcher.group("paragraphNumber").toInt(),
|
testInfoMatcher.group("paragraphNumber").toInt(),
|
||||||
testInfoMatcher.group("sentenceNumber").toInt(),
|
testInfoMatcher.group("sentenceNumber").toInt(),
|
||||||
testNumber = testInfoMatcher.group("testNumber").toInt()
|
testNumber = testInfoMatcher.group("testNumber").toInt()
|
||||||
|
|||||||
+3
-3
@@ -49,11 +49,11 @@ class NotLinkedSpecTest(
|
|||||||
class NotLinkedSpecTestValidator(testDataFile: File) : AbstractSpecTestValidator<NotLinkedSpecTest>(testDataFile) {
|
class NotLinkedSpecTestValidator(testDataFile: File) : AbstractSpecTestValidator<NotLinkedSpecTest>(testDataFile) {
|
||||||
override val testPathPattern = getPathPattern()
|
override val testPathPattern = getPathPattern()
|
||||||
override val testInfoPattern: Pattern =
|
override val testInfoPattern: Pattern =
|
||||||
Pattern.compile(MULTILINE_COMMENT_REGEX.format("""KOTLIN $testAreaRegex NOT LINKED SPEC TEST \($testTypeRegex\)$lineSeparator(?<infoElements>[\s\S]*?$lineSeparator)"""))
|
Pattern.compile(multilineCommentRegex.format("""KOTLIN $testAreaRegex NOT LINKED SPEC TEST \($testTypeRegex\)$lineSeparator(?<infoElements>[\s\S]*?$lineSeparator)"""))
|
||||||
|
|
||||||
companion object : SpecTestValidatorHelperObject {
|
companion object : SpecTestValidatorHelperObject {
|
||||||
override val pathPartRegex =
|
override val pathPartRegex =
|
||||||
"""${SpecTestLinkedType.NOT_LINKED.testDataPath}$pathSeparator(?<sections>[\w-]+)$pathSeparator(?<categories>(?:[\w-]+)(?:/[\w-]+)*?)"""
|
"""${SpecTestLinkedType.NOT_LINKED.testDataPath}$pathSeparator(?<sections>[\w-]+)$pathSeparator(?<categories>(?:[\w-]+)(?:$pathSeparator[\w-]+)*?)"""
|
||||||
override val filenameRegex = """(?<testNumber>$INTEGER_REGEX)\.kt"""
|
override val filenameRegex = """(?<testNumber>$INTEGER_REGEX)\.kt"""
|
||||||
override fun getPathPattern(): Pattern = Pattern.compile(testPathRegexTemplate.format(pathPartRegex, filenameRegex))
|
override fun getPathPattern(): Pattern = Pattern.compile(testPathRegexTemplate.format(pathPartRegex, filenameRegex))
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ class NotLinkedSpecTestValidator(testDataFile: File) : AbstractSpecTestValidator
|
|||||||
TestArea.valueOf(testInfoMatcher.group("testArea").toUpperCase()),
|
TestArea.valueOf(testInfoMatcher.group("testArea").toUpperCase()),
|
||||||
TestType.fromValue(testInfoMatcher.group("testType"))!!,
|
TestType.fromValue(testInfoMatcher.group("testType"))!!,
|
||||||
testInfoMatcher.group("sections"),
|
testInfoMatcher.group("sections"),
|
||||||
testInfoMatcher.group("categories").split("/"),
|
testInfoMatcher.group("categories").split(File.separator),
|
||||||
testNumber = testInfoMatcher.group("testNumber").toInt()
|
testNumber = testInfoMatcher.group("testNumber").toInt()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user