felipebz/zpa

Junit RecognitionException

jose-jimenezp opened this issue · 4 comments

Is it possible to set sonar.zpa.errorRecoveryEnabled to true when a Junit test is performed?.
I follow your wiki but Parse error RecognitionException is rised.

Thanks in advance ang great job.

Hi @jimenpar.

It seems that the PL/SQL code you're using for the test is invalid or there's an issue with the parser and it's not recognizing your code. I'm not sure if enabling the error recovery is the way to go. Could you share your test, please?

Hi @felipebz ,
The issue is related to the PL/SQL code, i'm trying to force an error to be detected on sonarqube, but i cannot pass unit test, because parser raise an exception.
Attached is the reaised error of junit tests. it fails to parser at line 5:
2020-11-09 17_25_22-plsql-custom-rules_src_test
I need to set true the errorRecoveryEnabled feature to pass the tests. How can I enable the error recovery?

Many thanks in advance

I'm still not sure why you want to use a invalid code for testing. This is already handled by the "Parser failure" rule, you can activate it to track the invalid code on your SonarQube instance.

Anyway, you can call the parser manually instead of using the PlSqlCheckVerifier, like:

@Test
public void test() {
    Parser<Grammar> parser = PlSqlParser.INSTANCE.create(
        new PlSqlConfiguration(StandardCharsets.UTF_8, /* isErrorRecoveryEnabled = */ true));

    AstNode rootTree = parser.parse(new File("src/test/resources/my-code.sql"));
    PlSqlVisitorContext context = new PlSqlVisitorContext(rootTree, null, null);

    MyCheck check = new MyCheck();
    List<PlSqlCheck.PreciseIssue> issues = check.scanFileForIssues(context);
    // then assert the content of "issues" manually
}

Hi,
Thanks for the advice, calling the parser manually all my troubles have been resolved.

Many thanks