[Spec tests] Minor changes of TestInfoParser and Generated files

This commit is contained in:
anastasiia.spaseeva
2020-01-09 12:52:56 +03:00
parent e0743f2268
commit 7dc469b32d
5 changed files with 39 additions and 35 deletions
@@ -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,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,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!!
@@ -30,8 +30,7 @@ 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 {
try {
val patterns = linkedTestType.patterns.value val patterns = linkedTestType.patterns.value
val testInfoByFilenameMatcher = patterns.testPathPattern.matcher(testFilePath) val testInfoByFilenameMatcher = patterns.testPathPattern.matcher(testFilePath)
@@ -61,6 +60,11 @@ fun parseTestInfo(testFilePath: String, testFiles: TestFiles, linkedTestType: Sp
helpers = helpers, helpers = helpers,
exception = testInfoElements[CommonInfoElementType.EXCEPTION]?.content?.let { TestsExceptionType.fromValue(it) } exception = testInfoElements[CommonInfoElementType.EXCEPTION]?.content?.let { TestsExceptionType.fromValue(it) }
) )
}
fun tryParseTestInfo(testFilePath: String, testFiles: TestFiles, linkedTestType: SpecTestLinkedType): ParsedTestFile {
try {
return parseTestInfo(testFilePath, testFiles, linkedTestType)
} 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}")
} }