gtr: Handle coverage events

This commit is contained in:
Joël Stemmer
2019-10-06 18:53:25 +01:00
parent ff9ad32c55
commit 824b607642
5 changed files with 39 additions and 11 deletions

View File

@ -9,6 +9,7 @@ import (
"os"
"regexp"
"runtime"
"strconv"
"strings"
"testing"
"time"
@ -1618,7 +1619,12 @@ func testNewParser(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
}
@ -1636,6 +1642,15 @@ func dropProperty(name string, properties []junit.Property) []junit.Property {
return props
}
func getProperty(name string, properties []junit.Property) (int, junit.Property) {
for i, prop := range properties {
if prop.Name == name {
return i, prop
}
}
return -1, junit.Property{}
}
func toXML(testsuites junit.Testsuites) (string, error) {
var buf bytes.Buffer