Skip to content

Commit

Permalink
cached suites have junit property cached set to true (#586)
Browse files Browse the repository at this point in the history
* cached suites have junit property cached set to true

* oneline
  • Loading branch information
goddenrich authored and peterebden committed Apr 9, 2019
1 parent df5c575 commit ffb3109
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/test/xml_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"path"
"strconv"
"time"

"github.com/thought-machine/please/src/core"
Expand Down Expand Up @@ -83,6 +84,7 @@ func toCoreTestSuite(xmlTestSuite jUnitXMLTestSuite) core.TestSuite {
Name: xmlTestSuite.Name,
Timestamp: xmlTestSuite.Timestamp,
Duration: xmlTestSuite.Duration(),
Cached: toCoreCached(xmlTestSuite.Properties),
Properties: toCoreProperties(xmlTestSuite.Properties),
}
for _, test := range xmlTestSuite.TestCases {
Expand All @@ -96,9 +98,24 @@ func toCoreTestSuite(xmlTestSuite jUnitXMLTestSuite) core.TestSuite {
return testSuite
}

func toCoreCached(properties jUnitXMLProperties) bool {
for _, prop := range properties.Property {
if prop.Name == "cached" {
if p, err := strconv.ParseBool(prop.Value); err == nil {
return p
}
return false
}
}
return false
}

func toCoreProperties(properties jUnitXMLProperties) map[string]string {
props := make(map[string]string)
for _, prop := range properties.Property {
if prop.Name == "cached" {
continue
}
props[prop.Name] = prop.Value
}
return props
Expand Down Expand Up @@ -421,7 +438,7 @@ func WriteResultsToFileOrDie(graph *core.BuildGraph, filename string) {
Failures: testSuite.Failures(),
Skipped: testSuite.Skips(),
timed: timed{testSuite.Duration.Seconds()},
Properties: toXMLProperties(testSuite.Properties),
Properties: toXMLProperties(testSuite.Properties, testSuite.Cached),
}
}
for _, testCase := range testSuite.TestCases {
Expand Down Expand Up @@ -450,14 +467,20 @@ func WriteResultsToFileOrDie(graph *core.BuildGraph, filename string) {
}
}

func toXMLProperties(props map[string]string) jUnitXMLProperties {
func toXMLProperties(props map[string]string, cached bool) jUnitXMLProperties {
out := jUnitXMLProperties{}
for k, v := range props {
out.Property = append(out.Property, jUnitXMLProperty{
Name: k,
Value: v,
})
}
if cached {
out.Property = append(out.Property, jUnitXMLProperty{
Name: "cached",
Value: strconv.FormatBool(cached),
})
}
return out
}

Expand Down

0 comments on commit ffb3109

Please sign in to comment.