@@ -289,22 +289,23 @@ func (s *Suite) createExpectedResults(pguri string, commit bool) error {
289289// necessary. It then compares the actual output to the expected output and
290290// reports results using the specified formatter.
291291// Each query runs in its own transaction that rolls back (unless commit is true).
292- func (s * Suite ) testQueries (pguri string , formatter OutputFormatter , outputPath string , commit bool ) error {
292+ // Returns the test summary for exit code determination.
293+ func (s * Suite ) testQueries (pguri string , formatter OutputFormatter , outputPath string , commit bool ) (* TestSummary , error ) {
293294 db , err := sql .Open ("pgx" , pguri )
294295 if err != nil {
295- return fmt .Errorf ("Failed to connect to '%s': %s\n " , pguri , err )
296+ return nil , fmt .Errorf ("Failed to connect to '%s': %s\n " , pguri , err )
296297 }
297298 defer db .Close ()
298299
299300 w , close , err := getWriter (outputPath )
300301 if err != nil {
301- return err
302+ return nil , err
302303 }
303304 defer close ()
304305
305306 summary := NewTestSummary ()
306307 if err := formatter .Start (w ); err != nil {
307- return err
308+ return nil , err
308309 }
309310
310311 for _ , folder := range s .Dirs {
@@ -319,7 +320,7 @@ func (s *Suite) testQueries(pguri string, formatter OutputFormatter, outputPath
319320
320321 queries , err := parseQueryFile (qfile )
321322 if err != nil {
322- return err
323+ return nil , err
323324 }
324325
325326 for _ , q := range queries {
@@ -334,7 +335,7 @@ func (s *Suite) testQueries(pguri string, formatter OutputFormatter, outputPath
334335
335336 p , err := q .GetPlan (rdir )
336337 if err != nil {
337- return err
338+ return nil , err
338339 }
339340
340341 if err := s .runInTransaction (db , commit , func (tx * sql.Tx ) error {
@@ -362,13 +363,16 @@ func (s *Suite) testQueries(pguri string, formatter OutputFormatter, outputPath
362363 }
363364 return nil
364365 }); err != nil {
365- return err
366+ return nil , err
366367 }
367368 }
368369 }
369370 }
370371
371- return formatter .Finish (summary , w )
372+ if err := formatter .Finish (summary , w ); err != nil {
373+ return nil , err
374+ }
375+ return summary , nil
372376}
373377
374378// runInTransaction executes fn within a transaction, rolling back on error or if commit is false
0 commit comments