Skip to content

Commit 2ae9631

Browse files
enable passing a glob for jUnit XML
1 parent 86da608 commit 2ae9631

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

junit.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"io"
66
"os"
77
"path"
8+
9+
"github.com/bmatcuk/doublestar"
810
)
911

1012
type junitXML struct {
@@ -26,23 +28,31 @@ func loadJUnitXML(reader io.Reader) *junitXML {
2628
return &junitXML
2729
}
2830

31+
func addFileTimesFromIOReader(fileTimes map[string]float64, reader io.Reader) {
32+
junitXML := loadJUnitXML(reader)
33+
for _, testCase := range junitXML.TestCases {
34+
filePath := path.Clean(testCase.File)
35+
fileTimes[filePath] += testCase.Time
36+
}
37+
}
38+
2939
func getFileTimesFromJUnitXML(fileTimes map[string]float64) {
30-
var source io.Reader
3140
if junitXMLPath != "" {
32-
file, err := os.Open(junitXMLPath)
41+
filenames, err := doublestar.Glob(junitXMLPath)
3342
if err != nil {
34-
fatalMsg("failed to open junit xml: %v\n", err)
43+
fatalMsg("failed to match jUnit filename pattern: %v", err)
44+
}
45+
for _, junitFilename := range filenames {
46+
file, err := os.Open(junitFilename)
47+
if err != nil {
48+
fatalMsg("failed to open junit xml: %v\n", err)
49+
}
50+
printMsg("using test times from JUnit report %s\n", junitXMLPath)
51+
addFileTimesFromIOReader(fileTimes, file)
52+
file.Close()
3553
}
36-
defer file.Close()
37-
printMsg("using test times from JUnit report %s\n", junitXMLPath)
38-
source = file
3954
} else {
4055
printMsg("using test times from JUnit report at stdin\n")
41-
source = os.Stdin
42-
}
43-
junitXML := loadJUnitXML(source)
44-
for _, testCase := range junitXML.TestCases {
45-
filePath := path.Clean(testCase.File)
46-
fileTimes[filePath] += testCase.Time
56+
addFileTimesFromIOReader(fileTimes, os.Stdin)
4757
}
4858
}

split_tests.go renamed to main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func parseFlags() {
7575
flag.StringVar(&circleCIBranchName, "circleci-branch", "", "Current branch for CircleCI (or set CIRCLE_BRANCH) - required to use CircleCI")
7676

7777
flag.BoolVar(&useJUnitXML, "junit", false, "Use a JUnit XML report for test times")
78-
flag.StringVar(&junitXMLPath, "junit-path", "", "Path to a JUnit XML report (leave empty to read from stdin)")
78+
flag.StringVar(&junitXMLPath, "junit-path", "", "Path to a JUnit XML report (leave empty to read from stdin; use glob pattern to load multiple files)")
7979

8080
flag.BoolVar(&useLineCount, "line-count", false, "Use line count to estimate test times")
8181

0 commit comments

Comments
 (0)