Created
January 14, 2015 20:50
-
-
Save squito/54afab78f41dd11312ad to your computer and use it in GitHub Desktop.
parsing the scalatest timing output from sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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