Skip to content

Commit 1e869d8

Browse files
authored
test: cleanup gazelle tests and run them in parallel (bazel-contrib#1159)
1 parent b80b8fd commit 1e869d8

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

gazelle/python/python_test.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ func TestGazelleBinary(t *testing.T) {
7474

7575
func 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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy