This commit is contained in:
Eugene Vigdorchik 2012-04-03 19:43:59 +04:00
parent cdfc72d05d
commit 291db63af3
4 changed files with 62 additions and 69 deletions

View File

@ -198,7 +198,7 @@ object Keys
val testListeners = TaskKey[Seq[TestReportListener]]("test-listeners", "Defines test listeners.")
val testExecution = TaskKey[Tests.Execution]("test-execution", "Settings controlling test execution")
val testFilter = TaskKey[Seq[String] => String => Boolean]("test-filter", "Filter controlling whether the test is executed")
val testGrouping = TaskKey[Seq[Tests.Group]]("test-grouping", "Groups discovered tests into groups.")
val testGrouping = TaskKey[Seq[Tests.Group]]("test-grouping", "Collects discovered tests into groups. Whether to fork and the options for forking are configurable on a per-group basis.")
val isModule = AttributeKey[Boolean]("is-module", "True if the target is a module.")
// Classpath/Dependency Management Keys

View File

@ -38,57 +38,50 @@ private[sbt] object ForkTests {
val results = collection.mutable.Map.empty[String, TestResult.Value]
def output = (overall(results.values), results.toMap)
def run = {
val socketOpt = try {
Some(server.accept())
} catch {
case e: IOException => None
}
for (socket <- socketOpt) {
val os = new ObjectOutputStream(socket.getOutputStream)
val is = new ObjectInputStream(socket.getInputStream)
val socket = server.accept()
val os = new ObjectOutputStream(socket.getOutputStream)
val is = new ObjectInputStream(socket.getInputStream)
import Tags._
@annotation.tailrec def react: Unit = is.readObject match {
case `Done` => os.writeObject(Done);
case Array(`Error`, s: String) => log.error(s); react
case Array(`Warn`, s: String) => log.warn(s); react
case Array(`Info`, s: String) => log.info(s); react
case Array(`Debug`, s: String) => log.debug(s); react
case t: Throwable => log.trace(t); react
case tEvents: Array[Event] =>
for (first <- tEvents.headOption) listeners.foreach(_ startGroup first.testName)
val event = TestEvent(tEvents)
listeners.foreach(_ testEvent event)
for (first <- tEvents.headOption) {
val result = event.result getOrElse TestResult.Passed
results += first.testName -> result
listeners.foreach(_ endGroup (first.testName, result))
}
react
}
try {
os.writeBoolean(log.ansiCodesSupported)
val testsFiltered = tests.filter(test => filters.forall(_(test.name))).map{
t => new ForkTestDefinition(t.name, t.fingerprint)
}.toArray
os.writeObject(testsFiltered)
os.writeInt(frameworks.size)
for ((clazz, args) <- argMap) {
os.writeObject(clazz)
os.writeObject(args.toArray)
import Tags._
@annotation.tailrec def react: Unit = is.readObject match {
case `Done` => os.writeObject(Done);
case Array(`Error`, s: String) => log.error(s); react
case Array(`Warn`, s: String) => log.warn(s); react
case Array(`Info`, s: String) => log.info(s); react
case Array(`Debug`, s: String) => log.debug(s); react
case t: Throwable => log.trace(t); react
case tEvents: Array[Event] =>
for (first <- tEvents.headOption) listeners.foreach(_ startGroup first.testName)
val event = TestEvent(tEvents)
listeners.foreach(_ testEvent event)
for (first <- tEvents.headOption) {
val result = event.result getOrElse TestResult.Passed
results += first.testName -> result
listeners.foreach(_ endGroup (first.testName, result))
}
react
} finally {
is.close()
os.close()
}
try {
os.writeBoolean(log.ansiCodesSupported)
val testsFiltered = tests.filter(test => filters.forall(_(test.name))).map{
t => new ForkTestDefinition(t.name, t.fingerprint)
}.toArray
os.writeObject(testsFiltered)
os.writeInt(frameworks.size)
for ((clazz, args) <- argMap) {
os.writeObject(clazz)
os.writeObject(args.toArray)
}
}
}
}
react
} finally {
is.close(); os.close(); socket.close()
}
}
}
try {
testListeners.foreach(_.doInit())
@ -96,7 +89,7 @@ private[sbt] object ForkTests {
val fullCp = classpath ++: Seq(IO.classLocationFile[ForkMain], IO.classLocationFile[Framework])
val options = javaOpts ++: Seq("-classpath", fullCp mkString File.pathSeparator, classOf[ForkMain].getCanonicalName, server.getLocalPort.toString)
val ec = Fork.java(javaHome, options, StdoutOutput)
val ec = Fork.java(javaHome, options, LoggedOutput(log))
if (ec != 0) log.error("Running java with options " + options.mkString(" ") + " failed with exit code " + ec)
} finally {
server.close()

View File

@ -40,7 +40,7 @@ object Tests
final case class Argument(framework: Option[TestFramework], args: List[String]) extends TestOption
sealed trait SubProcessPolicy
object InProcess extends SubProcessPolicy
case object InProcess extends SubProcessPolicy
final case class Fork(extraJvm: Seq[String]) extends SubProcessPolicy
final case class Execution(options: Seq[TestOption], parallel: Boolean, subproc: SubProcessPolicy, tags: Seq[(Tag, Int)])

View File

@ -90,24 +90,24 @@ public class ForkMain {
}
return false;
}
void write(ObjectOutputStream os, Object obj) {
try {
os.writeObject(obj);
} catch (IOException e) {
System.err.println("Cannot write to socket");
}
}
void run(ObjectInputStream is, final ObjectOutputStream os) throws Exception {
final boolean ansiCodesSupported = is.readBoolean();
Logger[] loggers = {
new Logger() {
public boolean ansiCodesSupported() { return ansiCodesSupported; }
void write(Object obj) {
try {
os.writeObject(obj);
} catch (IOException e) {
System.err.println("Cannot write to socket");
}
}
public void error(String s) { write(new Object[]{Tags.Error, s}); }
public void warn(String s) { write(new Object[]{Tags.Warn, s}); }
public void info(String s) { write(new Object[]{Tags.Info, s}); }
public void debug(String s) { write(new Object[]{Tags.Debug, s}); }
public void trace(Throwable t) { write(t); }
}
new Logger() {
public boolean ansiCodesSupported() { return ansiCodesSupported; }
public void error(String s) { write(os, new Object[]{Tags.Error, s}); }
public void warn(String s) { write(os, new Object[]{Tags.Warn, s}); }
public void info(String s) { write(os, new Object[]{Tags.Info, s}); }
public void debug(String s) { write(os, new Object[]{Tags.Debug, s}); }
public void trace(Throwable t) { write(os, t); }
}
};
final ForkTestDefinition[] tests = (ForkTestDefinition[]) is.readObject();
@ -118,7 +118,7 @@ public class ForkMain {
try {
framework = (Framework) Class.forName(implClassName).newInstance();
} catch (ClassNotFoundException e) {
System.err.println("Framework implementation '" + implClassName + "' not present.");
write(os, new Object[]{Tags.Error, "Framework implementation '" + implClassName + "' not present."});
continue;
}
@ -139,12 +139,12 @@ public class ForkMain {
} else if (test.fingerprint instanceof TestFingerprint) {
runner.run(test.name, (TestFingerprint) test.fingerprint, handler, frameworkArgs);
} else {
System.err.println("Framework '" + framework + "' does not support test '" + test.name + "'");
write(os, new Object[]{Tags.Error, "Framework '" + framework + "' does not support test '" + test.name + "'"});
}
os.writeObject(events.toArray(new ForkEvent[events.size()]));
write(os, events.toArray(new ForkEvent[events.size()]));
}
}
os.writeObject(Tags.Done);
write(os, Tags.Done);
is.readObject();
}
}