Remove milliseconds from format in order to comply with JUnit spec

This commit is contained in:
Tim Harper 2018-05-14 17:29:20 -06:00
parent add6bde396
commit 13085138a5
1 changed files with 12 additions and 2 deletions

View File

@ -10,6 +10,8 @@ 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
@ -84,7 +86,7 @@ class JUnitXmlTestsListener(val outputDir: String) extends TestsListener {
)
val result =
<testsuite hostname={ hostname } name={ name } tests={ tests + "" } errors={ errors + "" } failures={ failures + "" } skipped={ ignoredSkippedPending + "" } time={ (duration / 1000.0).toString } timestamp={timestamp.toString}>
<testsuite hostname={ hostname } name={ name } tests={ tests + "" } errors={ errors + "" } failures={ failures + "" } skipped={ ignoredSkippedPending + "" } time={ (duration / 1000.0).toString } timestamp={formatISO8601DateTime(timestamp)}>
{ properties }
{
for (e <- events) yield <testcase classname={ name } name={
@ -155,7 +157,9 @@ class JUnitXmlTestsListener(val outputDir: String) extends TestsListener {
/**
* called for each class or equivalent grouping
* We map one group to one Testsuite, so for each Group
* we create an XML like this:
* we create an XML which implements the [[https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd JUnit xml
* spec]], and looks like this:
*
* <?xml version="1.0" encoding="UTF-8" ?>
* <testsuite skipped="w" errors="x" failures="y" tests="z" hostname="example.com" name="eu.henkelmann.bla.SomeTest" time="0.23">
* <properties>
@ -201,6 +205,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