Extract and report coverage information.

When `go test` is run on multiple packages and with coverage collection
enabled, it appends coverage information to the final result line for
each package.

With this change, properly handle this additional information and add it
into the JUnit XML report as a property of the test suite.
This commit is contained in:
Jeff Grafton
2015-06-29 17:36:33 -07:00
parent 38eb577ca2
commit 6087bd544c
7 changed files with 147 additions and 12 deletions

View File

@ -260,6 +260,73 @@ var testCases = []TestCase{
},
},
},
{
name: "09-coverage.txt",
reportName: "09-report.xml",
report: &Report{
Packages: []Package{
{
Name: "package/name",
Time: 160,
Tests: []*Test{
{
Name: "TestZ",
Time: 60,
Result: PASS,
Output: []string{},
},
{
Name: "TestA",
Time: 100,
Result: PASS,
Output: []string{},
},
},
CoveragePct: "13.37",
},
},
},
},
{
name: "10-multipkg-coverage.txt",
reportName: "10-report.xml",
report: &Report{
Packages: []Package{
{
Name: "package1/foo",
Time: 400,
Tests: []*Test{
{
Name: "TestA",
Time: 100,
Result: PASS,
Output: []string{},
},
{
Name: "TestB",
Time: 300,
Result: PASS,
Output: []string{},
},
},
CoveragePct: "10.0",
},
{
Name: "package2/bar",
Time: 4200,
Tests: []*Test{
{
Name: "TestC",
Time: 4200,
Result: PASS,
Output: []string{},
},
},
CoveragePct: "99.8",
},
},
},
},
}
func TestParser(t *testing.T) {
@ -321,6 +388,9 @@ func TestParser(t *testing.T) {
t.Errorf("Test.Output ==\n%s\n, want\n%s", testOutput, expTestOutput)
}
}
if pkg.CoveragePct != expPkg.CoveragePct {
t.Errorf("Package.CoveragePct == %s, want %s", pkg.CoveragePct, expPkg.CoveragePct)
}
}
}
}