Permalink
Browse files

Use java.lang.Throwable.setStackTrace. Proper fix for #543.

  • Loading branch information...
1 parent 1c1e5c4 commit 960d17c358d368d2d82e4ec330f2a4dfae528922 @vigdorchik vigdorchik committed with Nov 15, 2012
@@ -27,8 +27,7 @@ private[sbt] object ForkTests {
}
val argMap = frameworks.map {
f => f.implClassName -> opts.flatMap {
- case Argument(None, args) => args
- case Argument(Some(`f`), args) => args
+ case Argument(None | Some(`f`), args) => args
case _ => Nil
}
}.toMap
@@ -112,4 +111,4 @@ private final class React(is: ObjectInputStream, os: ObjectOutputStream, log: Lo
listeners.foreach(_ endGroup (group, result))
react()
}
-}
+}
@@ -2,19 +2,23 @@ import sbt._
import Keys._
import Tests._
import Defaults._
+import java.io.{ CharArrayWriter, PrintWriter }
object Ticket543Test extends Build {
val marker = new File("marker")
- val check = TaskKey[Unit]("check", "Check non-null error has been returned.")
+ val check = TaskKey[Unit]("check", "Check correct 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()
+ for (e <- event.detail.filter(_.result == org.scalatools.testing.Result.Failure)) {
+ if (e.error ne null) {
+ val caw = new CharArrayWriter
+ e.error.printStackTrace(new PrintWriter(caw))
+ if (caw.toString.contains("Test.scala:"))
+ marker.createNewFile()
}
}
}
@@ -25,7 +29,7 @@ object Ticket543Test extends Build {
check := {
val exists = marker.exists
marker.delete()
- if (!exists) error("Null error had been returned previously")
+ if (!exists) error("Null or invalid error had been returned previously")
}
))
}
@@ -48,17 +48,15 @@ public ForkTestDefinition(String name, Fingerprint fingerprint) {
}
}
}
- static class ForkError extends Exception implements Serializable {
+ static class ForkError extends Exception {
private String originalMessage;
- private StackTraceElement[] originalStackTrace;
private ForkError cause;
ForkError(Throwable t) {
originalMessage = t.getMessage();
- originalStackTrace = t.getStackTrace();
+ setStackTrace(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 {

0 comments on commit 960d17c

Please sign in to comment.