@@ -74,8 +74,8 @@ func TestGazelleBinary(t *testing.T) {
74
74
75
75
func testPath (t * testing.T , name string , files []bazel.RunfileEntry ) {
76
76
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
79
79
80
80
var config * testYAML
81
81
for _ , f := range files {
@@ -111,43 +111,49 @@ func testPath(t *testing.T, name string, files []bazel.RunfileEntry) {
111
111
Path : filepath .Join (name , strings .TrimSuffix (shortPath , ".in" )),
112
112
Content : string (content ),
113
113
})
114
- } else if strings .HasSuffix (shortPath , ".out" ) {
114
+ continue
115
+ }
116
+
117
+ if strings .HasSuffix (shortPath , ".out" ) {
115
118
goldens = append (goldens , testtools.FileSpec {
116
119
Path : filepath .Join (name , strings .TrimSuffix (shortPath , ".out" )),
117
120
Content : string (content ),
118
121
})
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
128
123
}
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
+ })
129
133
}
130
134
131
135
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
142
140
}
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
+ })
144
150
145
151
workspaceRoot := filepath .Join (testdataDir , name )
146
152
147
153
args := []string {"-build_file_name=BUILD,BUILD.bazel" }
148
154
149
155
ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Second )
150
- defer cancel ( )
156
+ t . Cleanup ( cancel )
151
157
cmd := exec .CommandContext (ctx , gazellePath , args ... )
152
158
var stdout , stderr bytes.Buffer
153
159
cmd .Stdout = & stdout
0 commit comments