Add "go-version" flag

Makes it so that the value of the "go.version" property in
the output XML can be customized by the caller using the
"go-version" flag. If the flag is unspecified, falls back to
the previous behavior of using runtime.Version() as the value.

Fixes #48
This commit is contained in:
Nick Miyake
2017-03-26 14:20:21 -07:00
parent 6aeed679b6
commit 22792ea55c
3 changed files with 26 additions and 7 deletions

View File

@ -59,7 +59,7 @@ type JUnitFailure struct {
// JUnitReportXML writes a JUnit xml representation of the given report to w
// in the format described at http://windyroad.org/dl/Open%20Source/JUnit.xsd
func JUnitReportXML(report *parser.Report, noXMLHeader bool, w io.Writer) error {
func JUnitReportXML(report *parser.Report, noXMLHeader bool, goVersion string, w io.Writer) error {
suites := JUnitTestSuites{}
// convert Report to JUnit test suites
@ -79,7 +79,11 @@ func JUnitReportXML(report *parser.Report, noXMLHeader bool, w io.Writer) error
}
// properties
ts.Properties = append(ts.Properties, JUnitProperty{"go.version", runtime.Version()})
if goVersion == "" {
// if goVersion was not specified as a flag, fall back to version reported by runtime
goVersion = runtime.Version()
}
ts.Properties = append(ts.Properties, JUnitProperty{"go.version", goVersion})
if pkg.CoveragePct != "" {
ts.Properties = append(ts.Properties, JUnitProperty{"coverage.statements.pct", pkg.CoveragePct})
}