TestGolden runs errtrace on all .go files inside testdata/golden, and compares the output to the corresponding .golden file. Files must match exactly. If log messages are expected associated with specific lines, they can be included in the source and the .golden file in the format: foo() // want:
(t *testing.T)
| 46 | // The log message will be matched against the output of errtrace on stderr. |
| 47 | // The string must be a valid Go string literal. |
| 48 | func TestGolden(t *testing.T) { |
| 49 | files, err := filepath.Glob("testdata/golden/*.go") |
| 50 | if err != nil { |
| 51 | t.Fatal(err) |
| 52 | } |
| 53 | |
| 54 | for _, file := range files { |
| 55 | name := strings.TrimSuffix(filepath.Base(file), ".go") |
| 56 | t.Run(name, func(t *testing.T) { |
| 57 | testGoldenFile(t, file) |
| 58 | }) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func testGoldenFile(t *testing.T, file string) { |
| 63 | giveSrc, err := os.ReadFile(file) |
nothing calls this directly
no test coverage detected