Commit c9d53d9e authored by Martin Spoto's avatar Martin Spoto
Browse files

Uncomment occurence test; print whole test if line differs

parent e063833e
......@@ -233,6 +233,27 @@ public class ProloGraalTestRunner extends ParentRunner<TestCase> {
return outFile.toString();
}
private String buildErrorMsg(String title, String input, List<String> expectedLines, List<String> actualLines) {
return title +
"\nInput : \n" +
input +
"\nExpected : \n" +
expectedLines.stream().map(x -> "\t" + x).collect(Collectors.joining("\n")) +
"\nActual : \n" +
actualLines.stream().map(x -> "\t" + x).collect(Collectors.joining("\n")) +
"\n";
}
private void addError(List<String> errors, String title, String input, List<String> expectedLines, List<String> actualLines) {
String errorMsg = buildErrorMsg(
title,
input,
expectedLines,
actualLines);
System.err.println(errorMsg);
errors.add(errorMsg);
}
@Override
protected void runChild(TestCase testCase, RunNotifier notifier) {
notifier.fireTestStarted(testCase.name);
......@@ -247,7 +268,7 @@ public class ProloGraalTestRunner extends ParentRunner<TestCase> {
printer.flush();
String actualOutput = new String(out.toByteArray());
String[] input = testCase.testInput.split("\\R");
List<List<String>> linesPerInput;
......@@ -286,7 +307,7 @@ public class ProloGraalTestRunner extends ParentRunner<TestCase> {
List<String> errors = new ArrayList<>();
for (int i = 0; i < linesPerInput.size(); i++) {
outer: for (int i = 0; i < linesPerInput.size(); i++) {
List<String> actualLines = linesPerInput.get(i);
List<String> expectedLines = expectedLinesForInput.get(i);
......@@ -299,24 +320,29 @@ public class ProloGraalTestRunner extends ParentRunner<TestCase> {
}
if(expectedLines.size() != actualLines.size()) {
String errorMsg = "Output does not have expected size for input \"" +
msg +
"\"\nExpected : \n" +
expectedLines.stream().map(x -> "\t" + x).collect(Collectors.joining("\n")) +
"\nActual : \n" +
actualLines.stream().map(x -> "\t" + x).collect(Collectors.joining("\n")) +
"\n";
System.err.println(errorMsg);
errors.add(errorMsg);
addError(errors,
"Expected number of lines is different from actual",
msg,
expectedLines,
actualLines);
continue;
}
for(int j = 0; j < actualLines.size(); j++) {
Assert.assertEquals(msg, expectedLines.get(j), actualLines.get(j));
if (!expectedLines.get(j).equals(actualLines.get(j))) {
addError(
errors,
"Line content is different from what was expected",
msg,
expectedLines,
actualLines
);
continue outer;
}
}
}
if(!errors.isEmpty()) {
throw new AssertionError(errors.get(0));
}
if (!errors.isEmpty()) {
throw new AssertionError(errors.get(0));
}
} catch (Throwable ex) {
notifier.fireTestFailure(new Failure(testCase.name, ex));
......@@ -328,7 +354,7 @@ public class ProloGraalTestRunner extends ParentRunner<TestCase> {
}
}
private static void run(Context context, Path path, PrintWriter out) throws IOException {
private static void run(Context context, Path path, PrintWriter out) throws IOException {
try {
/* Parse the SL source file. */
Source source = Source.newBuilder(ProloGraalLanguage.ID, path.toFile()).interactive(true).build();
......
......@@ -14,4 +14,4 @@ multiple(X, b, a).
nested(X, one(Y, two(three(a)))).
f(B, h(A)).
indirection(A, B, C, x).
% occurs(X, X). TODO enable with when occurs check is fixed
\ No newline at end of file
occurs(X, X).
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment