Skip to content

Commit

Permalink
Merge pull request #168 from dnephin/slowest-skip-subtests
Browse files Browse the repository at this point in the history
slowest: skip root tests when subtests are slow
  • Loading branch information
dnephin committed Dec 13, 2020
2 parents fcc882a + fc388e3 commit 9c36896
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/tool/slowest/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func rewriteAST(file *ast.File, testNames set, skipStmt ast.Stmt) bool {

type set map[string]struct{}

// testNamesByPkgName removes subtests from the list of TestCases, then builds
// testNamesByPkgName strips subtest names from test names, then builds
// and returns a slice of all the packages names, and a mapping of package name
// to set of failed tests in that package.
//
Expand All @@ -124,14 +124,16 @@ func testNamesByPkgName(tcs []testjson.TestCase) ([]string, map[string]set) {
var pkgs []string
index := make(map[string]set)
for _, tc := range tcs {
testName := tc.Test.Name()
if tc.Test.IsSubTest() {
continue
root, _ := tc.Test.Split()
testName = root
}
if len(index[tc.Package]) == 0 {
pkgs = append(pkgs, tc.Package)
index[tc.Package] = make(map[string]struct{})
}
index[tc.Package][tc.Test.Name()] = struct{}{}
index[tc.Package][testName] = struct{}{}
}
return pkgs, index
}
Expand Down

0 comments on commit 9c36896

Please sign in to comment.