Skip to content

Commit

Permalink
Quote test names before they are used within the regex to rerun
Browse files Browse the repository at this point in the history
  • Loading branch information
noBlubb authored and dnephin committed Jun 16, 2023
1 parent 6d53517 commit 6f6b09d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/rerunfails.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"regexp"
"sort"

"gotest.tools/gotestsum/testjson"
Expand Down Expand Up @@ -137,9 +138,9 @@ func (r *failureRecorder) count() int {
func goTestRunFlagForTestCase(test testjson.TestName) string {
if test.IsSubTest() {
root, sub := test.Split()
return "-test.run=^" + root + "$/^" + sub + "$"
return "-test.run=^" + regexp.QuoteMeta(root) + "$/^" + regexp.QuoteMeta(sub) + "$"
}
return "-test.run=^" + test.Name() + "$"
return "-test.run=^" + regexp.QuoteMeta(test.Name()) + "$"
}

func writeRerunFailsReport(opts *options, exec *testjson.Execution) error {
Expand Down
4 changes: 4 additions & 0 deletions cmd/rerunfails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func TestGoTestRunFlagFromTestCases(t *testing.T) {
input: "TestOne/SubtestA",
expected: "-test.run=^TestOne$/^SubtestA$",
},
"sub test case with special characters": {
input: "TestOne/Subtest(A)[100]",
expected: `-test.run=^TestOne$/^Subtest\(A\)\[100\]$`,
},
}

for name := range testCases {
Expand Down

0 comments on commit 6f6b09d

Please sign in to comment.