From 5649662832ee49ccfb5a91298038825f700334a4 Mon Sep 17 00:00:00 2001 From: lanarimarco Date: Wed, 31 Jan 2024 14:42:54 +0100 Subject: [PATCH 1/2] Add tests --- .../rpgparser/interpreter/JarikoCallbackTest.kt | 14 ++++++++++++++ .../src/test/resources/ERROR11.rpgle | 6 ++++++ 2 files changed, 20 insertions(+) create mode 100644 rpgJavaInterpreter-core/src/test/resources/ERROR11.rpgle diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/interpreter/JarikoCallbackTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/interpreter/JarikoCallbackTest.kt index f31d2826a..4ecc05607 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/interpreter/JarikoCallbackTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/interpreter/JarikoCallbackTest.kt @@ -397,6 +397,16 @@ class JarikoCallbackTest : AbstractTest() { executeSourceLineTest("ERROR10") } + @Test + fun executeERROR11CallBackTest() { + executePgmCallBackTest("ERROR11", SourceReferenceType.Program, "ERROR11", listOf(5)) + } + + @Test + fun executeERROR11SourceLineTest() { + executeSourceLineTest("ERROR11") + } + /** * This test simulates what a precompiler might do throws the use of the beforeParsing callback * In ERROR01.rpgle I will comment C specification to avoid a division by zero errors @@ -489,6 +499,10 @@ class JarikoCallbackTest : AbstractTest() { } } + /** + * Verify that the sourceLine is correctly set in case of error. + * ErrorEvent must contain a reference of an absolute line of the source code + * */ private fun executeSourceLineTest(pgm: String) { lateinit var lines: List val errorEvents = mutableListOf() diff --git a/rpgJavaInterpreter-core/src/test/resources/ERROR11.rpgle b/rpgJavaInterpreter-core/src/test/resources/ERROR11.rpgle new file mode 100644 index 000000000..b5f730c58 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/ERROR11.rpgle @@ -0,0 +1,6 @@ + V* ============================================================== + D* Missing implementation of the DOWLE opcode + D* + V* ============================================================== + C $B DOWLE 13 + C ENDDO \ No newline at end of file From 5cf54755bbbcdf144fec6c46017a46ecafdb6975 Mon Sep 17 00:00:00 2001 From: lanarimarco Date: Wed, 31 Jan 2024 14:44:30 +0100 Subject: [PATCH 2/2] Fix issue. It is good practice to use the ParserRuleContext.todo and ParserRuleContext.error extension functions for a better error handling --- .../com/smeup/rpgparser/parsing/parsetreetoast/statements.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/statements.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/statements.kt index 2aaf6ff52..166579e15 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/statements.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/statements.kt @@ -54,7 +54,7 @@ internal fun BlockContext.toAst(conf: ToAstConfiguration = ToAstConfiguration()) this.begindow() != null -> this.begindow().toAst(blockContext = this, conf = conf) this.forstatement() != null -> this.forstatement().toAst(conf) this.begindou() != null -> this.begindou().toAst(blockContext = this, conf = conf) - else -> TODO(this.text.toString() + " " + toPosition(conf.considerPosition)) + else -> todo(message = "Missing composite statement implementation for this block: ${this.text}", conf = conf) } }