Skip to content

Commit

Permalink
emit errors for the right file
Browse files Browse the repository at this point in the history
  • Loading branch information
eggrobin committed May 24, 2024
1 parent f28d02c commit f02b9b9
Showing 1 changed file with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public static int testInvariants(String inputFile, boolean doRange) throws IOExc
} else if (line.startsWith("Let")) {
letLine(pp, line);
} else if (line.startsWith("In")) {
inLine(pp, line, lineNumber);
inLine(pp, line, inputFile, lineNumber);
} else if (line.startsWith("ShowScript")) {
showScript = true;
} else if (line.startsWith("HideScript")) {
Expand All @@ -243,12 +243,13 @@ public static int testInvariants(String inputFile, boolean doRange) throws IOExc
} else if (line.startsWith("Show")) {
showLine(line, pp);
} else if (line.startsWith("OnPairsOf")) {
equivalencesLine(line, pp, lineNumber);
equivalencesLine(line, pp, inputFile, lineNumber);
} else {
testLine(line, pp, lineNumber);
testLine(line, pp, inputFile, lineNumber);
}
} catch (final Exception e) {
parseErrorCount = parseError(parseErrorCount, line, e, lineNumber);
parseErrorCount =
parseError(parseErrorCount, line, e, inputFile, lineNumber);
continue;
}
}
Expand Down Expand Up @@ -323,7 +324,7 @@ protected String getFailure(int codepoint) {
}
}

private static void equivalencesLine(String line, ParsePosition pp, int lineNumber)
private static void equivalencesLine(String line, ParsePosition pp, String file, int lineNumber)
throws ParseException {
pp.setIndex("OnPairsOf".length());
final UnicodeSet domain = new UnicodeSet(line, pp, symbolTable);
Expand Down Expand Up @@ -504,7 +505,8 @@ private static void equivalencesLine(String line, ParsePosition pp, int lineNumb
}
errorMessageLines.addAll(counterexamples);
if (failure) {
reportTestFailure(lineNumber, String.join("\n", errorMessageLines).replace('\t', ' '));
reportTestFailure(
file, lineNumber, String.join("\n", errorMessageLines).replace('\t', ' '));
}
out.println(failure ? "<table class='f'>" : "<table>");
for (String counterexample : counterexamples) {
Expand All @@ -518,7 +520,7 @@ private static void equivalencesLine(String line, ParsePosition pp, int lineNumb
}
}

private static void inLine(ParsePosition pp, String line, int lineNumber)
private static void inLine(ParsePosition pp, String line, String file, int lineNumber)
throws ParseException {
pp.setIndex(2);
final PropertyPredicate propertyPredicate = getPropertyPredicate(pp, line);
Expand All @@ -539,7 +541,7 @@ private static void inLine(ParsePosition pp, String line, int lineNumber)
errorLister.setLineSeparator("\n");
errorLister.showSetNames(new PrintWriter(monoTable), failureSet);
errorLister.setTabber(htmlTabber);
reportTestFailure(lineNumber, errorMessage + "\n" + monoTable.toString());
reportTestFailure(file, lineNumber, errorMessage + "\n" + monoTable.toString());

if (doHtml) {
out.println("<table class='f'>");
Expand Down Expand Up @@ -921,7 +923,7 @@ private static void showMapLine(String line, ParsePosition pp) {
showLister.setMergeRanges(doRange);
}

private static void testLine(String line, ParsePosition pp, int lineNumber)
private static void testLine(String line, ParsePosition pp, String file, int lineNumber)
throws ParseException {
if (line.startsWith("Test")) {
line = line.substring(4).trim();
Expand Down Expand Up @@ -989,6 +991,7 @@ private static void testLine(String line, ParsePosition pp, int lineNumber)
rightSide,
"But Not In",
leftSide,
file,
lineNumber);
checkExpected(
rightAndLeft,
Expand All @@ -997,6 +1000,7 @@ private static void testLine(String line, ParsePosition pp, int lineNumber)
rightSide,
"And In",
leftSide,
file,
lineNumber);
checkExpected(
left_right,
Expand All @@ -1005,6 +1009,7 @@ private static void testLine(String line, ParsePosition pp, int lineNumber)
leftSide,
"But Not In",
rightSide,
file,
lineNumber);
}

Expand All @@ -1026,6 +1031,7 @@ private static void checkExpected(
String rightSide,
String leftStatus,
String leftSide,
String file,
int lineNumber) {
switch (expected) {
case empty:
Expand Down Expand Up @@ -1059,7 +1065,9 @@ private static void checkExpected(
errorLister.setLineSeparator("\n");
errorLister.showSetNames(new PrintWriter(monoTable), segment);
reportTestFailure(
lineNumber, String.join("\n", errorMessageLines) + "\n" + monoTable.toString());
file,
lineNumber,
String.join("\n", errorMessageLines) + "\n" + monoTable.toString());
errorLister.setTabber(htmlTabber);
if (doHtml) {
out.println("<table class='e'>");
Expand Down Expand Up @@ -1249,7 +1257,8 @@ private static void showSet(ParsePosition pp, final String value) {
println();
}

private static int parseError(int parseErrorCount, String line, Exception e, int lineNumber) {
private static int parseError(
int parseErrorCount, String line, Exception e, String file, int lineNumber) {
parseErrorCount++;
if (e instanceof ParseException) {
final int index = ((ParseException) e).getErrorOffset();
Expand All @@ -1263,7 +1272,7 @@ private static int parseError(int parseErrorCount, String line, Exception e, int
if (message != null) {
println("##" + message);
}
reportParseError(lineNumber, message);
reportParseError(file, lineNumber, message);
e.printStackTrace(out);

out.println("</pre>");
Expand Down Expand Up @@ -1358,19 +1367,19 @@ private static void println() {
println("");
}

private static void reportParseError(int lineNumber, String message) {
reportError(lineNumber, "Parse error", message);
private static void reportParseError(String file, int lineNumber, String message) {
reportError(file, lineNumber, "Parse error", message);
}

private static void reportTestFailure(int lineNumber, String message) {
reportError(lineNumber, "Invariant test failure", message);
private static void reportTestFailure(String file, int lineNumber, String message) {
reportError(file, lineNumber, "Invariant test failure", message);
}

private static void reportError(int lineNumber, String title, String message) {
private static void reportError(String file, int lineNumber, String title, String message) {
if (EMIT_GITHUB_ERRORS) {
System.err.println(
"::error file=unicodetools/src/main/resources/org/unicode/text/UCD/"
+ DEFAULT_FILE
+ file
+ ",line="
+ lineNumber
+ ",title="
Expand Down

0 comments on commit f02b9b9

Please sign in to comment.