When forking tests serialize Event.error as well. Closes #543.

This commit is contained in:
Eugene Vigdorchik 2012-09-12 20:56:51 +04:00 committed by Mark Harrah
parent 607824cc22
commit b8ef434ec1
4 changed files with 59 additions and 2 deletions

View File

@ -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")
}
))
}

View File

@ -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")
}
}

View File

@ -0,0 +1,3 @@
-> test
> check

View File

@ -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]));