mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-07-03 20:52:47 -05:00
Omit empty <properties> tag when there are no properties.
Go doesn't omit empty parent tags for empty values[1], so we'll work around this for now by creating a pointer to the property slice. [1]: https://github.com/golang/go/issues/7233.
This commit is contained in:
@ -223,21 +223,26 @@ func testReport(input, reportFile, packageName string, t *testing.T) {
|
||||
func modifyForBackwardsCompat(testsuites junit.Testsuites) junit.Testsuites {
|
||||
testsuites.XMLName.Local = ""
|
||||
for i, suite := range testsuites.Suites {
|
||||
if covIdx, covProp := getProperty("coverage.statements.pct", suite.Properties); covIdx > -1 {
|
||||
pct, _ := strconv.ParseFloat(covProp.Value, 64)
|
||||
testsuites.Suites[i].Properties[covIdx].Value = fmt.Sprintf("%.2f", pct)
|
||||
}
|
||||
testsuites.Suites[i].Properties = dropProperty("go.version", suite.Properties)
|
||||
|
||||
for j := range suite.Testcases {
|
||||
testsuites.Suites[i].Testcases[j].Classname = suite.Name
|
||||
}
|
||||
|
||||
if suite.Properties != nil {
|
||||
if covIdx, covProp := getProperty("coverage.statements.pct", *suite.Properties); covIdx > -1 {
|
||||
pct, _ := strconv.ParseFloat(covProp.Value, 64)
|
||||
(*testsuites.Suites[i].Properties)[covIdx].Value = fmt.Sprintf("%.2f", pct)
|
||||
}
|
||||
testsuites.Suites[i].Properties = dropProperty("go.version", suite.Properties)
|
||||
}
|
||||
}
|
||||
return testsuites
|
||||
}
|
||||
|
||||
func dropNewProperties(testsuites junit.Testsuites) junit.Testsuites {
|
||||
for i, suite := range testsuites.Suites {
|
||||
if suite.Properties == nil {
|
||||
continue
|
||||
}
|
||||
ps := suite.Properties
|
||||
ps = dropProperty("goos", ps)
|
||||
ps = dropProperty("goarch", ps)
|
||||
@ -247,14 +252,20 @@ func dropNewProperties(testsuites junit.Testsuites) junit.Testsuites {
|
||||
return testsuites
|
||||
}
|
||||
|
||||
func dropProperty(name string, properties []junit.Property) []junit.Property {
|
||||
func dropProperty(name string, properties *[]junit.Property) *[]junit.Property {
|
||||
if properties == nil {
|
||||
return nil
|
||||
}
|
||||
var props []junit.Property
|
||||
for _, prop := range properties {
|
||||
for _, prop := range *properties {
|
||||
if prop.Name != name {
|
||||
props = append(props, prop)
|
||||
}
|
||||
}
|
||||
return props
|
||||
if len(props) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &props
|
||||
}
|
||||
|
||||
func getProperty(name string, properties []junit.Property) (int, junit.Property) {
|
||||
|
Reference in New Issue
Block a user