mirror of https://github.com/sbt/sbt.git
fix tests/fork. It relied on being able to run a test multiple times in the same forked group.
This commit is contained in:
parent
c0e06a14fe
commit
94e6bb406e
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
Loading…
Reference in New Issue