Skip to content

Commit

Permalink
Handle tests in external test packages
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed May 15, 2020
1 parent d8df6c0 commit 82aae80
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/tool/slowest/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func writeTestSkip(tcs []testjson.TestCase, skipStmt ast.Stmt) error {
if len(pkg.Errors) > 0 {
return errPkgLoad(pkg)
}
tcs, ok := index[pkg.PkgPath]
tcs, ok := index[normalizePkgName(pkg.PkgPath)]
if !ok {
log.Debugf("skipping %v, no slow tests", pkg.PkgPath)
continue
Expand All @@ -53,6 +53,14 @@ func writeTestSkip(tcs []testjson.TestCase, skipStmt ast.Stmt) error {
return errTestCasesNotFound(index)
}

// normalizePkgName removes the _test suffix from a package name. External test
// packages (those named package_test) may contain tests, but the test2json output
// always uses the non-external package name. The _test suffix must be removed
// so that any slow tests in an external test package can be found.
func normalizePkgName(name string) string {
return strings.TrimSuffix(name, "_test")
}

// TODO: sometimes this writes the new AST with strange indentation. It appears
// to be non-deterministic. Given the same input, it only happens sometimes.
func writeFile(path string, file *ast.File, fset *token.FileSet) error {
Expand Down

0 comments on commit 82aae80

Please sign in to comment.