@@ -3,7 +3,6 @@ package main
33import (
44 "bytes"
55 "context"
6- "encoding/json"
76 "os"
87 osexec "os/exec"
98 "path/filepath"
@@ -81,32 +80,21 @@ func TestReplay(t *testing.T) {
8180
8281 t .Parallel ()
8382 ctx := context .Background ()
84- var dirs []string
85- err := filepath .Walk ("testdata" , func (path string , info os.FileInfo , err error ) error {
86- if err != nil {
87- return err
88- }
89- if info .Name () == "sqlc.json" || info .Name () == "sqlc.yaml" || info .Name () == "sqlc.yml" {
90- dirs = append (dirs , filepath .Dir (path ))
91- return filepath .SkipDir
92- }
93- return nil
94- })
95- if err != nil {
96- t .Fatal (err )
97- }
98- for _ , replay := range dirs {
83+ for _ , replay := range FindTests (t , "testdata" ) {
9984 tc := replay
100- t .Run (tc , func (t * testing.T ) {
85+ t .Run (tc . Name , func (t * testing.T ) {
10186 t .Parallel ()
10287
10388 var stderr bytes.Buffer
10489 var output map [string ]string
10590 var err error
10691
107- path , _ := filepath .Abs (tc )
108- args := parseExec (t , path )
109- expected := expectedStderr (t , path )
92+ path , _ := filepath .Abs (tc .Path )
93+ args := tc .Exec
94+ if args == nil {
95+ args = & Exec {Command : "generate" }
96+ }
97+ expected := string (tc .Stderr )
11098
11199 if args .Process != "" {
112100 _ , err := osexec .LookPath (args .Process )
@@ -206,44 +194,6 @@ func cmpDirectory(t *testing.T, dir string, actual map[string]string) {
206194 }
207195}
208196
209- func expectedStderr (t * testing.T , dir string ) string {
210- t .Helper ()
211- path := filepath .Join (dir , "stderr.txt" )
212- if _ , err := os .Stat (path ); ! os .IsNotExist (err ) {
213- blob , err := os .ReadFile (path )
214- if err != nil {
215- t .Fatal (err )
216- }
217- return string (blob )
218- }
219- return ""
220- }
221-
222- type exec struct {
223- Command string `json:"command"`
224- Process string `json:"process"`
225- Env map [string ]string `json:"env"`
226- }
227-
228- func parseExec (t * testing.T , dir string ) exec {
229- t .Helper ()
230- var e exec
231- path := filepath .Join (dir , "exec.json" )
232- if _ , err := os .Stat (path ); ! os .IsNotExist (err ) {
233- blob , err := os .ReadFile (path )
234- if err != nil {
235- t .Fatal (err )
236- }
237- if err := json .Unmarshal (blob , & e ); err != nil {
238- t .Fatal (err )
239- }
240- }
241- if e .Command == "" {
242- e .Command = "generate"
243- }
244- return e
245- }
246-
247197func BenchmarkReplay (b * testing.B ) {
248198 ctx := context .Background ()
249199 var dirs []string
0 commit comments