From 88e8090d7ada1e1374bdc78833a670861ca233a7 Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Thu, 11 Oct 2012 22:22:33 +0400 Subject: [PATCH] Abort running tests on the first failure to communicate results back to the main process. Closes #557. --- testing/agent/src/main/java/sbt/ForkMain.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/testing/agent/src/main/java/sbt/ForkMain.java b/testing/agent/src/main/java/sbt/ForkMain.java index 835de80a8..587b4ff33 100755 --- a/testing/agent/src/main/java/sbt/ForkMain.java +++ b/testing/agent/src/main/java/sbt/ForkMain.java @@ -85,7 +85,7 @@ public class ForkMain { new Run().run(is, os); } finally { is.close(); - os.close(); + os.close(); } } private static class Run { @@ -101,16 +101,21 @@ public class ForkMain { } return false; } + class RunAborted extends RuntimeException { + RunAborted(Exception e) { super(e); } + } void write(ObjectOutputStream os, Object obj) { try { os.writeObject(obj); os.flush(); } catch (IOException e) { - System.err.println("Cannot write to socket"); + throw new RunAborted(e); } } - void run(ObjectInputStream is, final ObjectOutputStream os) throws Exception { + void runTests(ObjectInputStream is, final ObjectOutputStream os) throws Exception { final boolean ansiCodesSupported = is.readBoolean(); + final ForkTestDefinition[] tests = (ForkTestDefinition[]) is.readObject(); + int nFrameworks = is.readInt(); Logger[] loggers = { new Logger() { public boolean ansiCodesSupported() { return ansiCodesSupported; } @@ -122,8 +127,6 @@ public class ForkMain { } }; - final ForkTestDefinition[] tests = (ForkTestDefinition[]) is.readObject(); - int nFrameworks = is.readInt(); for (int i = 0; i < nFrameworks; i++) { final String implClassName = (String) is.readObject(); final String[] frameworkArgs = (String[]) is.readObject(); @@ -159,5 +162,12 @@ public class ForkMain { write(os, ForkTags.Done); is.readObject(); } + void run(ObjectInputStream is, final ObjectOutputStream os) throws Exception { + try { + runTests(is, os); + } catch (RunAborted e) { + System.err.println("Internal error when running tests: " + e.getMessage()); + } + } } }