From c6728c55c928998e20b9b7c1d45004fde4cf5fdf Mon Sep 17 00:00:00 2001 From: Norman Meier Date: Tue, 10 Dec 2024 15:28:28 +0100 Subject: [PATCH] chore: make genstd consider test files Signed-off-by: Norman Meier --- misc/genstd/genstd.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/misc/genstd/genstd.go b/misc/genstd/genstd.go index 3dd38214595..f3656b5c0c5 100644 --- a/misc/genstd/genstd.go +++ b/misc/genstd/genstd.go @@ -119,13 +119,25 @@ func walkStdlibs(stdlibsPath string) ([]*pkgData, error) { return nil } - // skip non-source and test files. + // skip non-source files. ext := filepath.Ext(fpath) if (ext != ".go" && ext != ".gno") || strings.HasSuffix(fpath, ".gen.go") { return nil } + fs := token.NewFileSet() + f, err := parser.ParseFile(fs, fpath, nil, parser.SkipObjectResolution) + if err != nil { + return err + } + + // skip external test files + noExt := fpath[:len(fpath)-len(ext)] + if strings.HasSuffix(noExt, "_test") && strings.HasSuffix(f.Name.Name, "_test") { + return nil + } + dir := filepath.Dir(fpath) var pkg *pkgData // if we've already been in this directory in a previous file, it must @@ -141,11 +153,6 @@ func walkStdlibs(stdlibsPath string) ([]*pkgData, error) { } else { pkg = pkgs[len(pkgs)-1] } - fs := token.NewFileSet() - f, err := parser.ParseFile(fs, fpath, nil, parser.SkipObjectResolution) - if err != nil { - return err - } if ext == ".go" { // keep track of exported function declarations.