Commit 546aeec3 authored by Alexander's avatar Alexander
Browse files

Replace non-output placeholder with null

parent 05d8d8e0
......@@ -70,7 +70,7 @@ public final class Terminal {
if (current == null || current.isEmpty()) {
OUT_TEST.add(out);
} else {
OUT_TEST.add((current.equals(">>") ? "" : current + "\n") + out);
OUT_TEST.add(current + "\n" + out);
}
} else if (isTestCreation) {
System.err.println(out);
......@@ -97,7 +97,7 @@ public final class Terminal {
public static void printLine(final Object object) {
if (isTest) {
String current = OUT_TEST.pollLast();
OUT_TEST.add((current.equals(">>") ? "" : current + "\n") + object);
OUT_TEST.add((current == null ? "" : current + "\n") + object);
} else if (isTestCreation) {
System.out.println(object);
testPairFile.append(String.valueOf(object)).append("\n");
......@@ -149,7 +149,7 @@ public final class Terminal {
}
else {
//If the program outputted nothing we still have at least an empty line
OUT_TEST.add(">>");
OUT_TEST.add(null);
assert !IN_TEST.isEmpty()
: "Either the executed test doesn't has quit as last input\n"
......
......@@ -308,17 +308,12 @@ public abstract class TestBase {
String output = popProgramOutput();
assert output != null : "got no output, this should never happen, since this is handled by the Terminal";
assert output != null || testPair.getType().equals(TestPair.Type.CHECK_FOR_NO_OUTPUT)
: "got no output, this should never happen, since this is handled by the Terminal";
switch (testPair.getType()) {
case CHECK_EQUALS:
if (testPair.getOutput().equals("")) {
if (!output.equals(">>")) {
log.info(" Failed!\n");
printLog();
fail("Output should have been empty but was:"+output);
}
} else if (!output.equals(testPair.getOutput())) {
if (!output.equals(testPair.getOutput())) {
log.info(" Failed!\n");
printLog();
assertEquals(testPair.getOutput(), output);
......@@ -344,6 +339,13 @@ public abstract class TestBase {
break;
case NO_CHECK:
break;
case CHECK_FOR_NO_OUTPUT:
if (testPair.getOutput() != null) {
log.info(" Failed!\n");
printLog();
fail("Output should have been empty but was:" + output);
}
break;
default:
fail("Unimplemented error check");
}
......@@ -428,7 +430,7 @@ public abstract class TestBase {
}
if (builder.length() == 0 && input.length() != 0) {
fail("Test '" + testName + "' failed. No output for '" + input + "' was specified");
testPairs.add(new TestPair(input));
} else {
testPairs.add(getIOTestPair(builder, input));
}
......@@ -442,7 +444,9 @@ public abstract class TestBase {
private TestPair getIOTestPair(StringBuilder builder, String input) {
final String startsWithPostfix = "...";
String output = "";
if (builder.length() != 0)
if (builder.length() == 0) {
return new TestPair(input);
} else if (builder.length() != 0)
output = builder.deleteCharAt(builder.length() - 1).toString();
if (output.startsWith(ERROR_PREFIX)) {
return new TestPair(input, output, TestPair.Type.CHECK_FOR_ERROR);
......
package test;
import edu.kit.informatik.Terminal;
public class TestPair {
public String getFailMessage(String actualOutput) {
return "Fail with " + this + "\nOutput was"
......@@ -14,6 +12,7 @@ public class TestPair {
CHECK_STARTS_WITH,
CHECK_FOR_ERROR,
CHECK_CONTAINS,
CHECK_FOR_NO_OUTPUT,
NO_CHECK,
}
......@@ -44,6 +43,17 @@ public class TestPair {
this.output = "";
}
/**
* Constructs a new TestPair, that tests for an empty output for a given input
*
* @param input is the input to check
*/
public TestPair(String input) {
this.input = input;
this.output = null;
this.type = Type.CHECK_FOR_NO_OUTPUT;
}
public String getInput() {
return input;
}
......@@ -58,12 +68,14 @@ public class TestPair {
@Override
public String toString() {
String outStr = "'" + output.split("\n")[0] + "\'";
if (type == Type.CHECK_FOR_ERROR && output.equals(TestBase.ERROR_PREFIX + "...")) {
if (type == Type.CHECK_FOR_ERROR && output.equals(TestBase.ERROR_PREFIX + "...")
|| type == Type.CHECK_FOR_NO_OUTPUT) {
return "TestPair{'" + input + " @" + type + "}";
}
String outStr = "'" + output.split("\n")[0] + "\'";
return "TestPair{"
+ "'" + input + "\'->" + outStr + (output.contains("\n") ? "..." : "")
+ " @" + 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