`func \(unexportedType\)`,
},
},
+ // Package with just the package declaration. Issue 31457.
+ {
+ "only package declaration",
+ []string{"-all", p + "/nested/empty"},
+ []string{`package empty .*import`},
+ nil,
+ },
// Package dump -short
{
"full package with -short",
}
func (pb *pkgBuffer) Write(p []byte) (int, error) {
- if !pb.printed && len(p) > 0 {
+ pb.packageClause()
+ return pb.Buffer.Write(p)
+}
+
+func (pb *pkgBuffer) packageClause() {
+ if !pb.printed {
pb.printed = true
// Only show package clause for commands if requested explicitly.
if pb.pkg.pkg.Name != "main" || showCmd {
pb.pkg.packageClause()
}
}
- return pb.Buffer.Write(p)
}
type PackageError string // type returned by pkg.Fatalf.
}
func (pkg *Package) flush() {
+ // Print the package clause in case it wasn't written already.
+ pkg.buf.packageClause()
_, err := pkg.writer.Write(pkg.buf.Bytes())
if err != nil {
log.Fatal(err)