TestPermanentFailure covers a test that always fails: the wrapper must exit non-zero, emit a permanent test failures JSON line, and NOT emit a flakytest failures JSON line. The test should be retried at least minRetries times.
(t *testing.T)
| 169 | // non-zero, emit a permanent test failures JSON line, and NOT emit a flakytest |
| 170 | // failures JSON line. The test should be retried at least minRetries times. |
| 171 | func TestPermanentFailure(t *testing.T) { |
| 172 | t.Parallel() |
| 173 | |
| 174 | testfile := filepath.Join(t.TempDir(), "permfail_test.go") |
| 175 | code := []byte(`package permfail_test |
| 176 | |
| 177 | import "testing" |
| 178 | |
| 179 | func TestAlwaysFail(t *testing.T) { |
| 180 | t.Fatal("always fails") |
| 181 | } |
| 182 | `) |
| 183 | if err := os.WriteFile(testfile, code, 0o644); err != nil { |
| 184 | t.Fatalf("writing package: %s", err) |
| 185 | } |
| 186 | |
| 187 | out, err := cmdTestwrapper(t, "-v", testfile).CombinedOutput() |
| 188 | if err == nil { |
| 189 | t.Fatalf("testwrapper %s: expected error but it succeeded with output:\n%s", testfile, out) |
| 190 | } |
| 191 | if code, ok := errExitCode(err); ok && code != 1 { |
| 192 | t.Errorf("expected exit code 1 but got %d; output:\n%s", code, out) |
| 193 | } |
| 194 | |
| 195 | if bytes.Contains(out, []byte("flakytest failures JSON:")) { |
| 196 | t.Errorf("unexpected flakytest failures JSON line in output (test never passed):\n%s", out) |
| 197 | } |
| 198 | if !bytes.Contains(out, []byte("permanent test failures JSON:")) { |
| 199 | t.Errorf("missing permanent test failures JSON line in output:\n%s", out) |
| 200 | } |
| 201 | // First pass + at least minRetries retries = 3 runs. |
| 202 | if runs := bytes.Count(out, []byte("=== RUN TestAlwaysFail")); runs < 3 { |
| 203 | t.Errorf("expected TestAlwaysFail to run >= 3 times (1 first + 2 retries) but ran %d times in output:\n%s", runs, out) |
| 204 | } |
| 205 | |
| 206 | if testing.Verbose() { |
| 207 | t.Logf("success - output:\n%s", out) |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | // TestRaceSuppressesFlakyRetry verifies that detecting a data race |
| 212 | // in a package's output stops testwrapper from retrying any flaky |
nothing calls this directly
no test coverage detected
searching dependent graphs…