diff --git a/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala b/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala index 2f92523e8..9344305f5 100644 --- a/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala +++ b/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala @@ -9,6 +9,9 @@ package sbt import java.io.{ File, IOException, PrintWriter, StringWriter } import java.net.InetAddress +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter +import java.time.temporal.ChronoUnit import java.util.Hashtable import scala.collection.mutable.ListBuffer @@ -59,7 +62,9 @@ class JUnitXmlTestsListener(val outputDir: String) extends TestsListener { * Gathers data for one Test Suite. We map test groups to TestSuites. * Each TestSuite gets its own output file. */ - class TestSuite(val name: String) { + class TestSuite(val name: String, timestamp: LocalDateTime) { + def this(name: String) = this(name, LocalDateTime.now()) + val events: ListBuffer[TEvent] = new ListBuffer() /**Adds one test result to this suite.*/ @@ -83,7 +88,7 @@ class JUnitXmlTestsListener(val outputDir: String) extends TestsListener { ) val result = - + { properties } { for (e <- events) yield - * + * * * * ... @@ -197,6 +203,12 @@ class JUnitXmlTestsListener(val outputDir: String) extends TestsListener { // contort the user into not using spaces. private[this] def normalizeName(s: String) = s.replaceAll("""\s+""", "-") + /** + * Format the date, without milliseconds or the timezone, per the JUnit spec. + */ + private[this] def formatISO8601DateTime(d: LocalDateTime): String = + d.truncatedTo(ChronoUnit.SECONDS).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + private def writeSuite() = { val file = new File(targetDir, s"${normalizeName(withTestSuite(_.name))}.xml").getAbsolutePath // TODO would be nice to have a logger and log this with level debug