@@ -3,8 +3,6 @@ package main
33import (
44 "bytes"
55 "context"
6- "encoding/json"
7- "fmt"
86 "os"
97 osexec "os/exec"
108 "path/filepath"
@@ -97,20 +95,6 @@ func TestReplay(t *testing.T) {
9795
9896 // t.Parallel()
9997 ctx := context .Background ()
100- var dirs []string
101- err := filepath .Walk ("testdata" , func (path string , info os.FileInfo , err error ) error {
102- if err != nil {
103- return err
104- }
105- if info .Name () == "sqlc.json" || info .Name () == "sqlc.yaml" || info .Name () == "sqlc.yml" {
106- dirs = append (dirs , filepath .Dir (path ))
107- return filepath .SkipDir
108- }
109- return nil
110- })
111- if err != nil {
112- t .Fatal (err )
113- }
11498
11599 contexts := map [string ]textContext {
116100 "base" : {
@@ -135,24 +119,29 @@ func TestReplay(t *testing.T) {
135119 },
136120 }
137121
138- for _ , replay := range dirs {
139- tc := replay
140- for name , testctx := range contexts {
141- name := name
142- testctx := testctx
122+ for name , testctx := range contexts {
123+ name := name
124+ testctx := testctx
143125
144- if ! testctx .Enabled () {
145- continue
146- }
126+ if ! testctx .Enabled () {
127+ continue
128+ }
147129
148- t .Run (filepath .Join (name , tc ), func (t * testing.T ) {
130+ for _ , replay := range FindTests (t , "testdata" , name ) {
131+ tc := replay
132+ t .Run (filepath .Join (name , tc .Name ), func (t * testing.T ) {
149133 t .Parallel ()
134+
150135 var stderr bytes.Buffer
151136 var output map [string ]string
152137 var err error
153138
154- path , _ := filepath .Abs (tc )
155- args := parseExec (t , path )
139+ path , _ := filepath .Abs (tc .Path )
140+ args := tc .Exec
141+ if args == nil {
142+ args = & Exec {Command : "generate" }
143+ }
144+ expected := string (tc .Stderr )
156145
157146 if args .Process != "" {
158147 _ , err := osexec .LookPath (args .Process )
@@ -167,7 +156,6 @@ func TestReplay(t *testing.T) {
167156 }
168157 }
169158
170- expected := expectedStderr (t , path , name )
171159 opts := cmd.Options {
172160 Env : cmd.Env {
173161 Debug : opts .DebugFromString (args .Env ["SQLCDEBUG" ]),
@@ -263,50 +251,6 @@ func cmpDirectory(t *testing.T, dir string, actual map[string]string) {
263251 }
264252}
265253
266- func expectedStderr (t * testing.T , dir , testctx string ) string {
267- t .Helper ()
268- paths := []string {
269- filepath .Join (dir , "stderr" , fmt .Sprintf ("%s.txt" , testctx )),
270- filepath .Join (dir , "stderr.txt" ),
271- }
272- for _ , path := range paths {
273- if _ , err := os .Stat (path ); ! os .IsNotExist (err ) {
274- blob , err := os .ReadFile (path )
275- if err != nil {
276- t .Fatal (err )
277- }
278- return string (blob )
279- }
280- }
281- return ""
282- }
283-
284- type exec struct {
285- Command string `json:"command"`
286- Process string `json:"process"`
287- Contexts []string `json:"contexts"`
288- Env map [string ]string `json:"env"`
289- }
290-
291- func parseExec (t * testing.T , dir string ) exec {
292- t .Helper ()
293- var e exec
294- path := filepath .Join (dir , "exec.json" )
295- if _ , err := os .Stat (path ); ! os .IsNotExist (err ) {
296- blob , err := os .ReadFile (path )
297- if err != nil {
298- t .Fatal (err )
299- }
300- if err := json .Unmarshal (blob , & e ); err != nil {
301- t .Fatal (err )
302- }
303- }
304- if e .Command == "" {
305- e .Command = "generate"
306- }
307- return e
308- }
309-
310254func BenchmarkReplay (b * testing.B ) {
311255 ctx := context .Background ()
312256 var dirs []string
0 commit comments