Skip to content

Commit

Permalink
test: cleanup gazelle tests and run them in parallel (#1159)
Browse files Browse the repository at this point in the history
  • Loading branch information
aignas authored Apr 10, 2023
1 parent b80b8fd commit 1e869d8
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions gazelle/python/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func TestGazelleBinary(t *testing.T) {

func testPath(t *testing.T, name string, files []bazel.RunfileEntry) {
t.Run(name, func(t *testing.T) {
var inputs []testtools.FileSpec
var goldens []testtools.FileSpec
t.Parallel()
var inputs, goldens []testtools.FileSpec

var config *testYAML
for _, f := range files {
Expand Down Expand Up @@ -111,43 +111,49 @@ func testPath(t *testing.T, name string, files []bazel.RunfileEntry) {
Path: filepath.Join(name, strings.TrimSuffix(shortPath, ".in")),
Content: string(content),
})
} else if strings.HasSuffix(shortPath, ".out") {
continue
}

if strings.HasSuffix(shortPath, ".out") {
goldens = append(goldens, testtools.FileSpec{
Path: filepath.Join(name, strings.TrimSuffix(shortPath, ".out")),
Content: string(content),
})
} else {
inputs = append(inputs, testtools.FileSpec{
Path: filepath.Join(name, shortPath),
Content: string(content),
})
goldens = append(goldens, testtools.FileSpec{
Path: filepath.Join(name, shortPath),
Content: string(content),
})
continue
}

inputs = append(inputs, testtools.FileSpec{
Path: filepath.Join(name, shortPath),
Content: string(content),
})
goldens = append(goldens, testtools.FileSpec{
Path: filepath.Join(name, shortPath),
Content: string(content),
})
}

testdataDir, cleanup := testtools.CreateFiles(t, inputs)
defer cleanup()
defer func() {
if t.Failed() {
filepath.Walk(testdataDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
t.Logf("%q exists", strings.TrimPrefix(path, testdataDir))
return nil
})
t.Cleanup(cleanup)
t.Cleanup(func() {
if !t.Failed() {
return
}
}()

filepath.Walk(testdataDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
t.Logf("%q exists", strings.TrimPrefix(path, testdataDir))
return nil
})
})

workspaceRoot := filepath.Join(testdataDir, name)

args := []string{"-build_file_name=BUILD,BUILD.bazel"}

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
t.Cleanup(cancel)
cmd := exec.CommandContext(ctx, gazellePath, args...)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
Expand Down

0 comments on commit 1e869d8

Please sign in to comment.