From dec2b2918c58e0a3729be9035feaed6a60f4c3d1 Mon Sep 17 00:00:00 2001 From: Pieter Olivier Date: Sun, 1 Sep 2024 12:26:39 +0200 Subject: [PATCH] Worked on error recovery tests --- src/org/rascalmpl/library/ParseTree.rsc | 5 +++++ .../lang/rascal/tests/recovery/BasicRecoveryTests.rsc | 2 +- .../lang/rascal/tests/recovery/ToyRascalRecoveryTests.rsc | 4 ++-- .../{ErrorRecoveryModules.java => RunRascalTestModules.java} | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) rename test/org/rascalmpl/test/recovery/{ErrorRecoveryModules.java => RunRascalTestModules.java} (97%) diff --git a/src/org/rascalmpl/library/ParseTree.rsc b/src/org/rascalmpl/library/ParseTree.rsc index f603172f36..ef63f3afd2 100644 --- a/src/org/rascalmpl/library/ParseTree.rsc +++ b/src/org/rascalmpl/library/ParseTree.rsc @@ -786,6 +786,11 @@ Tree findFirstError(Tree tree) { fail; } +@synopsis{Find the best error from a tree containing errors.} +Tree findBestError(Tree tree) { + return findFirstError(defaultErrorDisambiguationFilter(tree)); +} + @synopsis{Get the symbol (sort) of the failing production} Symbol getErrorSymbol(appl(error(Symbol sym, _, _), _)) = sym; diff --git a/src/org/rascalmpl/library/lang/rascal/tests/recovery/BasicRecoveryTests.rsc b/src/org/rascalmpl/library/lang/rascal/tests/recovery/BasicRecoveryTests.rsc index b2f6615b54..b82245f27c 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/recovery/BasicRecoveryTests.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/recovery/BasicRecoveryTests.rsc @@ -38,7 +38,7 @@ test bool abx() { test bool axc() { Tree t = parseS("a x c $", visualize=true); - return getErrorText(findFirstError(t)) != "x c"; + return getErrorText(findFirstError(t)) == "x c"; } test bool ax() { diff --git a/src/org/rascalmpl/library/lang/rascal/tests/recovery/ToyRascalRecoveryTests.rsc b/src/org/rascalmpl/library/lang/rascal/tests/recovery/ToyRascalRecoveryTests.rsc index 7e56e3369a..6284c53188 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/recovery/ToyRascalRecoveryTests.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/recovery/ToyRascalRecoveryTests.rsc @@ -42,10 +42,10 @@ test bool toyRascalOk() { test bool toyRascalMissingOpenParen() { Tree t = parseToyRascal("f){}", visualize=true); - return hasErrors(t) && getErrorText(findFirstError(t)) == ")"; + return hasErrors(t) && getErrorText(findBestError(t)) == ")"; } test bool toyRascalMissingCloseParen() { Tree t = parseToyRascal("f({}", visualize=true); - return hasErrors(t) && getErrorText(findFirstError(t)) == ")"; + return hasErrors(t) && getErrorText(findBestError(t)) == "("; } diff --git a/test/org/rascalmpl/test/recovery/ErrorRecoveryModules.java b/test/org/rascalmpl/test/recovery/RunRascalTestModules.java similarity index 97% rename from test/org/rascalmpl/test/recovery/ErrorRecoveryModules.java rename to test/org/rascalmpl/test/recovery/RunRascalTestModules.java index 8f96ea6a52..b3437975cd 100644 --- a/test/org/rascalmpl/test/recovery/ErrorRecoveryModules.java +++ b/test/org/rascalmpl/test/recovery/RunRascalTestModules.java @@ -20,6 +20,6 @@ @RunWith(RascalJUnitTestRunner.class) @RascalJUnitTestPrefix("lang::rascal::tests::recovery") -public class ErrorRecoveryModules { +public class RunRascalTestModules { }