diff --git a/src/main/java/com/fathzer/jchess/uci/UCI.java b/src/main/java/com/fathzer/jchess/uci/UCI.java index c68eb50..f503025 100644 --- a/src/main/java/com/fathzer/jchess/uci/UCI.java +++ b/src/main/java/com/fathzer/jchess/uci/UCI.java @@ -153,6 +153,10 @@ protected void doNewGame(Deque tokens) { } protected void doPosition(Deque tokens) { + if (tokens.isEmpty()) { + debug("missing position definition"); + return; + } final String first = tokens.pop(); final String fen; if ("fen".equals(first)) { diff --git a/src/test/java/com/fathzer/jchess/uci/UCITest.java b/src/test/java/com/fathzer/jchess/uci/UCITest.java index 55a19bd..98d4e2b 100644 --- a/src/test/java/com/fathzer/jchess/uci/UCITest.java +++ b/src/test/java/com/fathzer/jchess/uci/UCITest.java @@ -28,11 +28,11 @@ void clear() { @Test void test() { -// assertFalse(uci.post("cjhjhl",500)); -// assertFalse(uci.getDebug().isEmpty()); + assertFalse(uci.post("cjhjhl",500)); + assertFalse(uci.getDebug().isEmpty()); clear(); assertTrue(uci.post("position", 60000)); - System.out.println(uci.getOutput()); + assertFalse(uci.getDebug().isEmpty()); } } diff --git a/src/test/java/com/fathzer/jchess/uci/util/InstrumentedUCI.java b/src/test/java/com/fathzer/jchess/uci/util/InstrumentedUCI.java index c782995..cace2f5 100644 --- a/src/test/java/com/fathzer/jchess/uci/util/InstrumentedUCI.java +++ b/src/test/java/com/fathzer/jchess/uci/util/InstrumentedUCI.java @@ -22,7 +22,7 @@ private UnknownCommandException(String command) { private final BlockingQueue input; private final BlockingQueue output; private final BlockingQueue debug; - private final Map exceptions; + private final Map exceptions; public InstrumentedUCI(Engine defaultEngine) { super(defaultEngine); @@ -47,6 +47,11 @@ protected void out(CharSequence message) { output.add(message.toString()); } + @Override + protected void err(String tag, Throwable e) { + exceptions.put(tag, e); + } + @Override protected void debug(CharSequence message) { debug.add(message.toString()); @@ -75,7 +80,7 @@ public boolean post(String command, long timeOutMS) { try { synchronized (this) { wait(timeOutMS); - final Exception e = exceptions.get(command); + final Throwable e = exceptions.get(command); if (e!=null) { if (e instanceof UnknownCommandException) { return false;