Commit ada7c4f6 authored by Alexander's avatar Alexander

Improve fail message

parent 17651f29
......@@ -204,10 +204,10 @@ public abstract class TestBase {
for (TestPair testPair : testPairs) {
log.info("Testing " + testPair);
String output = popProgramOutput();
assert output != null || testPair.getType().equals(TestPair.Type.CHECK_FOR_NO_OUTPUT)
assert !Terminal.OUT_TEST.isEmpty()
: "got no output, this should never happen, since this is handled by the Terminal";
String output = popProgramOutput();
switch (testPair.getType()) {
case CHECK_EQUALS:
......@@ -218,19 +218,19 @@ public abstract class TestBase {
}
break;
case CHECK_STARTS_WITH:
if (!(output != null && output.startsWith(testPair.getOutput()))) {
if (output == null || !output.startsWith(testPair.getOutput())) {
log.info(" Failed!\n");
failAndLog(testPair.getFailMessage(output));
}
break;
case CHECK_CONTAINS:
if (!(output != null && output.contains(testPair.getOutput()))) {
if (output == null || !output.contains(testPair.getOutput())) {
log.info(" Failed!\n");
failAndLog(testPair.getFailMessage(output));
}
break;
case CHECK_FOR_ERROR:
if (!(output != null && output.startsWith(ERROR_PREFIX))) {
if (output == null || !output.startsWith(ERROR_PREFIX)) {
log.info(" Failed!\n");
failAndLog(testPair.getFailMessage(output));
}
......@@ -241,7 +241,6 @@ public abstract class TestBase {
printLog();
fail("Output should have been empty but was:" + output);
}
break;
case NO_CHECK:
break;
......
......@@ -2,6 +2,10 @@ package test;
public class TestPair {
public String getFailMessage(String actualOutput) {
if (actualOutput == null) {
return "Fail with " + this + "\nThe program provided no output for that command";
}
return "Fail with " + this + "\nOutput was"
+ (actualOutput.contains("\n") ? "\n" : " ")
+ actualOutput + (actualOutput.isEmpty() ? "(empty)" : "");
......@@ -68,7 +72,6 @@ public class TestPair {
@Override
public String toString() {
if (type == Type.CHECK_FOR_ERROR && output.equals(TestBase.ERROR_PREFIX + "...")
|| type == Type.CHECK_FOR_NO_OUTPUT) {
return "TestPair{'" + input + " @" + type + "}";
......
Markdown is supported
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