diff --git a/sbt/src/sbt-test/tests/t543/project/Ticket543Test.scala b/sbt/src/sbt-test/tests/t543/project/Ticket543Test.scala new file mode 100755 index 000000000..dfad98959 --- /dev/null +++ b/sbt/src/sbt-test/tests/t543/project/Ticket543Test.scala @@ -0,0 +1,31 @@ +import sbt._ +import Keys._ +import Tests._ +import Defaults._ + +object Ticket543Test extends Build { + val marker = new File("marker") + val check = TaskKey[Unit]("check", "Check non-null error has been returned.") + + lazy val root = Project("root", file("."), settings = defaultSettings ++ Seq( + libraryDependencies += "org.scalatest" %% "scalatest" % "1.8" % "test", + fork := true, + testListeners += new TestReportListener { + def testEvent(event: TestEvent) { + for (e <- event.detail.filter(_.result() == org.scalatools.testing.Result.Failure)) { + if (e.error() ne null) { + marker.createNewFile() + } + } + } + def startGroup(name: String) {} + def endGroup(name: String, t: Throwable) {} + def endGroup(name: String, result: TestResult.Value) {} + }, + check := { + val exists = marker.exists + marker.delete() + if (!exists) error("Null error had been returned previously") + } + )) +} diff --git a/sbt/src/sbt-test/tests/t543/src/test/scala/Test.scala b/sbt/src/sbt-test/tests/t543/src/test/scala/Test.scala new file mode 100755 index 000000000..84ea70f61 --- /dev/null +++ b/sbt/src/sbt-test/tests/t543/src/test/scala/Test.scala @@ -0,0 +1,8 @@ +import org.scalatest.FunSuite + +class SBT543 extends FunSuite { + class MyCustomException(message: String) extends RuntimeException(message) + test("throws a custom excpetion") { + throw new MyCustomException("this is a custom exception") + } +} diff --git a/sbt/src/sbt-test/tests/t543/test b/sbt/src/sbt-test/tests/t543/test new file mode 100755 index 000000000..79e059fc5 --- /dev/null +++ b/sbt/src/sbt-test/tests/t543/test @@ -0,0 +1,3 @@ +-> test + +> check \ No newline at end of file diff --git a/testing/agent/src/main/java/sbt/ForkMain.java b/testing/agent/src/main/java/sbt/ForkMain.java index b92ed1c5e..835de80a8 100755 --- a/testing/agent/src/main/java/sbt/ForkMain.java +++ b/testing/agent/src/main/java/sbt/ForkMain.java @@ -48,19 +48,34 @@ public class ForkMain { } } } + static class ForkError extends Exception implements Serializable { + private String originalMessage; + private StackTraceElement[] originalStackTrace; + private ForkError cause; + ForkError(Throwable t) { + originalMessage = t.getMessage(); + originalStackTrace = t.getStackTrace(); + if (t.getCause() != null) cause = new ForkError(t.getCause()); + } + public String getMessage() { return originalMessage; } + public StackTraceElement[] getStackTrace() { return originalStackTrace; } + public Exception getCause() { return cause; } + } static class ForkEvent implements Event, Serializable { private String testName; private String description; private Result result; + private Throwable error; ForkEvent(Event e) { testName = e.testName(); description = e.description(); result = e.result(); + if (e.error() != null) error = new ForkError(e.error()); } public String testName() { return testName; } public String description() { return description; } - public Result result() { return result;} - public Throwable error() { return null; } + public Result result() { return result; } + public Throwable error() { return error; } } public static void main(String[] args) throws Exception { Socket socket = new Socket(InetAddress.getByName(null), Integer.valueOf(args[0]));