66import java .nio .file .Path ;
77import java .util .ArrayList ;
88import java .util .List ;
9+ import java .util .regex .Matcher ;
10+ import java .util .regex .Pattern ;
911
1012public class TestUtils {
11- /*
12- * A simple record to store an error message and its line number, used for expected errors read from test files
13- */
14- public record Pair (String errorMessage , int lineNumber ) {
15- @ Override
16- public String toString () {
17- return errorMessage + " at " + lineNumber ;
18- };
19- }
20-
2113 /**
2214 * Determines if the given path indicates that the test should pass
2315 *
@@ -45,23 +37,22 @@ public static boolean shouldFail(String path) {
4537 * @return list of expected error messages found in the file, or empty list if there was an error reading the file
4638 * or if there are no expected error messages in the file
4739 */
48- public static List <Pair > getExpectedErrorsFromFile (Path filePath ) {
49- List <Pair > expectedErrors = new ArrayList <>();
40+ public static List <Pair < String , Integer > > getExpectedErrorsFromFile (Path filePath ) {
41+ List <Pair < String , Integer > > expectedErrors = new ArrayList <>();
5042 try (BufferedReader reader = Files .newBufferedReader (filePath )) {
5143 String line ;
5244 int lineNumber = 0 ;
5345 while ((line = reader .readLine ()) != null ) {
5446 lineNumber ++;
55- int idx = line .indexOf ("//" );
56- if (idx != -1 && line .substring (idx ).contains ("Error" )) {
57- // only expects the error type, NOT the actual refinement error message, depends on deterministic
58- // variable names
59- String comment = line .substring (idx + 2 ).trim ();
47+ Pattern p = Pattern .compile ("//\\ s*(.*?\\ bError\\ b)" , Pattern .CASE_INSENSITIVE );
48+ Matcher m = p .matcher (line );
49+ if (m .find ()) {
50+ String comment = m .group (1 ).trim ();
6051 int dotIdx = comment .indexOf (":" );
6152 if (dotIdx != -1 ) {
6253 comment = comment .substring (0 , dotIdx ).trim ();
6354 }
64- expectedErrors .add (new Pair (comment , lineNumber ));
55+ expectedErrors .add (new Pair <> (comment , lineNumber ));
6556 }
6657 }
6758 } catch (IOException e ) {
@@ -78,8 +69,8 @@ public static List<Pair> getExpectedErrorsFromFile(Path filePath) {
7869 * @return list of expected error messages from all files in the directory, or empty list if there was an error
7970 * reading the directory or if there are no files in the directory
8071 */
81- public static List <Pair > getExpectedErrorsFromDirectory (Path dirPath ) {
82- List <Pair > expectedErrors = new ArrayList <>();
72+ public static List <Pair < String , Integer > > getExpectedErrorsFromDirectory (Path dirPath ) {
73+ List <Pair < String , Integer > > expectedErrors = new ArrayList <>();
8374 try {
8475 List <Path > files = Files .list (dirPath ).filter (Files ::isRegularFile ).toList ();
8576 for (Path file : files ) {
0 commit comments