Skip to content

Commit

Permalink
Merge pull request #338 from noBlubb/fix/quote_testnames_for_regex
Browse files Browse the repository at this point in the history
Quote test names before they are used within the regex to rerun
  • Loading branch information
dnephin committed Jun 16, 2023
2 parents 00a4f25 + 6f6b09d commit 9cca4bb
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 9cca4bb

Please sign in to comment.