Permalink
Browse files

Various fork in Test fixes. Closes #512 #515.

  • Loading branch information...
1 parent 089b4e2 commit b4e64d37dbd4e095da8da4ef38a4e532eacb4296 @vigdorchik vigdorchik committed with Aug 15, 2012
@@ -33,18 +33,24 @@ private[sbt] object ForkTests {
}.toMap
std.TaskExtra.task {
- val server = new ServerSocket(0)
- object Acceptor extends Runnable {
- val results = collection.mutable.Map.empty[String, TestResult.Value]
- def output = (overall(results.values), results.toMap)
- def run = {
- val socket = server.accept()
+ if (!tests.isEmpty) {
+ val server = new ServerSocket(0)
+ object Acceptor extends Runnable {
+ val resultsAcc = collection.mutable.Map.empty[String, TestResult.Value]
+ lazy val result = (overall(resultsAcc.values), resultsAcc.toMap)
+ def run: Unit = {
+ val socket =
+ try {
+ server.accept()
+ } catch {
+ case _: java.net.SocketException => return
+ }
val os = new ObjectOutputStream(socket.getOutputStream)
val is = new ObjectInputStream(socket.getInputStream)
import ForkTags._
@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(`Warn`, s: String) => log.warn(s); react
case Array(`Info`, s: String) => log.info(s); react
@@ -55,7 +61,7 @@ private[sbt] object ForkTests {
val event = TestEvent(tEvents)
listeners.foreach(_ testEvent event)
val result = event.result getOrElse TestResult.Passed
- results += group -> result
+ resultsAcc += group -> result
listeners.foreach(_ endGroup (group, result))
react
}
@@ -73,28 +79,34 @@ private[sbt] object ForkTests {
os.writeObject(clazz)
os.writeObject(args.toArray)
}
+ os.flush()
react
} finally {
is.close(); os.close(); socket.close()
}
}
- }
+ }
- try {
- testListeners.foreach(_.doInit())
- new Thread(Acceptor).start()
+ 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)
- 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
+ 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 result =
+ if (ec != 0)
+ (TestResult.Error, Map("Running java with options " + options.mkString(" ") + " failed with exit code " + ec -> TestResult.Error))
+ else
+ Acceptor.result
+ testListeners.foreach(_.doComplete(result._1))
+ result
+ } finally {
+ server.close()
+ }
+ } else
+ (TestResult.Passed, Map.empty[String, TestResult.Value])
} 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 @@ boolean matches(Fingerprint f1, Fingerprint f2) {
void write(ObjectOutputStream os, Object obj) {
try {
os.writeObject(obj);
+ os.flush();
} catch (IOException e) {
System.err.println("Cannot write to socket");
}
@@ -109,17 +110,17 @@ void run(ObjectInputStream is, final ObjectOutputStream os) throws Exception {
final ForkTestDefinition[] tests = (ForkTestDefinition[]) is.readObject();
int nFrameworks = is.readInt();
for (int i = 0; i < nFrameworks; i++) {
- final Framework framework;
final String implClassName = (String) is.readObject();
+ final String[] frameworkArgs = (String[]) is.readObject();
+
+ final Framework framework;
try {
framework = (Framework) Class.forName(implClassName).newInstance();
} catch (ClassNotFoundException e) {
write(os, new Object[]{ForkTags.Error, "Framework implementation '" + implClassName + "' not present."});
continue;
}
- final String[] frameworkArgs = (String[]) is.readObject();
-
ArrayList<ForkTestDefinition> filteredTests = new ArrayList<ForkTestDefinition>();
for (Fingerprint testFingerprint : framework.tests()) {
for (ForkTestDefinition test : tests) {

0 comments on commit b4e64d3

Please sign in to comment.