properly wrap unknown test data structures in serializable ones

This commit is contained in:
Mark Harrah 2013-06-28 11:20:47 -04:00
parent 3e74b92bf8
commit a1a00526ff
4 changed files with 16 additions and 8 deletions

View File

@ -11,7 +11,7 @@ import Tests.{Output => TestOutput, _}
import ForkMain._
private[sbt] object ForkTests {
def apply(runners: Map[TestFramework, Runner], tests: List[TestDefinition], config: Execution, loader: ClassLoader, classpath: Seq[File], fork: ForkOptions, log: Logger): Task[TestOutput] = {
def apply(runners: Map[TestFramework, Runner], tests: List[TestDefinition], config: Execution, classpath: Seq[File], fork: ForkOptions, log: Logger): Task[TestOutput] = {
val opts = config.options.toList
val listeners = opts flatMap {
case Listeners(ls) => ls
@ -46,7 +46,7 @@ private[sbt] object ForkTests {
os.writeBoolean(log.ansiCodesSupported)
val testsFiltered = tests.filter(test => filters.forall(_(test.name))).map{
t => new TaskDef(t.name, t.fingerprint, t.explicitlySpecified, t.selectors)
t => new TaskDef(t.name, forkFingerprint(t.fingerprint), t.explicitlySpecified, t.selectors)
}.toArray
os.writeObject(testsFiltered)
@ -92,6 +92,12 @@ private[sbt] object ForkTests {
TestOutput(TestResult.Passed, Map.empty[String, SuiteResult], Iterable.empty)
} tagw (config.tags: _*)
}
private[this] def forkFingerprint(f: Fingerprint): Fingerprint with Serializable =
f match {
case s: SubclassFingerprint => new ForkMain.SubclassFingerscan(s)
case a: AnnotatedFingerprint => new ForkMain.AnnotatedFingerscan(a)
case _ => error("Unknown fingerprint type: " + f.getClass)
}
}
private final class React(is: ObjectInputStream, os: ObjectOutputStream, log: Logger, listeners: Seq[TestReportListener], results: mutable.Map[String, SuiteResult])
{

View File

@ -484,7 +484,7 @@ object Defaults extends BuildCommon
case Tests.Group(name, tests, runPolicy) =>
runPolicy match {
case Tests.SubProcess(opts) =>
ForkTests(runners, tests.toList, config, loader, cp.files, opts, s.log) tag Tags.ForkedTestGroup
ForkTests(runners, tests.toList, config, cp.files, opts, s.log) tag Tags.ForkedTestGroup
case Tests.InProcess =>
Tests(frameworks, loader, runners, tests, config, s.log)
}

View File

@ -147,7 +147,7 @@ public class ForkMain {
public void warn(String s) { write(os, new Object[]{ForkTags.Warn, s}); }
public void info(String s) { write(os, new Object[]{ForkTags.Info, s}); }
public void debug(String s) { write(os, new Object[]{ForkTags.Debug, s}); }
public void trace(Throwable t) { write(os, t); }
public void trace(Throwable t) { write(os, new ForkError(t)); }
}
};
@ -254,7 +254,7 @@ public class ForkMain {
} catch (Throwable t) {
try {
logError(os, "Uncaught exception when running tests: " + t.toString());
write(os, t);
write(os, new ForkError(t));
} catch (Throwable t2) {
internalError(t2);
}
@ -263,7 +263,7 @@ public class ForkMain {
void internalError(Throwable t) {
System.err.println("Internal error when running tests: " + t.toString());
}
ForkEvent testEvent(final String fullyQualifiedName, final Fingerprint fingerprint, final Selector selector, final Status r, final Throwable err, final long duration) {
ForkEvent testEvent(final String fullyQualifiedName, final Fingerprint fingerprint, final Selector selector, final Status r, final ForkError err, final long duration) {
final OptionalThrowable throwable;
if (err == null)
throwable = new OptionalThrowable();
@ -288,8 +288,9 @@ public class ForkMain {
}
ForkEvent testError(ObjectOutputStream os, TaskDef taskDef, String message, Throwable t) {
logError(os, message);
write(os, t);
return testEvent(taskDef.fullyQualifiedName(), taskDef.fingerprint(), new SuiteSelector(), Status.Error, t, 0);
ForkError fe = new ForkError(t);
write(os, fe);
return testEvent(taskDef.fullyQualifiedName(), taskDef.fingerprint(), new SuiteSelector(), Status.Error, fe, 0);
}
}
}

View File

@ -1,6 +1,7 @@
package sbt;
import sbt.testing.*;
import java.io.Serializable;
final class FrameworkWrapper implements Framework {