@@ -74,8 +74,8 @@ func TestGazelleBinary(t *testing.T) {
7474
7575func testPath (t * testing.T , name string , files []bazel.RunfileEntry ) {
7676 t .Run (name , func (t * testing.T ) {
77- var inputs []testtools. FileSpec
78- var goldens []testtools.FileSpec
77+ t . Parallel ()
78+ var inputs , goldens []testtools.FileSpec
7979
8080 var config * testYAML
8181 for _ , f := range files {
@@ -111,43 +111,49 @@ func testPath(t *testing.T, name string, files []bazel.RunfileEntry) {
111111 Path : filepath .Join (name , strings .TrimSuffix (shortPath , ".in" )),
112112 Content : string (content ),
113113 })
114- } else if strings .HasSuffix (shortPath , ".out" ) {
114+ continue
115+ }
116+
117+ if strings .HasSuffix (shortPath , ".out" ) {
115118 goldens = append (goldens , testtools.FileSpec {
116119 Path : filepath .Join (name , strings .TrimSuffix (shortPath , ".out" )),
117120 Content : string (content ),
118121 })
119- } else {
120- inputs = append (inputs , testtools.FileSpec {
121- Path : filepath .Join (name , shortPath ),
122- Content : string (content ),
123- })
124- goldens = append (goldens , testtools.FileSpec {
125- Path : filepath .Join (name , shortPath ),
126- Content : string (content ),
127- })
122+ continue
128123 }
124+
125+ inputs = append (inputs , testtools.FileSpec {
126+ Path : filepath .Join (name , shortPath ),
127+ Content : string (content ),
128+ })
129+ goldens = append (goldens , testtools.FileSpec {
130+ Path : filepath .Join (name , shortPath ),
131+ Content : string (content ),
132+ })
129133 }
130134
131135 testdataDir , cleanup := testtools .CreateFiles (t , inputs )
132- defer cleanup ()
133- defer func () {
134- if t .Failed () {
135- filepath .Walk (testdataDir , func (path string , info os.FileInfo , err error ) error {
136- if err != nil {
137- return err
138- }
139- t .Logf ("%q exists" , strings .TrimPrefix (path , testdataDir ))
140- return nil
141- })
136+ t .Cleanup (cleanup )
137+ t .Cleanup (func () {
138+ if ! t .Failed () {
139+ return
142140 }
143- }()
141+
142+ filepath .Walk (testdataDir , func (path string , info os.FileInfo , err error ) error {
143+ if err != nil {
144+ return err
145+ }
146+ t .Logf ("%q exists" , strings .TrimPrefix (path , testdataDir ))
147+ return nil
148+ })
149+ })
144150
145151 workspaceRoot := filepath .Join (testdataDir , name )
146152
147153 args := []string {"-build_file_name=BUILD,BUILD.bazel" }
148154
149155 ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Second )
150- defer cancel ( )
156+ t . Cleanup ( cancel )
151157 cmd := exec .CommandContext (ctx , gazellePath , args ... )
152158 var stdout , stderr bytes.Buffer
153159 cmd .Stdout = & stdout
0 commit comments