From 7dc469b32da959e3cd6c80d1b72a0764468e6c8d Mon Sep 17 00:00:00 2001 From: "anastasiia.spaseeva" Date: Thu, 9 Jan 2020 12:52:56 +0300 Subject: [PATCH] [Spec tests] Minor changes of TestInfoParser and Generated files --- .../DiagnosticsTestSpecGenerated.java | 2 +- .../BlackBoxCodegenTestSpecGenerated.java | 2 +- .../parsing/ParsingTestSpecGenerated.java | 2 +- .../kotlin/spec/utils/parsers/CommonParser.kt | 4 +- .../spec/utils/parsers/TestInfoParser.kt | 64 ++++++++++--------- 5 files changed, 39 insertions(+), 35 deletions(-) diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java index 6f3506e0c78..c1f7d856bf2 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java @@ -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. */ diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java index 0869751e449..38c4dc28fb5 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java @@ -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. */ diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/parsing/ParsingTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/parsing/ParsingTestSpecGenerated.java index aebf31995f5..8677455a3f7 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/parsing/ParsingTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/parsing/ParsingTestSpecGenerated.java @@ -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. */ diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/parsers/CommonParser.kt b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/parsers/CommonParser.kt index 914f149228f..6606329c2e4 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/parsers/CommonParser.kt +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/parsers/CommonParser.kt @@ -55,7 +55,7 @@ object CommonParser { ) 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 placeMatcher = testInfoElements[LinkedSpecTestFileInfoElementType.PLACE]!!.additionalMatcher!! val relevantPlacesMatcher = testInfoElements[LinkedSpecTestFileInfoElementType.RELEVANT_PLACES]?.additionalMatcher @@ -86,7 +86,7 @@ object CommonParser { } 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 sectionsMatcher = testInfoElements[NotLinkedSpecTestFileInfoElementType.SECTIONS]!!.additionalMatcher!! diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/parsers/TestInfoParser.kt b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/parsers/TestInfoParser.kt index 4e37cd1e7fe..7db8ae8af5d 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/parsers/TestInfoParser.kt +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/parsers/TestInfoParser.kt @@ -30,37 +30,41 @@ data class ParsedTestFile( 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 { - 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) } - ) + return parseTestInfo(testFilePath, testFiles, linkedTestType) } catch (e: Exception) { error("Wrong format of file:\nfile://$testFilePath \n${e.message}") }