compiler/protogen: disable warnings in tests

Change-Id: I80ff3c31dc1039a833e6c962d5f3fc6e0aa46f6a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/222377
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Herbie Ong <herbie@google.com>
This commit is contained in:
Damien Neil 2020-03-06 13:58:41 -08:00
parent a30b571f93
commit e358d430e7
2 changed files with 16 additions and 4 deletions

View File

@ -295,7 +295,7 @@ func (opts Options) New(req *pluginpb.CodeGeneratorRequest) (*Plugin, error) {
switch {
case packageImportPath != "":
// Command line: import_path=quux/bar
log.Printf("WARNING: Deprecated use of the 'import_path' command-line argument. In %q, please specify:\n"+
warn("Deprecated use of the 'import_path' command-line argument. In %q, please specify:\n"+
"\toption go_package = %q;\n"+
"A future release of protoc-gen-go will no longer support the 'import_path' argument.\n"+
"See "+goPackageDocURL+" for more information.\n"+
@ -304,14 +304,14 @@ func (opts Options) New(req *pluginpb.CodeGeneratorRequest) (*Plugin, error) {
// Command line: M=foo.proto=quux/bar
case packageName != "" && importPath == "":
// Source file: option go_package = "quux";
log.Printf("WARNING: Deprecated use of 'go_package' option without a full import path in %q, please specify:\n"+
warn("Deprecated use of 'go_package' option without a full import path in %q, please specify:\n"+
"\toption go_package = %q;\n"+
"A future release of protoc-gen-go will require the import path be specified.\n"+
"See "+goPackageDocURL+" for more information.\n"+
"\n", fdesc.GetName(), goPkgOpt)
case packageName == "" && importPath == "":
// No Go package information provided.
log.Printf("WARNING: Missing 'go_package' option in %q, please specify:\n"+
warn("Missing 'go_package' option in %q, please specify:\n"+
"\toption go_package = %q;\n"+
"A future release of protoc-gen-go will require this be specified.\n"+
"See "+goPackageDocURL+" for more information.\n"+
@ -534,7 +534,7 @@ func goPackageOption(d *descriptorpb.FileDescriptorProto) (pkg GoPackageName, im
rawPkg, impPath := goPackageOptionRaw(opt)
pkg = cleanPackageName(rawPkg)
if string(pkg) != rawPkg && impPath != "" {
log.Printf("WARNING: Malformed 'go_package' option in %q, please specify:\n"+
warn("Malformed 'go_package' option in %q, please specify:\n"+
"\toption go_package = %q;\n"+
"A future release of protoc-gen-go will reject this.\n"+
"See "+goPackageDocURL+" for more information.\n"+
@ -1346,3 +1346,11 @@ func (c Comments) String() string {
}
return string(b)
}
var warnings = true
func warn(format string, a ...interface{}) {
if warnings {
log.Printf("WARNING: "+format, a...)
}
}

View File

@ -18,6 +18,10 @@ import (
"google.golang.org/protobuf/types/pluginpb"
)
func init() {
warnings = false // avoid spam in tests
}
func TestPluginParameters(t *testing.T) {
var flags flag.FlagSet
value := flags.Int("integer", 0, "")