Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Vigdorchik committed Apr 3, 2012
1 parent cdfc72d commit 291db63
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 68 deletions.
2 changes: 1 addition & 1 deletion main/Keys.scala
Expand Up @@ -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
Expand Down
87 changes: 40 additions & 47 deletions main/actions/ForkTests.scala
Expand Up @@ -38,65 +38,58 @@ 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
}
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)
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)
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()
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())
new Thread(Acceptor).start()

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()
Expand Down
2 changes: 1 addition & 1 deletion main/actions/Tests.scala
Expand Up @@ -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)])
Expand Down
38 changes: 19 additions & 19 deletions testing/agent/src/main/java/sbt/ForkMain.java
Expand Up @@ -90,24 +90,24 @@ boolean matches(Fingerprint f1, Fingerprint f2) {
}
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();
Expand All @@ -118,7 +118,7 @@ void write(Object obj) {
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;
}

Expand All @@ -139,12 +139,12 @@ void write(Object obj) {
} 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();
}
}
Expand Down

0 comments on commit 291db63

Please sign in to comment.