nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: gotestyourself/gotestsum
Pull request #280 (2022-10-02 19:38:14)

Error if `-failfast` is used with `--rerun-fails`
`-failfast` stops the initial run of tests before all tests are run, so gotestsum never sees the full list of tests. When `gotestsum` goes to re-run tests, it uses the list of failed tests from the initial test run. Since only some of the tests ran, it never has the change to re-run all the tests that were skipped by `-failfast`.

`-failfast` has other problems (golang/go#30522, golang/go#33038).  If we wanted to support this combination of flags it is possible that `gotestsum` could get the list of tests from `go test --list`, however that introduces other problems. `go test --list` can be pretty slow, which adds more time to the overall test run. It also only lists top-level test cases, so there would be no way to re-run only failed subtests. That effectively makes the behaviour introduced in #275 the default and there'd be no way to support the current behaviour of re-running only the subtests that failed. I'd like to avoid that approach, so I think the best option for now is to refuse to run.  https://github.com/gotestyourself/gotestsum/issues/278#issuecomment-1238681323 has a recommendation for re-running all tests along with `-failfast`.


Related to #278


Patch:
diff --git a/cmd/main.go b/cmd/main.go
index 3c3c6c4..981b7ab 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -174,9 +174,13 @@ type options struct {
 func (o options) Validate() error {
 	if o.rerunFailsMaxAttempts > 0 && len(o.args) > 0 && !o.rawCommand && len(o.packages) == 0 {
 		return fmt.Errorf(
-			"when go test args are used with --rerun-fails-max-attempts " +
+			"when go test args are used with --rerun-fails " +
 				"the list of packages to test must be specified by the --packages flag")
 	}
+	if o.rerunFailsMaxAttempts > 0 && boolArgIndex("failfast", o.args) > -1 {
+		return fmt.Errorf("-failfast can not be used with --rerun-fails " +
+			"because not all test cases will run")
+	}
 	return nil
 }
 


Test patch:
diff --git a/cmd/main_test.go b/cmd/main_test.go
index ae06dc3..27dd695 100644
--- a/cmd/main_test.go
+++ b/cmd/main_test.go
@@ -70,6 +70,11 @@ func TestOptions_Validate_FromFlags(t *testing.T) {
 			name: "rerun flag, no go-test args, with packages flag",
 			args: []string{"--rerun-fails", "--packages", "./..."},
 		},
+		{
+			name:     "rerun-fails with failfast",
+			args:     []string{"--rerun-fails", "--packages=./...", "--", "-failfast"},
+			expected: "-failfast can not be used with --rerun-fails",
+		},
 	}
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {
Repository: gotestyourself/gotestsum
Pull request #300 (2023-01-29 11:35:19)

Fix need to save twice to trigger watch on OSX using Neovim
On OSX (12.6.2) using Neovim (NVIM v0.8.2) the triggering event varies between `fsnotify.Rename` and `Create`.
This fix adds `fsnotify.Rename` to the events triggering a new test run.

*Before*
```
handling event "cors_middleware.go": RENAME
handling event "cors_middleware.go": CREATE

Running tests in ./.
exec: [go test -json ./.]
go test pid: 96495
✓  . (cached)

DONE 71 tests in 0.237s
```

*After*
```
handling event "cors_middleware.go": RENAME

Running tests in ./.
exec: [go test -json ./.]
go test pid: 95707
✓  . (cached)

DONE 71 tests in 0.245s
```


Patch:
diff --git a/internal/filewatcher/watch.go b/internal/filewatcher/watch.go
index e639f27..837ec44 100644
--- a/internal/filewatcher/watch.go
+++ b/internal/filewatcher/watch.go
@@ -236,7 +236,7 @@ type fsEventHandler struct {
 var floodThreshold = 250 * time.Millisecond
 
 func (h *fsEventHandler) handleEvent(event fsnotify.Event) error {
-	if event.Op&(fsnotify.Write|fsnotify.Create) == 0 {
+	if event.Op&(fsnotify.Write|fsnotify.Create|fsnotify.Rename) == 0 {
 		return nil
 	}
 


Test patch:
diff --git a/internal/filewatcher/watch_test.go b/internal/filewatcher/watch_test.go
index d0e5af0..fcf2376 100644
--- a/internal/filewatcher/watch_test.go
+++ b/internal/filewatcher/watch_test.go
@@ -38,8 +38,9 @@ func TestFSEventHandler_HandleEvent(t *testing.T) {
 
 	var testCases = []testCase{
 		{
-			name:  "Op is rename",
-			event: fsnotify.Event{Op: fsnotify.Rename, Name: "file_test.go"},
+			name:        "Op is rename",
+			event:       fsnotify.Event{Op: fsnotify.Rename, Name: "file_test.go"},
+			expectedRun: true,
 		},
 		{
 			name:  "Op is remove",
Repository: gotestyourself/gotestsum
Pull request #307 (2023-02-18 21:56:51)

ci-matrix: improve description
Github actions UI only shows the first few characters of the job name. The previous description resulted in the job names being mostly the same.

With this new description the more relevant parts of the name (the index and the primary package) should be more prominent.


Patch:
diff --git a/cmd/tool/matrix/matrix.go b/cmd/tool/matrix/matrix.go
index b5db797..a41752c 100644
--- a/cmd/tool/matrix/matrix.go
+++ b/cmd/tool/matrix/matrix.go
@@ -247,7 +247,7 @@ func writeMatrix(out io.Writer, buckets []bucket) error {
 			if len(bucket.Packages) > 1 {
 				extra = fmt.Sprintf(" and %d others", len(bucket.Packages)-1)
 			}
-			p.Description = fmt.Sprintf("partition %d - package %v%v",
+			p.Description = fmt.Sprintf("%d - %v%v",
 				p.ID, testjson.RelativePackagePath(bucket.Packages[0]), extra)
 		}
 


Test patch:
diff --git a/cmd/tool/matrix/matrix_test.go b/cmd/tool/matrix/matrix_test.go
index b537318..f4a9b3c 100644
--- a/cmd/tool/matrix/matrix_test.go
+++ b/cmd/tool/matrix/matrix_test.go
@@ -226,19 +226,19 @@ func TestRun(t *testing.T) {
 var expectedMatrix = `{
   "include": [
     {
-      "description": "partition 0 - package pkg2",
+      "description": "0 - pkg2",
       "estimatedRuntime": "6s",
       "id": 0,
       "packages": "pkg2"
     },
     {
-      "description": "partition 1 - package pkg1",
+      "description": "1 - pkg1",
       "estimatedRuntime": "4s",
       "id": 1,
       "packages": "pkg1"
     },
     {
-      "description": "partition 2 - package pkg0 and 1 others",
+      "description": "2 - pkg0 and 1 others",
       "estimatedRuntime": "2s",
       "id": 2,
       "packages": "pkg0 other"
Repository: gotestyourself/gotestsum
Pull request #342 (2023-07-14 19:48:38)

handle multiple levels in subtest regex generation
Addresses part of the issue in #341 


Patch:
diff --git a/cmd/rerunfails.go b/cmd/rerunfails.go
index 72fdbcc..61de3ff 100644
--- a/cmd/rerunfails.go
+++ b/cmd/rerunfails.go
@@ -6,6 +6,7 @@ import (
 	"os"
 	"regexp"
 	"sort"
+	"strings"
 
 	"gotest.tools/gotestsum/testjson"
 )
@@ -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()) + "$"
 }


Test patch:
diff --git a/cmd/rerunfails_test.go b/cmd/rerunfails_test.go
index d2904c2..232c80f 100644
--- a/cmd/rerunfails_test.go
+++ b/cmd/rerunfails_test.go
@@ -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 {
Repository: gotestyourself/gotestsum
Pull request #360 (2023-08-20 14:45:23)

Export elapsed time to the post-run environment
For use with `go-test-report` and for completeness


Patch:
diff --git a/README.md b/README.md
index 0373c9e..cca98cf 100644
--- a/README.md
+++ b/README.md
@@ -146,6 +146,7 @@ TESTS_ERRORS            # number of errors
 TESTS_FAILED            # number of failed tests
 TESTS_SKIPPED           # number of skipped tests
 TESTS_TOTAL             # number of tests run
+TESTS_ELAPSED           # test time elapsed, in seconds
 ```
 
 To get more details about the test run, such as failure messages or the full list of failed
diff --git a/cmd/handler.go b/cmd/handler.go
index 8c47205..5771fb5 100644
--- a/cmd/handler.go
+++ b/cmd/handler.go
@@ -166,6 +166,7 @@ func postRunHook(opts *options, execution *testjson.Execution) error {
 		fmt.Sprintf("TESTS_FAILED=%d", len(execution.Failed())),
 		fmt.Sprintf("TESTS_SKIPPED=%d", len(execution.Skipped())),
 		fmt.Sprintf("TESTS_ERRORS=%d", len(execution.Errors())),
+		fmt.Sprintf("TESTS_ELAPSED=%.3f", execution.Elapsed().Seconds()),
 	)
 	return cmd.Run()
 }


Test patch:
diff --git a/cmd/handler_test.go b/cmd/handler_test.go
index 48322de..b0e0f00 100644
--- a/cmd/handler_test.go
+++ b/cmd/handler_test.go
@@ -8,6 +8,7 @@ import (
 	"strings"
 	"testing"
 
+	"gotest.tools/gotestsum/internal/text"
 	"gotest.tools/gotestsum/testjson"
 	"gotest.tools/v3/assert"
 	"gotest.tools/v3/env"
@@ -34,7 +35,15 @@ func TestPostRunHook(t *testing.T) {
 	exec := newExecFromTestData(t)
 	err = postRunHook(opts, exec)
 	assert.NilError(t, err)
-	golden.Assert(t, buf.String(), "post-run-hook-expected")
+
+	actual := text.ProcessLines(t, buf, func(line string) string {
+		if strings.HasPrefix(line, "TESTS_ELAPSED=0.0") {
+			i := strings.Index(line, "=")
+			return line[:i] + "=0.000"
+		}
+		return line
+	})
+	golden.Assert(t, actual, "post-run-hook-expected")
 }
 
 func newExecFromTestData(t *testing.T) *testjson.Execution {
diff --git a/cmd/testdata/post-run-hook-expected b/cmd/testdata/post-run-hook-expected
index 5c1ebcf..55ea6b5 100644
--- a/cmd/testdata/post-run-hook-expected
+++ b/cmd/testdata/post-run-hook-expected
@@ -2,6 +2,7 @@ GOTESTSUM_FORMAT=short
 GOTESTSUM_JSONFILE=events.json
 GOTESTSUM_JSONFILE_TIMING_EVENTS=timing.json
 GOTESTSUM_JUNITFILE=junit.xml
+TESTS_ELAPSED=0.000
 TESTS_ERRORS=0
 TESTS_FAILED=13
 TESTS_SKIPPED=5
Repository: gotestyourself/gotestsum
Pull request #361 (2023-08-21 06:14:36)

Rename TESTS_ELAPSED environment variable
Follow-up on:
* https://github.com/gotestyourself/gotestsum/pull/360

I think looks nicer, and works better in the external programs.

Environment: `GOTESTSUM_JSONFILE` `GOTESTSUM_ELAPSED`
 


Patch:
diff --git a/README.md b/README.md
index cca98cf..8c662c4 100644
--- a/README.md
+++ b/README.md
@@ -139,6 +139,7 @@ test run has completed. The binary will be run with the following environment
 variables set:
 
 ```
+GOTESTSUM_ELAPSED       # test time elapsed, in seconds
 GOTESTSUM_FORMAT        # gotestsum format (ex: short)
 GOTESTSUM_JSONFILE      # path to the jsonfile, empty if no file path was given
 GOTESTSUM_JUNITFILE     # path to the junit.xml file, empty if no file path was given
@@ -146,7 +147,6 @@ TESTS_ERRORS            # number of errors
 TESTS_FAILED            # number of failed tests
 TESTS_SKIPPED           # number of skipped tests
 TESTS_TOTAL             # number of tests run
-TESTS_ELAPSED           # test time elapsed, in seconds
 ```
 
 To get more details about the test run, such as failure messages or the full list of failed
diff --git a/cmd/handler.go b/cmd/handler.go
index 0820ee6..99fd002 100644
--- a/cmd/handler.go
+++ b/cmd/handler.go
@@ -170,11 +170,11 @@ func postRunHook(opts *options, execution *testjson.Execution) error {
 		"GOTESTSUM_JSONFILE="+opts.jsonFile,
 		"GOTESTSUM_JSONFILE_TIMING_EVENTS="+opts.jsonFileTimingEvents,
 		"GOTESTSUM_JUNITFILE="+opts.junitFile,
+		fmt.Sprintf("GOTESTSUM_ELAPSED=%.3f", execution.Elapsed().Seconds()),
 		fmt.Sprintf("TESTS_TOTAL=%d", execution.Total()),
 		fmt.Sprintf("TESTS_FAILED=%d", len(execution.Failed())),
 		fmt.Sprintf("TESTS_SKIPPED=%d", len(execution.Skipped())),
 		fmt.Sprintf("TESTS_ERRORS=%d", len(execution.Errors())),
-		fmt.Sprintf("TESTS_ELAPSED=%.3f", execution.Elapsed().Seconds()),
 	)
 	return cmd.Run()
 }


Test patch:
diff --git a/cmd/handler_test.go b/cmd/handler_test.go
index dabefd2..5d55f9d 100644
--- a/cmd/handler_test.go
+++ b/cmd/handler_test.go
@@ -39,7 +39,7 @@ func TestPostRunHook(t *testing.T) {
 	assert.NilError(t, err)
 
 	actual := text.ProcessLines(t, buf, func(line string) string {
-		if strings.HasPrefix(line, "TESTS_ELAPSED=0.0") {
+		if strings.HasPrefix(line, "GOTESTSUM_ELAPSED=0.0") {
 			i := strings.Index(line, "=")
 			return line[:i] + "=0.000"
 		}
diff --git a/cmd/testdata/post-run-hook-expected b/cmd/testdata/post-run-hook-expected
index 55ea6b5..a2a6b9e 100644
--- a/cmd/testdata/post-run-hook-expected
+++ b/cmd/testdata/post-run-hook-expected
@@ -1,8 +1,8 @@
+GOTESTSUM_ELAPSED=0.000
 GOTESTSUM_FORMAT=short
 GOTESTSUM_JSONFILE=events.json
 GOTESTSUM_JSONFILE_TIMING_EVENTS=timing.json
 GOTESTSUM_JUNITFILE=junit.xml
-TESTS_ELAPSED=0.000
 TESTS_ERRORS=0
 TESTS_FAILED=13
 TESTS_SKIPPED=5
Repository: gotestyourself/gotestsum
Pull request #363 (2023-08-22 09:47:51)

Add the time unit to elapsed time duration
One final change, add the time unit to the value...

Less guessing, less "is it nano ? or micro ? or seconds"

And it also allows calling `time.ParseDuration` directly

Not to mention it now has the same format as printed.

* #361 


Patch:
diff --git a/README.md b/README.md
index 8c662c4..ed86817 100644
--- a/README.md
+++ b/README.md
@@ -139,8 +139,8 @@ test run has completed. The binary will be run with the following environment
 variables set:
 
 ```
-GOTESTSUM_ELAPSED       # test time elapsed, in seconds
-GOTESTSUM_FORMAT        # gotestsum format (ex: short)
+GOTESTSUM_ELAPSED       # test run time in seconds (ex: 2.45s)
+GOTESTSUM_FORMAT        # gotestsum format (ex: pkgname)
 GOTESTSUM_JSONFILE      # path to the jsonfile, empty if no file path was given
 GOTESTSUM_JUNITFILE     # path to the junit.xml file, empty if no file path was given
 TESTS_ERRORS            # number of errors
diff --git a/cmd/handler.go b/cmd/handler.go
index 99fd002..c5159a5 100644
--- a/cmd/handler.go
+++ b/cmd/handler.go
@@ -170,7 +170,7 @@ func postRunHook(opts *options, execution *testjson.Execution) error {
 		"GOTESTSUM_JSONFILE="+opts.jsonFile,
 		"GOTESTSUM_JSONFILE_TIMING_EVENTS="+opts.jsonFileTimingEvents,
 		"GOTESTSUM_JUNITFILE="+opts.junitFile,
-		fmt.Sprintf("GOTESTSUM_ELAPSED=%.3f", execution.Elapsed().Seconds()),
+		fmt.Sprintf("GOTESTSUM_ELAPSED=%.3fs", execution.Elapsed().Seconds()),
 		fmt.Sprintf("TESTS_TOTAL=%d", execution.Total()),
 		fmt.Sprintf("TESTS_FAILED=%d", len(execution.Failed())),
 		fmt.Sprintf("TESTS_SKIPPED=%d", len(execution.Skipped())),


Test patch:
diff --git a/cmd/handler_test.go b/cmd/handler_test.go
index 5d55f9d..0848a92 100644
--- a/cmd/handler_test.go
+++ b/cmd/handler_test.go
@@ -39,9 +39,10 @@ func TestPostRunHook(t *testing.T) {
 	assert.NilError(t, err)
 
 	actual := text.ProcessLines(t, buf, func(line string) string {
-		if strings.HasPrefix(line, "GOTESTSUM_ELAPSED=0.0") {
+		if strings.HasPrefix(line, "GOTESTSUM_ELAPSED=0.0") &&
+			strings.HasSuffix(line, "s") {
 			i := strings.Index(line, "=")
-			return line[:i] + "=0.000"
+			return line[:i] + "=0.000s"
 		}
 		return line
 	})
diff --git a/cmd/testdata/post-run-hook-expected b/cmd/testdata/post-run-hook-expected
index a2a6b9e..7e5fd9a 100644
--- a/cmd/testdata/post-run-hook-expected
+++ b/cmd/testdata/post-run-hook-expected
@@ -1,4 +1,4 @@
-GOTESTSUM_ELAPSED=0.000
+GOTESTSUM_ELAPSED=0.000s
 GOTESTSUM_FORMAT=short
 GOTESTSUM_JSONFILE=events.json
 GOTESTSUM_JSONFILE_TIMING_EVENTS=timing.json