From 2d52d37f97d4eb1c6f70a9baeae03f1c65c24003 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 3 Nov 2023 19:57:53 -0400 Subject: [PATCH] Fix append bug in --rerun-fails with -run flag --- cmd/main.go | 2 +- cmd/main_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index 977d2748..cd8b2ff7 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -335,7 +335,7 @@ func goTestCmdArgs(opts *options, rerunOpts rerunOpts) []string { return result } - args := opts.args + args := append([]string{}, opts.args...) result := []string{"go", "test"} if len(args) == 0 { diff --git a/cmd/main_test.go b/cmd/main_test.go index fffe2f96..a177683e 100644 --- a/cmd/main_test.go +++ b/cmd/main_test.go @@ -306,6 +306,22 @@ func TestGoTestCmdArgs(t *testing.T) { }, expected: []string{"go", "test", "-json", "-run=TestOne|TestTwo", "-count", "1", "-run", "./fails"}, }) + t.Run("rerun with -run flag", func(t *testing.T) { + tc := testCase{ + opts: &options{ + args: []string{"-run", "TestExample", "-tags", "some", "-json"}, + packages: []string{"./pkg"}, + }, + rerunOpts: rerunOpts{ + runFlag: "-run=TestOne|TestTwo", + pkg: "./fails", + }, + expected: []string{"go", "test", "-run=TestOne|TestTwo", "-tags", "some", "-json", "./fails"}, + } + run(t, "first", tc) + run(t, "second", tc) + }) + } func runCase(t *testing.T, name string, fn func(t *testing.T)) {