Add the ability to paginate scripted tests.

* Modify scripted task parser to allow "pagination" of globs
  e.g.  "*1of3" will create three pages and run page 1.
* Modify travis definition to fragment long-running test groups
  into pages so we stay under the 50 minute limit.
This commit is contained in:
Josh Suereth 2014-05-07 11:06:26 -04:00
parent 8e70aa4e93
commit 5d5d7a6c05
2 changed files with 50 additions and 15 deletions

View File

@ -1,18 +1,23 @@
language: scala
script:
- sbt "scripted $SCRIPTED_TEST"
- sbt "$SCRIPTED_TEST"
env:
- SCRIPTED_TEST=actions/*
- SCRIPTED_TEST=api/*
- SCRIPTED_TEST=compiler-project/*
- SCRIPTED_TEST=dependency-management/*
- SCRIPTED_TEST=java/*
- SCRIPTED_TEST=package/*
- SCRIPTED_TEST=project/*
- SCRIPTED_TEST=reporter/*
- SCRIPTED_TEST=run/*
- SCRIPTED_TEST=source-dependencies/*
- SCRIPTED_TEST=tests/*
- SCRIPTED_TEST=scripted actions/*
- SCRIPTED_TEST=scripted api/*
- SCRIPTED_TEST=scripted compiler-project/*
- SCRIPTED_TEST=scripted dependency-management/*1of2
- SCRIPTED_TEST=scripted dependency-management/*2of2
- SCRIPTED_TEST=scripted java/*
- SCRIPTED_TEST=scripted package/*
- SCRIPTED_TEST=scripted project/*
- SCRIPTED_TEST=scripted reporter/*
- SCRIPTED_TEST=scripted run/*
- SCRIPTED_TEST=scripted source-dependencies/*1of3
- SCRIPTED_TEST=scripted source-dependencies/*2of3
- SCRIPTED_TEST=scripted source-dependencies/*3of3
- SCRIPTED_TEST=scripted tests/*
- SCRIPTED_TEST=launcher/test
# TODO - we'd like to actually test everything, but the process library has a deadlock right now
jdk:
- openjdk6
notifications:

View File

@ -152,6 +152,7 @@ object Sbt extends Build {
)
private def doScripted(launcher: File, scriptedSbtClasspath: Seq[Attributed[File]], scriptedSbtInstance: ScalaInstance, sourcePath: File, args: Seq[String]) {
System.err.println(s"About to run tests: ${args.mkString("\n * ", "\n * ", "\n")}")
val noJLine = new classpath.FilteredLoader(scriptedSbtInstance.loader, "jline." :: Nil)
val loader = classpath.ClasspathUtilities.toLoader(scriptedSbtClasspath.files, noJLine)
val m = ModuleUtilities.getObject("sbt.test.ScriptedTests", loader)
@ -174,6 +175,8 @@ object Sbt extends Build {
import sbt.complete._
import DefaultParsers._
// Paging, 1-index based.
case class ScriptedTestPage(page: Int, total: Int)
def scriptedParser(scriptedBase: File): Parser[Seq[String]] =
{
val pairs = (scriptedBase * AllPassFilter * AllPassFilter * "test").get map { (f: File) =>
@ -184,9 +187,36 @@ object Sbt extends Build {
val id = charClass(c => !c.isWhitespace && c != '/').+.string
val groupP = token(id.examples(pairMap.keySet.toSet)) <~ token('/')
def nameP(group: String) = token("*".id | id.examples(pairMap(group)))
val testID = for (group <- groupP; name <- nameP(group)) yield (group, name)
(token(Space) ~> matched(testID)).*
// A parser for page definitions
val pageP: Parser[ScriptedTestPage] = ("*" ~ NatBasic ~ "of" ~ NatBasic) map {
case _ ~ page ~ _ ~ total => ScriptedTestPage(page, total)
}
// Grabs the filenames from a given test group in the current page definition.
def pagedFilenames(group: String, page: ScriptedTestPage): Seq[String] = {
val files = pairMap(group).toSeq.sortBy(_.toLowerCase)
val pageSize = files.size / page.total
// The last page may loose some values, so we explicitly keep them
val dropped = files.drop(pageSize * (page.page - 1))
if(page.page == page.total) dropped
else dropped.take(pageSize)
}
def nameP(group: String) = {
token("*".id | id.examples(pairMap(group)))
}
val PagedIds: Parser[Seq[String]] =
for {
group <- groupP
page <- pageP
files = pagedFilenames(group, page)
// TODO - Fail the parser if we don't have enough files for the given page size
//if !files.isEmpty
} yield files map (f => group + '/' + f)
val testID = (for (group <- groupP; name <- nameP(group)) yield (group, name))
val testIdAsGroup = matched(testID) map (test => Seq(test))
//(token(Space) ~> matched(testID)).*
(token(Space) ~> (PagedIds | testIdAsGroup)).* map (_.flatten)
}
lazy val scripted = InputKey[Unit]("scripted")