Increase test coverage

Fixed an intermittent deadlock in MainTest:
FlushListener could receive more than the expected number of flushes
before the VirtualTerminalInteractor was given control. So by setting
the flush count to zero in waitForFlushes(), flushes could be lost. Now
it only reduces the number of flushes by the expected number.
This commit is contained in:
Mike Cifelli 2017-03-24 11:53:33 -04:00
parent a8620307c9
commit 2de2e3947a
4 changed files with 16 additions and 10 deletions

View File

@ -17,7 +17,7 @@ public class LispInterpreterFixture {
private static LispInterpreter interpreter = null; private static LispInterpreter interpreter = null;
public static void buildInterpreter() { public static void buildInterpreter() {
LispInterpreterBuilder builder = LispInterpreterBuilderImpl.getInstance(); LispInterpreterBuilder builder = new LispInterpreterBuilderImpl() {};
builder.setOutput(new PrintStream(outputStream)); builder.setOutput(new PrintStream(outputStream));
builder.setErrorOutput(new PrintStream(outputStream)); builder.setErrorOutput(new PrintStream(outputStream));
builder.setNotInteractive(); builder.setNotInteractive();

View File

@ -41,9 +41,12 @@ public class MainTest {
latch = new CountDownLatch(1); latch = new CountDownLatch(1);
new Thread(() -> { new Thread(() -> {
LispMain main = new LispMain(new LispInterpreterBuilderImpl() {}, terminal.getConfiguration()); try {
main.runInteractive(); LispMain main = new LispMain(new LispInterpreterBuilderImpl() {}, terminal.getConfiguration());
latch.countDown(); main.runInteractive();
} finally {
latch.countDown();
}
}).start(); }).start();
return terminal; return terminal;
@ -121,8 +124,11 @@ public class MainTest {
} }
@Test @Test
public void defaultConstructorCoverage() { public void runMain() {
new LispMain(); LispMain.main(new String[] { "test/main/test-files/file.lisp" });
assertEquals("", getSystemErrLog());
assertEquals(format("{0}{1}{2}\n\n", ANSI_GREEN, "RADISH", ANSI_RESET), getSystemOutLog());
} }
} }

View File

@ -12,12 +12,12 @@ public class FlushListener implements VirtualTerminalListener {
this.flushCount = 0; this.flushCount = 0;
} }
public int getFlushCount() { public synchronized int getFlushCount() {
return flushCount; return flushCount;
} }
public void resetFlushCount() { public synchronized void reduceFlushCount(int reduction) {
flushCount = 0; flushCount -= reduction;
} }
@Override @Override

View File

@ -110,7 +110,7 @@ public class VirtualTerminalInteractor {
while (flushListener.getFlushCount() < flushCount) while (flushListener.getFlushCount() < flushCount)
flushListener.wait(); flushListener.wait();
flushListener.resetFlushCount(); flushListener.reduceFlushCount(flushCount);
} }
} catch (InterruptedException ignored) {} } catch (InterruptedException ignored) {}
} }