import (
"bytes"
"flag"
+ "log"
"os"
"path/filepath"
"regexp"
`func MultiLineFunc\(x interface{ ... }\) \(r struct{ ... }\)`, // Multi line function.
`var LongLine = newLongLine\(("someArgument[1-4]", ){4}...\)`, // Long list of arguments.
`type T1 = T2`, // Type alias
+ `type SimpleConstraint interface{ ... }`,
+ `type TildeConstraint interface{ ... }`,
+ `type StructConstraint interface{ ... }`,
},
[]string{
`const internalConstant = 2`, // No internal constants.
`Comment about exported method`,
`type T1 = T2`,
`type T2 int`,
+ `type SimpleConstraint interface {`,
+ `type TildeConstraint interface {`,
+ `type StructConstraint interface {`,
},
[]string{
`constThree`,
func TestDoc(t *testing.T) {
maybeSkip(t)
+ defer log.SetOutput(log.Writer())
for _, test := range tests {
var b bytes.Buffer
var flagSet flag.FlagSet
+ var logbuf bytes.Buffer
+ log.SetOutput(&logbuf)
err := do(&b, &flagSet, test.args)
if err != nil {
t.Fatalf("%s %v: %s\n", test.name, test.args, err)
}
+ if logbuf.Len() > 0 {
+ t.Errorf("%s %v: unexpected log messages:\n%s", test.name, test.args, logbuf.Bytes())
+ }
output := b.Bytes()
failed := false
for j, yes := range test.yes {
if len(names) == 0 {
// Embedded type. Use the name of the type. It must be of the form ident or
// pkg.ident (for structs and interfaces), or *ident or *pkg.ident (structs only).
+ // Or a type embedded in a constraint.
// Nothing else is allowed.
ty := field.Type
if se, ok := field.Type.(*ast.StarExpr); !isInterface && ok {
// embedded types in structs.
ty = se.X
}
+ constraint := false
switch ident := ty.(type) {
case *ast.Ident:
if isInterface && ident.Name == "error" && ident.Obj == nil {
case *ast.SelectorExpr:
// An embedded type may refer to a type in another package.
names = []*ast.Ident{ident.Sel}
+ default:
+ // An approximation or union or type
+ // literal in an interface.
+ constraint = true
}
- if names == nil {
+ if names == nil && !constraint {
// Can only happen if AST is incorrect. Safe to continue with a nil list.
log.Print("invalid program: unexpected type for embedded field")
}