(t *testing.T, file string)
| 60 | } |
| 61 | |
| 62 | func testGoldenFile(t *testing.T, file string) { |
| 63 | giveSrc, err := os.ReadFile(file) |
| 64 | if err != nil { |
| 65 | t.Fatal(err) |
| 66 | } |
| 67 | |
| 68 | wantSrc, err := os.ReadFile(file + ".golden") |
| 69 | if err != nil { |
| 70 | t.Fatal("Bad test: missing .golden file:", err) |
| 71 | } |
| 72 | |
| 73 | type runTests struct { |
| 74 | noOptions bool |
| 75 | optNoWrapN bool |
| 76 | } |
| 77 | run := runTests{true, true} // by default, run all tests. |
| 78 | if strings.Contains(string(giveSrc), "@runIf options=<empty>") { |
| 79 | run = runTests{noOptions: true} |
| 80 | } |
| 81 | if strings.Contains(string(giveSrc), "@runIf options=no-wrapn") { |
| 82 | run = runTests{optNoWrapN: true} |
| 83 | } |
| 84 | |
| 85 | if run.noOptions { |
| 86 | t.Run("no options", func(t *testing.T) { |
| 87 | testGoldenContents(t, nil /* additionalFlags */, file, giveSrc, wantSrc) |
| 88 | }) |
| 89 | } |
| 90 | |
| 91 | if run.optNoWrapN { |
| 92 | t.Run("option no-wrapn", func(t *testing.T) { |
| 93 | testGoldenContents(t, []string{"-no-wrapn"}, file, giveSrc, wantSrc) |
| 94 | }) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | func testGoldenContents(t *testing.T, additionalFlags []string, file string, giveSrc, wantSrc []byte) { |
| 99 | wantLogs, err := extractLogs(giveSrc) |
no test coverage detected