Skip to content

Instantly share code, notes, and snippets.

@squito
Created January 14, 2015 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squito/54afab78f41dd11312ad to your computer and use it in GitHub Desktop.
Save squito/54afab78f41dd11312ad to your computer and use it in GitHub Desktop.
parsing the scalatest timing output from sbt
case class TestTime(suite: String, test: String, time: Int)
def parse(input: Iterator[String]): Seq[TestTime] = {
val TimingPattern = """(.*)\(((\d+) seconds?, )?(.*) milliseconds?\)""".r
val x = input.filter{line => line.startsWith("[info]") && !line.contains("!!! IGNORED !!!") && !line.startsWith("[info] +")}.map{_.substring("[info] ".length)}
var suiteName: String = null
var result = IndexedSeq[TestTime]()
while(x.hasNext) {
val line = x.next
if(line.endsWith(":"))
suiteName = line
else if (line.startsWith("- ")) {
val TimingPattern(test, _, seconds, millis) = line
val time = Option(seconds).map{_.toInt * 1000}.getOrElse(0) + millis.toInt
result :+= TestTime(suiteName, test, time)
} else {
throw new RuntimeException(line)
}
}
result
}
val in = scala.io.Source.fromFile("sbt_output.txt")
val times = parse(in.getLines)
val out = new java.io.PrintWriter("test_times_table.tsv")
times.foreach{t => out.println(t.suite + "\t" + t.test + "\t" + t.time)}
out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment