From 94e6bb406e63e299b716d61d4aba03b9389fcf84 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Tue, 16 Jul 2013 13:55:10 -0400 Subject: [PATCH] fix tests/fork. It relied on being able to run a test multiple times in the same forked group. --- .../tests/fork/project/ForkTestsTest.scala | 25 ++++++++----------- .../tests/fork/src/test/scala/Ensemble.scala | 21 +++++++--------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/sbt/src/sbt-test/tests/fork/project/ForkTestsTest.scala b/sbt/src/sbt-test/tests/fork/project/ForkTestsTest.scala index 961962f8e..f8ae9ec08 100755 --- a/sbt/src/sbt-test/tests/fork/project/ForkTestsTest.scala +++ b/sbt/src/sbt-test/tests/fork/project/ForkTestsTest.scala @@ -4,8 +4,8 @@ import Tests._ import Defaults._ object ForkTestsTest extends Build { - val totalFiles = 9 val groupSize = 3 + val groups = 3 val check = TaskKey[Unit]("check", "Check all files were created and remove them.") @@ -15,21 +15,18 @@ object ForkTestsTest extends Build { lazy val root = Project("root", file("."), settings = defaultSettings ++ Seq( scalaVersion := "2.9.2", testGrouping in Test <<= definedTests in Test map { tests => - assert(tests.size == 1) - val groups = Stream continually tests(0) take totalFiles grouped groupSize - for ((ts, idx) <- groups.toSeq.zipWithIndex) yield { - new Group(groupId(idx), ts, SubProcess(Seq("-Dgroup.prefix=" + groupPrefix(idx), "-Dgroup.size=" + ts.size))) - } + assert(tests.size == 3) + for (idx <- 0 until groups) yield + new Group(groupId(idx), tests, SubProcess(Seq("-Dgroup.prefix=" + groupPrefix(idx)))) }, check := { - for (i <- 0 until totalFiles/groupSize) - for (j <- 1 to groupSize) { - val f = file(groupPrefix(i) + j) - if (!f.exists) - error("File " + f.getName + " was not created.") - else - f.delete() - } + val files = + for(i <- 0 until groups; j <- 1 to groupSize) yield + file(groupPrefix(i) + j) + val (exist, absent) = files.partition(_.exists) + exist.foreach(_.delete()) + if(absent.nonEmpty) + error("Files were not created:\n\t" + absent.mkString("\n\t")) }, concurrentRestrictions := Tags.limit(Tags.ForkedTestGroup, 2) :: Nil, libraryDependencies += "org.scalatest" %% "scalatest" % "1.8" % "test" diff --git a/sbt/src/sbt-test/tests/fork/src/test/scala/Ensemble.scala b/sbt/src/sbt-test/tests/fork/src/test/scala/Ensemble.scala index fc009691f..6d1d152d7 100755 --- a/sbt/src/sbt-test/tests/fork/src/test/scala/Ensemble.scala +++ b/sbt/src/sbt-test/tests/fork/src/test/scala/Ensemble.scala @@ -2,19 +2,16 @@ import org.scalatest.FlatSpec import org.scalatest.matchers.MustMatchers import java.io.File -class Ensemble extends FlatSpec with MustMatchers { - val prefix = System.getProperty("group.prefix") - val countTo = System.getProperty("group.size").toInt +trait Ensemble extends FlatSpec with MustMatchers { + def i: Int + def prefix = System.getProperty("group.prefix") "an ensemble" must "create all files" in { - @annotation.tailrec - def step(i: Int): Unit = { - val f = new File(prefix + i) - if (!f.createNewFile) - step(if (f.exists) i + 1 else i) - else - i must be <= (countTo) - } - step(1) + val f = new File(prefix + i) + f.createNewFile } } + +class Ensemble1 extends Ensemble { def i = 1 } +class Ensemble2 extends Ensemble { def i = 2 } +class Ensemble3 extends Ensemble { def i = 3 } \ No newline at end of file