| 36 | } |
| 37 | |
| 38 | func TestExamples(t *testing.T) { |
| 39 | t.Parallel() |
| 40 | ctx := context.Background() |
| 41 | |
| 42 | examples, err := filepath.Abs(filepath.Join("..", "..", "examples")) |
| 43 | if err != nil { |
| 44 | t.Fatal(err) |
| 45 | } |
| 46 | |
| 47 | files, err := os.ReadDir(examples) |
| 48 | if err != nil { |
| 49 | t.Fatal(err) |
| 50 | } |
| 51 | |
| 52 | for _, replay := range files { |
| 53 | if !replay.IsDir() { |
| 54 | continue |
| 55 | } |
| 56 | tc := replay.Name() |
| 57 | t.Run(tc, func(t *testing.T) { |
| 58 | t.Parallel() |
| 59 | path := filepath.Join(examples, tc) |
| 60 | var stderr bytes.Buffer |
| 61 | opts := &cmd.Options{ |
| 62 | Env: cmd.Env{}, |
| 63 | Stderr: &stderr, |
| 64 | } |
| 65 | output, err := cmd.Generate(ctx, path, "", opts) |
| 66 | if err != nil { |
| 67 | t.Fatalf("sqlc generate failed: %s", stderr.String()) |
| 68 | } |
| 69 | cmpDirectory(t, path, output) |
| 70 | }) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | func BenchmarkExamples(b *testing.B) { |
| 75 | ctx := context.Background() |