mirror of https://github.com/sbt/sbt.git
Fixes after review, take 3.
This commit is contained in:
parent
4d5effcb28
commit
2741515d44
|
|
@ -297,7 +297,7 @@ object Defaults extends BuildCommon
|
|||
Tests(frameworkMap, loader, tests, config, s.log)
|
||||
}
|
||||
}
|
||||
Tests.flatten(results)
|
||||
Tests.foldTasks(results)
|
||||
},
|
||||
test <<= (executeTests, streams, resolvedScoped, state) map {
|
||||
(results, s, scoped, st) =>
|
||||
|
|
@ -385,7 +385,7 @@ object Defaults extends BuildCommon
|
|||
Tests(frameworks, loader, tests, newConfig, s.log)
|
||||
}
|
||||
}
|
||||
Tests.flatten(results) map (Tests.showResults(s.log, _, noTestsMessage(scoped)))
|
||||
Tests.foldTasks(results) map (Tests.showResults(s.log, _, noTestsMessage(scoped)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ private[sbt] object ForkTests {
|
|||
val opts = config.options.toList
|
||||
val listeners = opts flatMap {
|
||||
case Listeners(ls) => ls
|
||||
case _ => List.empty
|
||||
case _ => Nil
|
||||
}
|
||||
val testListeners = listeners flatMap {
|
||||
case tl: TestsListener => Some(tl)
|
||||
|
|
@ -28,11 +28,11 @@ private[sbt] object ForkTests {
|
|||
f => f.implClassName -> opts.flatMap {
|
||||
case Argument(None, args) => args
|
||||
case Argument(Some(`f`), args) => args
|
||||
case _ => List.empty
|
||||
case _ => Nil
|
||||
}
|
||||
}.toMap
|
||||
|
||||
std.TaskExtra.toTask {
|
||||
std.TaskExtra.task {
|
||||
val server = new ServerSocket(0)
|
||||
object Acceptor extends Runnable {
|
||||
val results = collection.mutable.Map.empty[String, TestResult.Value]
|
||||
|
|
@ -47,17 +47,6 @@ private[sbt] object ForkTests {
|
|||
val os = new ObjectOutputStream(socket.getOutputStream)
|
||||
val is = new ObjectInputStream(socket.getInputStream)
|
||||
|
||||
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);
|
||||
|
|
@ -77,33 +66,44 @@ private[sbt] object ForkTests {
|
|||
}
|
||||
react
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
react
|
||||
} finally {
|
||||
is.close()
|
||||
os.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
() => {
|
||||
try {
|
||||
testListeners.foreach(_.doInit())
|
||||
val t = new Thread(Acceptor)
|
||||
t.start()
|
||||
testListeners.foreach(_.doInit())
|
||||
try {
|
||||
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)
|
||||
if (ec != 0) {
|
||||
log.error("Running java with options " + options.mkString(" ") + " failed with exit code " + ec)
|
||||
server.close()
|
||||
}
|
||||
|
||||
t.join()
|
||||
val result = Acceptor.output
|
||||
testListeners.foreach(_.doComplete(result._1))
|
||||
result
|
||||
} finally {
|
||||
server.close()
|
||||
}
|
||||
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)
|
||||
if (ec != 0) log.error("Running java with options " + options.mkString(" ") + " failed with exit code " + ec)
|
||||
} finally {
|
||||
server.close()
|
||||
}
|
||||
val result = Acceptor.output
|
||||
testListeners.foreach(_.doComplete(result._1))
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,10 +126,12 @@ object Tests
|
|||
|
||||
def processResults(results: Iterable[(String, TestResult.Value)]): (TestResult.Value, Map[String, TestResult.Value]) =
|
||||
(overall(results.map(_._2)), results.toMap)
|
||||
def flatten(results: Seq[Task[Output]]): Task[Output] =
|
||||
reduced(results.toIndexedSeq, {
|
||||
case ((v1, m1), (v2, m2)) => (if (v1.id < v2.id) v2 else v1, m1 ++ m2)
|
||||
})
|
||||
def foldTasks(results: Seq[Task[Output]]): Task[Output] =
|
||||
(task((TestResult.Passed, Map.empty[String, TestResult.Value])) /: results) {
|
||||
reducePair(_, _, {
|
||||
case ((v1, m1), (v2, m2)) => (if (v1.id < v2.id) v2 else v1, m1 ++ m2)
|
||||
})
|
||||
}
|
||||
def overall(results: Iterable[TestResult.Value]): TestResult.Value =
|
||||
(TestResult.Passed /: results) { (acc, result) => if(acc.id < result.id) result else acc }
|
||||
def discover(frameworks: Seq[Framework], analysis: Analysis, log: Logger): (Seq[TestDefinition], Set[String]) =
|
||||
|
|
|
|||
|
|
@ -90,9 +90,10 @@ public class ForkMain {
|
|||
return false;
|
||||
}
|
||||
void run(ObjectInputStream is, final ObjectOutputStream os) throws Exception {
|
||||
final boolean ansiCodesSupported = is.readBoolean();
|
||||
Logger[] loggers = {
|
||||
new Logger() {
|
||||
public boolean ansiCodesSupported() { return false; }
|
||||
public boolean ansiCodesSupported() { return ansiCodesSupported; }
|
||||
void write(Object obj) {
|
||||
try {
|
||||
os.writeObject(obj);
|
||||
|
|
@ -100,7 +101,7 @@ public class ForkMain {
|
|||
System.err.println("Cannot write to socket");
|
||||
}
|
||||
}
|
||||
public void error(String s) { write(new Object[]{Tags.Error, s}); }
|
||||
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}); }
|
||||
|
|
|
|||
Loading…
Reference in New Issue