Skip to content

Commit

Permalink
Merge pull request #342 from brycekahle/bryce.kahle/fix-subtest-regex
Browse files Browse the repository at this point in the history
handle multiple levels in subtest regex generation
  • Loading branch information
dnephin committed Jul 15, 2023
2 parents 049fc26 + 3d41fd7 commit 40adf53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/rerunfails.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"regexp"
"sort"
"strings"

"gotest.tools/gotestsum/testjson"
)
Expand Down Expand Up @@ -137,8 +138,18 @@ func (r *failureRecorder) count() int {

func goTestRunFlagForTestCase(test testjson.TestName) string {
if test.IsSubTest() {
root, sub := test.Split()
return "-test.run=^" + regexp.QuoteMeta(root) + "$/^" + regexp.QuoteMeta(sub) + "$"
parts := strings.Split(string(test), "/")
var sb strings.Builder
sb.WriteString("-test.run=")
for i, p := range parts {
if i > 0 {
sb.WriteByte('/')
}
sb.WriteByte('^')
sb.WriteString(regexp.QuoteMeta(p))
sb.WriteByte('$')
}
return sb.String()
}
return "-test.run=^" + regexp.QuoteMeta(test.Name()) + "$"
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/rerunfails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func TestGoTestRunFlagFromTestCases(t *testing.T) {
input: "TestOne/Subtest(A)[100]",
expected: `-test.run=^TestOne$/^Subtest\(A\)\[100\]$`,
},
"nested sub test case": {
input: "TestOne/Nested/SubtestA",
expected: `-test.run=^TestOne$/^Nested$/^SubtestA$`,
},
}

for name := range testCases {
Expand Down

0 comments on commit 40adf53

Please sign in to comment.