From 2de2e3947aaf56e39f697a5256fe79b290290a15 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Fri, 24 Mar 2017 11:53:33 -0400 Subject: [PATCH] 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. --- .../fixture/LispInterpreterFixture.java | 2 +- test/main/MainTest.java | 16 +++++++++++----- test/terminal/FlushListener.java | 6 +++--- test/terminal/VirtualTerminalInteractor.java | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/test/acceptance/fixture/LispInterpreterFixture.java b/test/acceptance/fixture/LispInterpreterFixture.java index a4b759a..bb4f0d2 100644 --- a/test/acceptance/fixture/LispInterpreterFixture.java +++ b/test/acceptance/fixture/LispInterpreterFixture.java @@ -17,7 +17,7 @@ public class LispInterpreterFixture { private static LispInterpreter interpreter = null; public static void buildInterpreter() { - LispInterpreterBuilder builder = LispInterpreterBuilderImpl.getInstance(); + LispInterpreterBuilder builder = new LispInterpreterBuilderImpl() {}; builder.setOutput(new PrintStream(outputStream)); builder.setErrorOutput(new PrintStream(outputStream)); builder.setNotInteractive(); diff --git a/test/main/MainTest.java b/test/main/MainTest.java index 462dd75..03e32c8 100644 --- a/test/main/MainTest.java +++ b/test/main/MainTest.java @@ -41,9 +41,12 @@ public class MainTest { latch = new CountDownLatch(1); new Thread(() -> { - LispMain main = new LispMain(new LispInterpreterBuilderImpl() {}, terminal.getConfiguration()); - main.runInteractive(); - latch.countDown(); + try { + LispMain main = new LispMain(new LispInterpreterBuilderImpl() {}, terminal.getConfiguration()); + main.runInteractive(); + } finally { + latch.countDown(); + } }).start(); return terminal; @@ -121,8 +124,11 @@ public class MainTest { } @Test - public void defaultConstructorCoverage() { - new LispMain(); + public void runMain() { + 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()); } } diff --git a/test/terminal/FlushListener.java b/test/terminal/FlushListener.java index a754875..8d7c377 100644 --- a/test/terminal/FlushListener.java +++ b/test/terminal/FlushListener.java @@ -12,12 +12,12 @@ public class FlushListener implements VirtualTerminalListener { this.flushCount = 0; } - public int getFlushCount() { + public synchronized int getFlushCount() { return flushCount; } - public void resetFlushCount() { - flushCount = 0; + public synchronized void reduceFlushCount(int reduction) { + flushCount -= reduction; } @Override diff --git a/test/terminal/VirtualTerminalInteractor.java b/test/terminal/VirtualTerminalInteractor.java index e72ee18..f916dca 100644 --- a/test/terminal/VirtualTerminalInteractor.java +++ b/test/terminal/VirtualTerminalInteractor.java @@ -110,7 +110,7 @@ public class VirtualTerminalInteractor { while (flushListener.getFlushCount() < flushCount) flushListener.wait(); - flushListener.resetFlushCount(); + flushListener.reduceFlushCount(flushCount); } } catch (InterruptedException ignored) {} }