mirror of https://github.com/sbt/sbt.git
parent
089b4e284c
commit
b4e64d37db
|
|
@ -33,18 +33,24 @@ private[sbt] object ForkTests {
|
||||||
}.toMap
|
}.toMap
|
||||||
|
|
||||||
std.TaskExtra.task {
|
std.TaskExtra.task {
|
||||||
val server = new ServerSocket(0)
|
if (!tests.isEmpty) {
|
||||||
object Acceptor extends Runnable {
|
val server = new ServerSocket(0)
|
||||||
val results = collection.mutable.Map.empty[String, TestResult.Value]
|
object Acceptor extends Runnable {
|
||||||
def output = (overall(results.values), results.toMap)
|
val resultsAcc = collection.mutable.Map.empty[String, TestResult.Value]
|
||||||
def run = {
|
lazy val result = (overall(resultsAcc.values), resultsAcc.toMap)
|
||||||
val socket = server.accept()
|
def run: Unit = {
|
||||||
|
val socket =
|
||||||
|
try {
|
||||||
|
server.accept()
|
||||||
|
} catch {
|
||||||
|
case _: java.net.SocketException => return
|
||||||
|
}
|
||||||
val os = new ObjectOutputStream(socket.getOutputStream)
|
val os = new ObjectOutputStream(socket.getOutputStream)
|
||||||
val is = new ObjectInputStream(socket.getInputStream)
|
val is = new ObjectInputStream(socket.getInputStream)
|
||||||
|
|
||||||
import ForkTags._
|
import ForkTags._
|
||||||
@annotation.tailrec def react: Unit = is.readObject match {
|
@annotation.tailrec def react: Unit = is.readObject match {
|
||||||
case `Done` => os.writeObject(Done);
|
case `Done` => os.writeObject(Done); os.flush()
|
||||||
case Array(`Error`, s: String) => log.error(s); react
|
case Array(`Error`, s: String) => log.error(s); react
|
||||||
case Array(`Warn`, s: String) => log.warn(s); react
|
case Array(`Warn`, s: String) => log.warn(s); react
|
||||||
case Array(`Info`, s: String) => log.info(s); react
|
case Array(`Info`, s: String) => log.info(s); react
|
||||||
|
|
@ -55,7 +61,7 @@ private[sbt] object ForkTests {
|
||||||
val event = TestEvent(tEvents)
|
val event = TestEvent(tEvents)
|
||||||
listeners.foreach(_ testEvent event)
|
listeners.foreach(_ testEvent event)
|
||||||
val result = event.result getOrElse TestResult.Passed
|
val result = event.result getOrElse TestResult.Passed
|
||||||
results += group -> result
|
resultsAcc += group -> result
|
||||||
listeners.foreach(_ endGroup (group, result))
|
listeners.foreach(_ endGroup (group, result))
|
||||||
react
|
react
|
||||||
}
|
}
|
||||||
|
|
@ -73,28 +79,34 @@ private[sbt] object ForkTests {
|
||||||
os.writeObject(clazz)
|
os.writeObject(clazz)
|
||||||
os.writeObject(args.toArray)
|
os.writeObject(args.toArray)
|
||||||
}
|
}
|
||||||
|
os.flush()
|
||||||
|
|
||||||
react
|
react
|
||||||
} finally {
|
} finally {
|
||||||
is.close(); os.close(); socket.close()
|
is.close(); os.close(); socket.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
testListeners.foreach(_.doInit())
|
testListeners.foreach(_.doInit())
|
||||||
new Thread(Acceptor).start()
|
new Thread(Acceptor).start()
|
||||||
|
|
||||||
val fullCp = classpath ++: Seq(IO.classLocationFile[ForkMain], IO.classLocationFile[Framework])
|
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 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, StdoutOutput)
|
||||||
if (ec != 0) log.error("Running java with options " + options.mkString(" ") + " failed with exit code " + ec)
|
val result =
|
||||||
} finally {
|
if (ec != 0)
|
||||||
server.close()
|
(TestResult.Error, Map("Running java with options " + options.mkString(" ") + " failed with exit code " + ec -> TestResult.Error))
|
||||||
}
|
else
|
||||||
val result = Acceptor.output
|
Acceptor.result
|
||||||
testListeners.foreach(_.doComplete(result._1))
|
testListeners.foreach(_.doComplete(result._1))
|
||||||
result
|
result
|
||||||
|
} finally {
|
||||||
|
server.close()
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
(TestResult.Passed, Map.empty[String, TestResult.Value])
|
||||||
} tagw (config.tags: _*)
|
} tagw (config.tags: _*)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fork := true
|
||||||
|
|
||||||
|
libraryDependencies += "org.scalatest" % "scalatest_2.9.2" % "1.8" % "test"
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
import org.scalatest.FlatSpec
|
||||||
|
import org.scalatest.matchers.MustMatchers
|
||||||
|
|
||||||
|
class Test extends FlatSpec with MustMatchers {
|
||||||
|
"A simple equation" must "hold" in {
|
||||||
|
Int.MaxValue must equal (Int.MaxValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
> test
|
||||||
|
|
||||||
|
$ copy-file changes/Test.scala src/test/scala/Test.scala
|
||||||
|
|
||||||
|
> test
|
||||||
|
|
||||||
|
> 'set javaOptions += "-Xno-opt"'
|
||||||
|
-> test
|
||||||
|
|
@ -89,6 +89,7 @@ public class ForkMain {
|
||||||
void write(ObjectOutputStream os, Object obj) {
|
void write(ObjectOutputStream os, Object obj) {
|
||||||
try {
|
try {
|
||||||
os.writeObject(obj);
|
os.writeObject(obj);
|
||||||
|
os.flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Cannot write to socket");
|
System.err.println("Cannot write to socket");
|
||||||
}
|
}
|
||||||
|
|
@ -109,8 +110,10 @@ public class ForkMain {
|
||||||
final ForkTestDefinition[] tests = (ForkTestDefinition[]) is.readObject();
|
final ForkTestDefinition[] tests = (ForkTestDefinition[]) is.readObject();
|
||||||
int nFrameworks = is.readInt();
|
int nFrameworks = is.readInt();
|
||||||
for (int i = 0; i < nFrameworks; i++) {
|
for (int i = 0; i < nFrameworks; i++) {
|
||||||
final Framework framework;
|
|
||||||
final String implClassName = (String) is.readObject();
|
final String implClassName = (String) is.readObject();
|
||||||
|
final String[] frameworkArgs = (String[]) is.readObject();
|
||||||
|
|
||||||
|
final Framework framework;
|
||||||
try {
|
try {
|
||||||
framework = (Framework) Class.forName(implClassName).newInstance();
|
framework = (Framework) Class.forName(implClassName).newInstance();
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
|
@ -118,8 +121,6 @@ public class ForkMain {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] frameworkArgs = (String[]) is.readObject();
|
|
||||||
|
|
||||||
ArrayList<ForkTestDefinition> filteredTests = new ArrayList<ForkTestDefinition>();
|
ArrayList<ForkTestDefinition> filteredTests = new ArrayList<ForkTestDefinition>();
|
||||||
for (Fingerprint testFingerprint : framework.tests()) {
|
for (Fingerprint testFingerprint : framework.tests()) {
|
||||||
for (ForkTestDefinition test : tests) {
|
for (ForkTestDefinition test : tests) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue