Commit 694f87a3 authored by uglke's avatar uglke

Merge branch 'development' into 'development'

Use StringBuilder in Terminal instead of always overwriting old String

See merge request WS-17-18/assignment-tests!53
parents 3e2f1062 55dd075d
......@@ -40,7 +40,7 @@ public final class Terminal {
/**
* This field represents the output from a tested program to a test
*/
public static final LinkedList<String> OUT_TEST = new LinkedList<>();
public static final LinkedList<StringBuilder> OUT_TEST = new LinkedList<>();
/**
* Reads text from the "standard" input stream, buffering characters so as to provide for the efficient reading
......@@ -73,12 +73,13 @@ public final class Terminal {
String out = "Error, " + message;
if (isTest) {
String current = OUT_TEST.pollLast();
if (current == null || current.isEmpty()) {
OUT_TEST.add(out);
if (OUT_TEST.getLast() == null) {
OUT_TEST.pollLast();
OUT_TEST.add(new StringBuilder());
} else {
OUT_TEST.add(current + "\n" + out);
OUT_TEST.getLast().append("\n");
}
OUT_TEST.getLast().append(out);
} else if (isTestCreation) {
System.err.println(out);
if (useMyErrorMessagesInTestCreation) {
......@@ -103,8 +104,13 @@ public final class Terminal {
*/
public static void printLine(final Object object) {
if (isTest) {
String current = OUT_TEST.pollLast();
OUT_TEST.add((current == null ? "" : current + "\n") + object);
if (OUT_TEST.getLast() == null) {
OUT_TEST.pollLast();
OUT_TEST.add(new StringBuilder());
} else {
OUT_TEST.getLast().append("\n");
}
OUT_TEST.getLast().append(object);
} else if (isTestCreation) {
System.out.println(object);
testPairFile.append(String.valueOf(object)).append("\n");
......@@ -167,11 +173,12 @@ public final class Terminal {
}
}
}
//If the program outputted nothing we still have null which means "no output"
OUT_TEST.add(null);
assert !IN_TEST.isEmpty()
: "Either the executed test doesn't has quit as last input\n"
: "Either the executed test doesn't have quit as last input\n"
+ "or your quitting mechanism doesn't work properly.\n"
+ "Expect the second option or check the test!";
return IN_TEST.poll();
......
......@@ -58,14 +58,15 @@ public class Assignment1TestBase extends TestBase {
}
}
log.info("args[]: '" + strb.toString() + "'");
Terminal.OUT_TEST.add(null);
DummyMain.main(args);
String output = Terminal.OUT_TEST.poll();
StringBuilder output = Terminal.OUT_TEST.pollFirst();
if (acceptable) {
if (output != null && !output.equals(">>")) {
if (output != null) {
failAndLog("test should have succeeded");
}
} else {
if (output == null || !output.startsWith("Error")) {
if (output == null || !output.toString().startsWith("Error")) {
failAndLog("test should have failed");
}
}
......
......@@ -61,7 +61,7 @@ public class CaseCreator {
for (TestPair testPair : testPairs) {
testPairfile.append("> " + testPair.getInput() + "\n");
String partOutput;
StringBuilder partOutput;
StringBuilder stringBuilder = new StringBuilder();
do {
partOutput = Terminal.OUT_TEST.pollFirst();
......
......@@ -174,7 +174,7 @@ public class CaseCreator {
testPairFile.append(testPair.getInput());
testPairFile.append("\n");
String partOutput;
StringBuilder partOutput;
StringBuilder stringBuilder = new StringBuilder();
do {
partOutput = Terminal.OUT_TEST.pollFirst();
......
......@@ -25,7 +25,6 @@ public class PerformanceTest extends Assignment2TestBase {
* amount of memory.
*/
@Disabled
@Test
@DisplayName("PerformanceTest2")
void performanceTest2() {
......@@ -36,7 +35,6 @@ public class PerformanceTest extends Assignment2TestBase {
testUsingPairs(pairs, () -> DummyMain.main(null));
}
@Disabled
@Test
@DisplayName("PerformanceTest3")
void performanceTest3() {
......
......@@ -106,9 +106,8 @@ public abstract class TestBase {
if (showAllProgramOutput && !testPassed && !Terminal.OUT_TEST.isEmpty()) {
System.out.println("The output after that was:");
while (!Terminal.OUT_TEST.isEmpty()) {
System.out.println(popProgramOutput());
}
while (!Terminal.OUT_TEST.isEmpty())
System.out.println(Terminal.OUT_TEST.pollFirst().toString());
}
clearData();
......@@ -160,17 +159,14 @@ public abstract class TestBase {
* @return a string containing the output
*/
protected String popProgramOutput() {
return Terminal.OUT_TEST.pollFirst();
}
/**
* Gets the next output from the output-queue and removes it
* This does the same as {@code popProgramOutput}
*
* @return a string containing the output
*/
protected String getNextProgramOutput() {
return popProgramOutput();
//Shouldn't ever happen, but if it does, we effectively have no output
if (Terminal.OUT_TEST.isEmpty())
return null;
StringBuilder res = Terminal.OUT_TEST.pollFirst();
if (res == null)
return null;
else
return res.toString();
}
/**
......@@ -207,14 +203,11 @@ public abstract class TestBase {
for (TestPair testPair : testPairs) {
log.info("Testing " + testPair);
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:
if (!testPair.getOutput().equals(output)) {
if (output == null || !testPair.getOutput().equals(output)) {
log.info(" Failed!\n");
printLog();
assertEquals(testPair.getOutput(), output);
......
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