Teach stubmaker how to work with methods, not just funcs. (#23634)

Teach stubmaker how to work with methods, not just funcs.  Fix some stubs defined in #23557 which either had the wrong signature or needed to be public.
This commit is contained in:
Nick Cabatoff
2023-10-12 14:38:28 -04:00
committed by GitHub
parent 7872338ec1
commit e232da5ffa
4 changed files with 19 additions and 12 deletions

View File

@@ -12,11 +12,14 @@ import (
"io"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-hclog"
"golang.org/x/tools/go/packages"
)
@@ -225,21 +228,23 @@ func isStubNeeded(funcs []string) (bool, error) {
case len(found) == len(funcs):
return false, nil
case len(found) != 0:
return false, fmt.Errorf("funcs partially defined: need=%v, found=%v", funcs, found)
sort.Strings(found)
sort.Strings(funcs)
delta := cmp.Diff(found, funcs)
return false, fmt.Errorf("funcs partially defined, delta=%s", delta)
}
return true, nil
}
var funcRE = regexp.MustCompile("^func *(?:[(][^)]+[)])? *([^(]+)")
func getFuncs(inputLines []string) []string {
var funcs []string
for _, line := range inputLines {
trimmed := strings.TrimSpace(line)
if strings.HasPrefix(trimmed, "func ") {
i := strings.Index(trimmed, "(")
if i != -1 {
funcs = append(funcs, trimmed[5:i])
}
matches := funcRE.FindStringSubmatch(line)
if len(matches) > 1 {
funcs = append(funcs, matches[1])
}
}
return funcs