[Spec tests] Minor changes of TestInfoParser and Generated files
This commit is contained in:
Generated
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ object CommonParser {
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun parseLinkedSpecTest(testFilePath: String, testFiles: TestFiles): LinkedSpecTest {
|
fun parseLinkedSpecTest(testFilePath: String, testFiles: TestFiles): LinkedSpecTest {
|
||||||
val parsedTestFile = parseTestInfo(testFilePath, testFiles, SpecTestLinkedType.LINKED)
|
val parsedTestFile = tryParseTestInfo(testFilePath, testFiles, SpecTestLinkedType.LINKED)
|
||||||
val testInfoElements = parsedTestFile.testInfoElements
|
val testInfoElements = parsedTestFile.testInfoElements
|
||||||
val placeMatcher = testInfoElements[LinkedSpecTestFileInfoElementType.PLACE]!!.additionalMatcher!!
|
val placeMatcher = testInfoElements[LinkedSpecTestFileInfoElementType.PLACE]!!.additionalMatcher!!
|
||||||
val relevantPlacesMatcher = testInfoElements[LinkedSpecTestFileInfoElementType.RELEVANT_PLACES]?.additionalMatcher
|
val relevantPlacesMatcher = testInfoElements[LinkedSpecTestFileInfoElementType.RELEVANT_PLACES]?.additionalMatcher
|
||||||
@@ -86,7 +86,7 @@ object CommonParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun parseNotLinkedSpecTest(testFilePath: String, testFiles: TestFiles): NotLinkedSpecTest {
|
private fun parseNotLinkedSpecTest(testFilePath: String, testFiles: TestFiles): NotLinkedSpecTest {
|
||||||
val parsedTestFile = parseTestInfo(testFilePath, testFiles, SpecTestLinkedType.NOT_LINKED)
|
val parsedTestFile = tryParseTestInfo(testFilePath, testFiles, SpecTestLinkedType.NOT_LINKED)
|
||||||
val testInfoElements = parsedTestFile.testInfoElements
|
val testInfoElements = parsedTestFile.testInfoElements
|
||||||
val sectionsMatcher = testInfoElements[NotLinkedSpecTestFileInfoElementType.SECTIONS]!!.additionalMatcher!!
|
val sectionsMatcher = testInfoElements[NotLinkedSpecTestFileInfoElementType.SECTIONS]!!.additionalMatcher!!
|
||||||
|
|
||||||
|
|||||||
+34
-30
@@ -30,37 +30,41 @@ data class ParsedTestFile(
|
|||||||
val exception: TestsExceptionType?
|
val exception: TestsExceptionType?
|
||||||
)
|
)
|
||||||
|
|
||||||
fun parseTestInfo(testFilePath: String, testFiles: TestFiles, linkedTestType: SpecTestLinkedType): ParsedTestFile {
|
private fun parseTestInfo(testFilePath: String, testFiles: TestFiles, linkedTestType: SpecTestLinkedType): ParsedTestFile {
|
||||||
|
val patterns = linkedTestType.patterns.value
|
||||||
|
val testInfoByFilenameMatcher = patterns.testPathPattern.matcher(testFilePath)
|
||||||
|
|
||||||
|
if (!testInfoByFilenameMatcher.find())
|
||||||
|
throw SpecTestValidationException(SpecTestValidationFailedReason.FILENAME_NOT_VALID)
|
||||||
|
|
||||||
|
val testInfoByContentMatcher = patterns.testInfoPattern.matcher(FileUtil.loadFile(File(testFilePath), true))
|
||||||
|
|
||||||
|
if (!testInfoByContentMatcher.find())
|
||||||
|
throw SpecTestValidationException(SpecTestValidationFailedReason.TESTINFO_NOT_VALID)
|
||||||
|
|
||||||
|
val testInfoElements = CommonParser.parseTestInfoElements(
|
||||||
|
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()),
|
||||||
|
testType = TestType.valueOf(testInfoByContentMatcher.group("testType")),
|
||||||
|
testNumber = testInfoElements[CommonSpecTestFileInfoElementType.NUMBER]!!.content.toInt(),
|
||||||
|
testDescription = testInfoElements[CommonSpecTestFileInfoElementType.DESCRIPTION]!!.content,
|
||||||
|
testInfoElements = testInfoElements,
|
||||||
|
testCasesSet = parseTestCases(testFiles),
|
||||||
|
unexpectedBehavior = testInfoElements.contains(CommonInfoElementType.UNEXPECTED_BEHAVIOUR),
|
||||||
|
issues = CommonParser.parseIssues(testInfoElements[CommonInfoElementType.ISSUES]),
|
||||||
|
helpers = helpers,
|
||||||
|
exception = testInfoElements[CommonInfoElementType.EXCEPTION]?.content?.let { TestsExceptionType.fromValue(it) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun tryParseTestInfo(testFilePath: String, testFiles: TestFiles, linkedTestType: SpecTestLinkedType): ParsedTestFile {
|
||||||
try {
|
try {
|
||||||
val patterns = linkedTestType.patterns.value
|
return parseTestInfo(testFilePath, testFiles, linkedTestType)
|
||||||
val testInfoByFilenameMatcher = patterns.testPathPattern.matcher(testFilePath)
|
|
||||||
|
|
||||||
if (!testInfoByFilenameMatcher.find())
|
|
||||||
throw SpecTestValidationException(SpecTestValidationFailedReason.FILENAME_NOT_VALID)
|
|
||||||
|
|
||||||
val testInfoByContentMatcher = patterns.testInfoPattern.matcher(FileUtil.loadFile(File(testFilePath), true))
|
|
||||||
|
|
||||||
if (!testInfoByContentMatcher.find())
|
|
||||||
throw SpecTestValidationException(SpecTestValidationFailedReason.TESTINFO_NOT_VALID)
|
|
||||||
|
|
||||||
val testInfoElements = CommonParser.parseTestInfoElements(
|
|
||||||
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()),
|
|
||||||
testType = TestType.valueOf(testInfoByContentMatcher.group("testType")),
|
|
||||||
testNumber = testInfoElements[CommonSpecTestFileInfoElementType.NUMBER]!!.content.toInt(),
|
|
||||||
testDescription = testInfoElements[CommonSpecTestFileInfoElementType.DESCRIPTION]!!.content,
|
|
||||||
testInfoElements = testInfoElements,
|
|
||||||
testCasesSet = parseTestCases(testFiles),
|
|
||||||
unexpectedBehavior = testInfoElements.contains(CommonInfoElementType.UNEXPECTED_BEHAVIOUR),
|
|
||||||
issues = CommonParser.parseIssues(testInfoElements[CommonInfoElementType.ISSUES]),
|
|
||||||
helpers = helpers,
|
|
||||||
exception = testInfoElements[CommonInfoElementType.EXCEPTION]?.content?.let { TestsExceptionType.fromValue(it) }
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
error("Wrong format of file:\nfile://$testFilePath \n${e.message}")
|
error("Wrong format of file:\nfile://$testFilePath \n${e.message}")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user