(t *testing.T)
| 391 | } |
| 392 | |
| 393 | func TestCached(t *testing.T) { |
| 394 | t.Parallel() |
| 395 | |
| 396 | // Construct our trivial package. |
| 397 | pkgDir := t.TempDir() |
| 398 | goVersion := runtime.Version() |
| 399 | goVersion = strings.TrimPrefix(goVersion, "go") |
| 400 | goVersion, _, _ = strings.Cut(goVersion, "-X:") // map 1.26.1-X:nogreenteagc to 1.26.1 |
| 401 | |
| 402 | goMod := fmt.Sprintf(`module example.com |
| 403 | |
| 404 | go %s |
| 405 | `, goVersion) |
| 406 | test := `package main |
| 407 | import "testing" |
| 408 | |
| 409 | func TestCached(t *testing.T) {} |
| 410 | ` |
| 411 | |
| 412 | for f, c := range map[string]string{ |
| 413 | "go.mod": goMod, |
| 414 | "cached_test.go": test, |
| 415 | } { |
| 416 | err := os.WriteFile(filepath.Join(pkgDir, f), []byte(c), 0o644) |
| 417 | if err != nil { |
| 418 | t.Fatalf("writing package: %s", err) |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | for name, args := range map[string][]string{ |
| 423 | "without_flags": {"./..."}, |
| 424 | "with_short": {"./...", "-short"}, |
| 425 | "with_coverprofile": {"./...", "-coverprofile=" + filepath.Join(t.TempDir(), "coverage.out")}, |
| 426 | } { |
| 427 | t.Run(name, func(t *testing.T) { |
| 428 | var ( |
| 429 | out []byte |
| 430 | err error |
| 431 | ) |
| 432 | for range 2 { |
| 433 | cmd := cmdTestwrapper(t, args...) |
| 434 | cmd.Dir = pkgDir |
| 435 | out, err = cmd.CombinedOutput() |
| 436 | if err != nil { |
| 437 | t.Fatalf("testwrapper ./...: expected no error but got: %v; output was:\n%s", err, out) |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | want := []byte("ok\texample.com\t(cached)") |
| 442 | if !bytes.Contains(out, want) { |
| 443 | t.Fatalf("wanted output containing %q but got:\n%s", want, out) |
| 444 | } |
| 445 | |
| 446 | if testing.Verbose() { |
| 447 | t.Logf("success - output:\n%s", out) |
| 448 | } |
| 449 | }) |
| 450 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…