From 4161080c0988ace7cc92e2eee08df843d0d32d8b Mon Sep 17 00:00:00 2001 From: Felipe Zorzo Date: Tue, 17 Sep 2024 22:24:59 -0300 Subject: [PATCH] feat(grammar): Support COVERAGE pragma --- .../oracle-database_23/DbmsOutputPutCheck.json | 4 ++++ .../expected/oracle-database_23/ParsingErrorCheck.json | 3 --- .../org/sonar/plugins/plsqlopen/api/PlSqlGrammar.kt | 10 ++++++++-- .../org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt | 1 + .../api/declarations/PragmaDeclarationTest.kt | 4 ++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/DbmsOutputPutCheck.json b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/DbmsOutputPutCheck.json index 1cebf4c9..f4708e7c 100644 --- a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/DbmsOutputPutCheck.json +++ b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/DbmsOutputPutCheck.json @@ -21,6 +21,10 @@ 9, 13 ], + "lnpls/COVERAGE-pragma-3.sql" : [ + 15, + 17 + ], "lnpls/DEPRECATE-pragma-27.sql" : [ 12 ], diff --git a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/ParsingErrorCheck.json b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/ParsingErrorCheck.json index 15b1c732..f6c9559e 100644 --- a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/ParsingErrorCheck.json +++ b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/ParsingErrorCheck.json @@ -212,9 +212,6 @@ "lnpls/COVERAGE-pragma-1.sql" : [ 2 ], - "lnpls/COVERAGE-pragma-3.sql" : [ - 10 - ], "lnpls/CREATE-FUNCTION-statement-0.sql" : [ 2 ], diff --git a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlGrammar.kt b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlGrammar.kt index 9edd7e8d..82bd317a 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlGrammar.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlGrammar.kt @@ -198,6 +198,7 @@ enum class PlSqlGrammar : GrammarRuleKey { UDF_PRAGMA, DEPRECATE_PRAGMA, SUPPRESSES_WARNING_6009_PRAGMA, + COVERAGE_PRAGMA, PRAGMA_DECLARATION, HOST_AND_INDICATOR_VARIABLE, JAVA_DECLARATION, @@ -682,7 +683,8 @@ enum class PlSqlGrammar : GrammarRuleKey { CASE_STATEMENT, SET_TRANSACTION_STATEMENT, MERGE_STATEMENT, - INLINE_PRAGMA_STATEMENT)) + INLINE_PRAGMA_STATEMENT, + COVERAGE_PRAGMA)) b.rule(STATEMENTS, Statements::class).define(b.oneOrMore(STATEMENT)) } @@ -1014,6 +1016,9 @@ enum class PlSqlGrammar : GrammarRuleKey { b.rule(SUPPRESSES_WARNING_6009_PRAGMA) .define(PRAGMA, SUPPRESSES_WARNING_6009, LPARENTHESIS, IDENTIFIER_NAME, RPARENTHESIS) + b.rule(COVERAGE_PRAGMA) + .define(PRAGMA, COVERAGE, LPARENTHESIS, STRING_LITERAL, RPARENTHESIS, SEMICOLON) + b.rule(PRAGMA_DECLARATION).define( b.firstOf( EXCEPTION_INIT_PRAGMA, @@ -1023,7 +1028,8 @@ enum class PlSqlGrammar : GrammarRuleKey { RESTRICT_REFERENCES_PRAGMA, UDF_PRAGMA, b.sequence(DEPRECATE_PRAGMA, SEMICOLON), - b.sequence(SUPPRESSES_WARNING_6009_PRAGMA, SEMICOLON) + b.sequence(SUPPRESSES_WARNING_6009_PRAGMA, SEMICOLON), + COVERAGE_PRAGMA ) ) diff --git a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt index 2e345b40..21297b2f 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt @@ -178,6 +178,7 @@ enum class PlSqlKeyword(override val value: String, val isReserved: Boolean = fa CONVERSION("conversion"), COPY("copy"), COUNT("count"), + COVERAGE("coverage"), CRASH("crash"), CROSS("cross"), CROSSEDITION("crossedition"), diff --git a/zpa-core/src/test/kotlin/org/sonar/plugins/plsqlopen/api/declarations/PragmaDeclarationTest.kt b/zpa-core/src/test/kotlin/org/sonar/plugins/plsqlopen/api/declarations/PragmaDeclarationTest.kt index 07de5554..8550f1e5 100644 --- a/zpa-core/src/test/kotlin/org/sonar/plugins/plsqlopen/api/declarations/PragmaDeclarationTest.kt +++ b/zpa-core/src/test/kotlin/org/sonar/plugins/plsqlopen/api/declarations/PragmaDeclarationTest.kt @@ -69,8 +69,8 @@ class PragmaDeclarationTest : RuleTest() { } @Test - fun matchesSuppressWarning6009Pragma() { - assertThat(p).matches("pragma suppresses_warning_6009(pcd);") + fun matchesCoveragePragma() { + assertThat(p).matches("pragma coverage('NOT_FEASIBLE_START');") } }