Skip to content

Commit

Permalink
Make testmaingen more idiomatic
Browse files Browse the repository at this point in the history
Summary: Better layout/organization. Needed for downstream work.

Reviewed By: inesusvet

Differential Revision: D68396871

fbshipit-source-id: 6e6976d724d985c144dbb2d73b32e636aa70182f
  • Loading branch information
echistyakov authored and facebook-github-bot committed Jan 20, 2025
1 parent afd9d44 commit a979e49
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions go_bootstrap/tools/go/testmaingen.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ import (
"go/scanner"
"go/token"
"log"
"maps"
"os"
"path/filepath"
"reflect"
"slices"
"sort"
"strings"
"text/template"
Expand Down Expand Up @@ -131,20 +133,31 @@ func main() {
os.Args = loadArgs(os.Args)
flag.Parse()

testFuncs, err := loadTestFuncsFromFiles(pkgImportPath, flag.Args())
if err != nil {
log.Fatalln("Could not read test files:", err)
}
coverInfos := make([]coverInfo, 0, len(coverPkgs))
for importPath, varToFileMap := range coverPkgs {
coverVarMap := make(map[string]*CoverVar, len(varToFileMap))
for varName, fileName := range varToFileMap {
coverVarMap[fileName] = &CoverVar{
File: filepath.Join(importPath, fileName),
Var: varName,
}
}

for importPath, vars := range coverPkgs {
cover := coverInfo{&Package{importPath}, make(map[string]*CoverVar)}
for v, f := range vars {
cover.Vars[f] = &CoverVar{File: filepath.Join(importPath, f), Var: v}
cover := coverInfo{
Package: &Package{ImportPath: importPath},
Vars: coverVarMap,
}
testFuncs.Cover = append(testFuncs.Cover, cover)
testCoverPaths = append(testCoverPaths, importPath)
coverInfos = append(coverInfos, cover)
}

testCover = testCoverMode != ""
testCoverPaths = append(testCoverPaths, slices.Collect(maps.Keys(coverPkgs))...)

testFuncs, err := loadTestFuncsFromFiles(pkgImportPath, flag.Args())
if err != nil {
log.Fatalln("Could not read test files:", err)
}
testFuncs.Cover = append(testFuncs.Cover, coverInfos...)

out := os.Stdout
if outputFile != "" {
Expand Down

0 comments on commit a979e49

Please sign in to comment.