From 3efa4ee19a4b3da000caf09cb386d3bada995b1d Mon Sep 17 00:00:00 2001 From: Raffael Stahl Date: Wed, 14 Jun 2023 13:07:47 +0200 Subject: [PATCH] Quote test names before they are used within the regex to rerun --- cmd/rerunfails.go | 5 +++-- cmd/rerunfails_test.go | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/rerunfails.go b/cmd/rerunfails.go index b3344c67..72fdbcca 100644 --- a/cmd/rerunfails.go +++ b/cmd/rerunfails.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "regexp" "sort" "gotest.tools/gotestsum/testjson" @@ -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 { diff --git a/cmd/rerunfails_test.go b/cmd/rerunfails_test.go index f636094a..154800d7 100644 --- a/cmd/rerunfails_test.go +++ b/cmd/rerunfails_test.go @@ -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 {