Просмотр исходного кода

internal/fileinit: add tests for fileinit and protodesc

Test the fileinit and protodesc packages by verifying that passing a
FileDescriptorProto through a round trip of these packages leaves it
unchanged.

Change-Id: I6bfb894d95f1736f9908adee1ab63e9653b3f1be
Reviewed-on: https://go-review.googlesource.com/c/159762
Reviewed-by: Herbie Ong <herbie@google.com>
Damien Neil 7 лет назад
Родитель
Сommit
e475eaa7ad

+ 92 - 0
internal/fileinit/fileinit_test.go

@@ -0,0 +1,92 @@
+package fileinit_test
+
+import (
+	"bytes"
+	"compress/gzip"
+	"io/ioutil"
+	"testing"
+
+	proto "github.com/golang/protobuf/proto"
+	testpb "github.com/golang/protobuf/v2/internal/testprotos/test"
+	"github.com/golang/protobuf/v2/reflect/protodesc"
+	"github.com/golang/protobuf/v2/reflect/protoreflect"
+	descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
+)
+
+func TestInit(t *testing.T) {
+	// Compare the FileDescriptorProto for the same test file from two different sources:
+	//
+	// 1. The result of passing the fileinit-produced FileDescriptor through protodesc.
+	// 2. The protoc-generated wire-encoded message.
+	//
+	// This serves as a test of both fileinit and protodesc.
+	got := protodesc.ToFileDescriptorProto(testpb.Test_protoFile)
+
+	want := &descriptorpb.FileDescriptorProto{}
+	zb, _ := (&testpb.TestAllTypes{}).Descriptor()
+	r, _ := gzip.NewReader(bytes.NewBuffer(zb))
+	b, _ := ioutil.ReadAll(r)
+	if err := proto.Unmarshal(b, want); err != nil {
+		t.Fatal(err)
+	}
+
+	if !proto.Equal(got, want) {
+		t.Errorf("protodesc.ToFileDescriptorProto(testpb.Test_protoFile) is not equal to the protoc-generated FileDescriptorProto for internal/testprotos/test/test.proto")
+	}
+
+	// Verify that the test proto file provides exhaustive coverage of all descriptor fields.
+	seen := make(map[protoreflect.FullName]bool)
+	visitFields(want.ProtoReflect(), func(field protoreflect.FieldDescriptor) {
+		seen[field.FullName()] = true
+	})
+	ignore := map[protoreflect.FullName]bool{
+		// The protoreflect descriptors don't include source info.
+		"google.protobuf.FileDescriptorProto.source_code_info": true,
+		"google.protobuf.FileDescriptorProto.syntax":           true,
+
+		// TODO: Test oneof and extension options. Testing these requires extending the
+		// options messages (because they contain no user-settable fields), but importing
+		// decriptor.proto from test.proto currently causes an import cycle. Add test
+		// cases when that import cycle has been fixed.
+		"google.protobuf.OneofDescriptorProto.options": true,
+	}
+	for _, messageName := range []protoreflect.Name{
+		"FileDescriptorProto",
+		"DescriptorProto",
+		"FieldDescriptorProto",
+		"OneofDescriptorProto",
+		"EnumDescriptorProto",
+		"EnumValueDescriptorProto",
+		"ServiceDescriptorProto",
+		"MethodDescriptorProto",
+	} {
+		message := descriptorpb.Descriptor_protoFile.Messages().ByName(messageName)
+		for i, fields := 0, message.Fields(); i < fields.Len(); i++ {
+			if name := fields.Get(i).FullName(); !seen[name] && !ignore[name] {
+				t.Errorf("No test for descriptor field: %v", name)
+			}
+		}
+	}
+
+}
+
+// visitFields calls f for every field set in m and its children.
+func visitFields(m protoreflect.Message, f func(protoreflect.FieldDescriptor)) {
+	typ := m.Type()
+	k := m.KnownFields()
+	k.Range(func(num protoreflect.FieldNumber, value protoreflect.Value) bool {
+		field := typ.Fields().ByNumber(num)
+		f(field)
+		switch field.Kind() {
+		case protoreflect.MessageKind, protoreflect.GroupKind:
+			if field.Cardinality() == protoreflect.Repeated {
+				for i, list := 0, value.List(); i < list.Len(); i++ {
+					visitFields(list.Get(i).Message(), f)
+				}
+			} else {
+				visitFields(value.Message(), f)
+			}
+		}
+		return true
+	})
+}

Разница между файлами не показана из-за своего большого размера
+ 1356 - 556
internal/testprotos/test/test.pb.go


+ 92 - 4
internal/testprotos/test/test.proto

@@ -6,6 +6,10 @@ syntax = "proto2";
 
 package goproto.proto.test;
 
+import "test_import.proto";
+import public "test_public.proto";
+import weak "test_weak.proto";
+
 option go_package = "github.com/golang/protobuf/v2/internal/testprotos/test";
 
 message TestAllTypes {
@@ -39,8 +43,12 @@ message TestAllTypes {
   optional group OptionalGroup = 16 {
     optional int32 a = 17;
   }
-  optional NestedMessage optional_nested_message = 18;
-  optional NestedEnum    optional_nested_enum    = 21;
+  optional NestedMessage  optional_nested_message  = 18;
+  optional ForeignMessage optional_foreign_message = 19;
+  optional ImportMessage  optional_import_message  = 20;
+  optional NestedEnum     optional_nested_enum     = 21;
+  optional ForeignEnum    optional_foreign_enum    = 22;
+  optional ImportEnum     optional_import_enum     = 23;
 
   repeated int32         repeated_int32    = 31;
   repeated int64         repeated_int64    = 32;
@@ -60,8 +68,12 @@ message TestAllTypes {
   repeated group RepeatedGroup = 46 {
     optional int32 a = 47;
   }
-  repeated NestedMessage repeated_nested_message = 48;
-  repeated NestedEnum    repeated_nested_enum    = 51;
+  repeated NestedMessage  repeated_nested_message  = 48;
+  repeated ForeignMessage repeated_foreign_message = 49;
+  repeated ImportMessage  repeated_importmessage   = 50;
+  repeated NestedEnum     repeated_nested_enum     = 51;
+  repeated ForeignEnum    repeated_foreign_enum    = 52;
+  repeated ImportEnum     repeated_importenum      = 53;
 
   map <   int32, int32>         map_int32_int32           = 56;
   map <   int64, int64>         map_int64_int64           = 57;
@@ -81,6 +93,25 @@ message TestAllTypes {
   map <  string, NestedMessage> map_string_nested_message = 71;
   map <  string, NestedEnum>    map_string_nested_enum    = 73;
 
+  // Singular with defaults
+  optional    int32 default_int32    = 81 [default =  81    ];
+  optional    int64 default_int64    = 82 [default =  82    ];
+  optional   uint32 default_uint32   = 83 [default =  83    ];
+  optional   uint64 default_uint64   = 84 [default =  84    ];
+  optional   sint32 default_sint32   = 85 [default = -85    ];
+  optional   sint64 default_sint64   = 86 [default =  86    ];
+  optional  fixed32 default_fixed32  = 87 [default =  87    ];
+  optional  fixed64 default_fixed64  = 88 [default =  88    ];
+  optional sfixed32 default_sfixed32 = 89 [default =  89    ];
+  optional sfixed64 default_sfixed64 = 80 [default = -90    ];
+  optional    float default_float    = 91 [default =  91.5  ];
+  optional   double default_double   = 92 [default =  92e3  ];
+  optional     bool default_bool     = 93 [default = true   ];
+  optional   string default_string   = 94 [default = "hello"];
+  optional    bytes default_bytes    = 95 [default = "world"];
+  optional NestedEnum  default_nested_enum  = 96 [default = BAR        ];
+  optional ForeignEnum default_foreign_enum = 97 [default = FOREIGN_BAR];
+
   oneof oneof_field {
     uint32        oneof_uint32         = 111;
     NestedMessage oneof_nested_message = 112;
@@ -94,6 +125,41 @@ message TestAllTypes {
   }
 }
 
+message TestDeprecatedMessage {
+  option deprecated = true;
+  optional int32 deprecated_int32 = 1 [deprecated=true];
+  enum DeprecatedEnum {
+    option deprecated = true;
+    DEPRECATED = 0 [deprecated=true];
+    //DEPRECATED = 0 [deprecated=true];
+  }
+  oneof deprecated_oneof {
+    int32 deprecated_oneof_field = 2 [deprecated = true];
+  }
+}
+
+message ForeignMessage {
+  optional int32 c = 1;
+  optional int32 d = 2;
+}
+
+enum ForeignEnum {
+  FOREIGN_FOO = 4;
+  FOREIGN_BAR = 5;
+  FOREIGN_BAZ = 6;
+}
+
+message TestReservedFields {
+  reserved 2, 15, 9 to 11;
+  reserved "bar", "baz";
+}
+
+enum TestReservedEnumFields {
+  RESERVED_ENUM = 0;
+  reserved 2, 15, 9 to 11;
+  reserved "BAR", "BAZ";
+}
+
 message TestAllExtensions {
   extensions 1 to max;
 }
@@ -145,3 +211,25 @@ extend TestAllExtensions {
   repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;
   repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;
 }
+
+message TestNestedExtension {
+  extend TestAllExtensions {
+    optional string nested_string_extension = 1003;
+  }
+}
+
+// Test that RPC services work.
+message FooRequest  {}
+message FooResponse {}
+
+service TestService {
+  rpc Foo(FooRequest) returns (FooResponse);
+  rpc TestStream(stream FooRequest) returns (stream FooResponse);
+}
+
+service TestDeprecatedService {
+  option deprecated = true;
+  rpc Deprecated(TestDeprecatedMessage) returns (TestDeprecatedMessage) {
+    option deprecated = true;
+  }
+}

+ 155 - 0
internal/testprotos/test/test_import.pb.go

@@ -0,0 +1,155 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// source: test_import.proto
+
+package test
+
+import (
+	bytes "bytes"
+	gzip "compress/gzip"
+	proto "github.com/golang/protobuf/proto"
+	protoreflect "github.com/golang/protobuf/v2/reflect/protoreflect"
+	protoimpl "github.com/golang/protobuf/v2/runtime/protoimpl"
+	reflect "reflect"
+)
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the proto package it is being compiled against.
+// A compilation error at this line likely means your copy of the
+// proto package needs to be updated.
+const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
+
+type ImportEnum int32
+
+const (
+	ImportEnum_IMPORT_ZERO ImportEnum = 0
+)
+
+func (e ImportEnum) Type() protoreflect.EnumType {
+	return xxx_TestImport_protoFile_enumTypes[0]
+}
+func (e ImportEnum) Number() protoreflect.EnumNumber {
+	return protoreflect.EnumNumber(e)
+}
+
+var ImportEnum_name = map[int32]string{
+	0: "IMPORT_ZERO",
+}
+
+var ImportEnum_value = map[string]int32{
+	"IMPORT_ZERO": 0,
+}
+
+func (x ImportEnum) Enum() *ImportEnum {
+	p := new(ImportEnum)
+	*p = x
+	return p
+}
+
+func (x ImportEnum) String() string {
+	return proto.EnumName(ImportEnum_name, int32(x))
+}
+
+func (x *ImportEnum) UnmarshalJSON(data []byte) error {
+	value, err := proto.UnmarshalJSONEnum(ImportEnum_value, data, "ImportEnum")
+	if err != nil {
+		return err
+	}
+	*x = ImportEnum(value)
+	return nil
+}
+
+func (ImportEnum) EnumDescriptor() ([]byte, []int) {
+	return fileDescriptor_89be98e26346f54e_gzipped, []int{0}
+}
+
+type ImportMessage struct {
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *ImportMessage) ProtoReflect() protoreflect.Message {
+	return xxx_TestImport_protoFile_messageTypes[0].MessageOf(m)
+}
+func (m *ImportMessage) Reset()         { *m = ImportMessage{} }
+func (m *ImportMessage) String() string { return proto.CompactTextString(m) }
+func (*ImportMessage) ProtoMessage()    {}
+func (*ImportMessage) Descriptor() ([]byte, []int) {
+	return fileDescriptor_89be98e26346f54e_gzipped, []int{0}
+}
+
+func (m *ImportMessage) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_ImportMessage.Unmarshal(m, b)
+}
+func (m *ImportMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_ImportMessage.Marshal(b, m, deterministic)
+}
+func (m *ImportMessage) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_ImportMessage.Merge(m, src)
+}
+func (m *ImportMessage) XXX_Size() int {
+	return xxx_messageInfo_ImportMessage.Size(m)
+}
+func (m *ImportMessage) XXX_DiscardUnknown() {
+	xxx_messageInfo_ImportMessage.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_ImportMessage proto.InternalMessageInfo
+
+func init() {
+	proto.RegisterFile("test_import.proto", fileDescriptor_89be98e26346f54e_gzipped)
+	proto.RegisterEnum("goproto.proto.test.ImportEnum", ImportEnum_name, ImportEnum_value)
+	proto.RegisterType((*ImportMessage)(nil), "goproto.proto.test.ImportMessage")
+}
+
+var fileDescriptor_89be98e26346f54e = []byte{
+	// 145 bytes of the wire-encoded FileDescriptorProto
+	0x0a, 0x11, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x70, 0x72,
+	0x6f, 0x74, 0x6f, 0x12, 0x12, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f,
+	0x74, 0x6f, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x22, 0x0f, 0x0a, 0x0d, 0x49, 0x6d, 0x70, 0x6f, 0x72,
+	0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a, 0x1d, 0x0a, 0x0a, 0x49, 0x6d, 0x70, 0x6f,
+	0x72, 0x74, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x0f, 0x0a, 0x0b, 0x49, 0x4d, 0x50, 0x4f, 0x52, 0x54,
+	0x5f, 0x5a, 0x45, 0x52, 0x4f, 0x10, 0x00, 0x42, 0x38, 0x5a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75,
+	0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2f, 0x70, 0x72, 0x6f,
+	0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x32, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61,
+	0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x74, 0x65, 0x73,
+	0x74,
+}
+
+var fileDescriptor_89be98e26346f54e_gzipped = func() []byte {
+	bb := new(bytes.Buffer)
+	zw, _ := gzip.NewWriterLevel(bb, gzip.NoCompression)
+	zw.Write(fileDescriptor_89be98e26346f54e)
+	zw.Close()
+	return bb.Bytes()
+}()
+
+const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+
+var TestImport_protoFile protoreflect.FileDescriptor
+
+var xxx_TestImport_protoFile_enumTypes [1]protoreflect.EnumType
+var xxx_TestImport_protoFile_messageTypes [1]protoimpl.MessageType
+var xxx_TestImport_protoFile_goTypes = []interface{}{
+	(ImportEnum)(0),       // 0: goproto.proto.test.ImportEnum
+	(*ImportMessage)(nil), // 1: goproto.proto.test.ImportMessage
+}
+var xxx_TestImport_protoFile_depIdxs = []int32{}
+
+func init() {
+	var messageTypes [1]protoreflect.MessageType
+	TestImport_protoFile = protoimpl.FileBuilder{
+		RawDescriptor:      fileDescriptor_89be98e26346f54e,
+		GoTypes:            xxx_TestImport_protoFile_goTypes,
+		DependencyIndexes:  xxx_TestImport_protoFile_depIdxs,
+		EnumOutputTypes:    xxx_TestImport_protoFile_enumTypes[:],
+		MessageOutputTypes: messageTypes[:],
+	}.Init()
+	messageGoTypes := xxx_TestImport_protoFile_goTypes[1:][:1]
+	for i, mt := range messageTypes[:] {
+		xxx_TestImport_protoFile_messageTypes[i].GoType = reflect.TypeOf(messageGoTypes[i])
+		xxx_TestImport_protoFile_messageTypes[i].PBType = mt
+	}
+	xxx_TestImport_protoFile_goTypes = nil
+	xxx_TestImport_protoFile_depIdxs = nil
+}

+ 16 - 0
internal/testprotos/test/test_import.proto

@@ -0,0 +1,16 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+syntax = "proto2";
+
+package goproto.proto.test;
+
+option go_package = "github.com/golang/protobuf/v2/internal/testprotos/test";
+
+message ImportMessage {
+}
+
+enum ImportEnum {
+ IMPORT_ZERO = 0;
+}

+ 105 - 0
internal/testprotos/test/test_public.pb.go

@@ -0,0 +1,105 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// source: test_public.proto
+
+package test
+
+import (
+	bytes "bytes"
+	gzip "compress/gzip"
+	proto "github.com/golang/protobuf/proto"
+	protoreflect "github.com/golang/protobuf/v2/reflect/protoreflect"
+	protoimpl "github.com/golang/protobuf/v2/runtime/protoimpl"
+	reflect "reflect"
+)
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the proto package it is being compiled against.
+// A compilation error at this line likely means your copy of the
+// proto package needs to be updated.
+const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
+
+type PublicImportMessage struct {
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *PublicImportMessage) ProtoReflect() protoreflect.Message {
+	return xxx_TestPublic_protoFile_messageTypes[0].MessageOf(m)
+}
+func (m *PublicImportMessage) Reset()         { *m = PublicImportMessage{} }
+func (m *PublicImportMessage) String() string { return proto.CompactTextString(m) }
+func (*PublicImportMessage) ProtoMessage()    {}
+func (*PublicImportMessage) Descriptor() ([]byte, []int) {
+	return fileDescriptor_36dd44afd5b47374_gzipped, []int{0}
+}
+
+func (m *PublicImportMessage) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_PublicImportMessage.Unmarshal(m, b)
+}
+func (m *PublicImportMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_PublicImportMessage.Marshal(b, m, deterministic)
+}
+func (m *PublicImportMessage) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_PublicImportMessage.Merge(m, src)
+}
+func (m *PublicImportMessage) XXX_Size() int {
+	return xxx_messageInfo_PublicImportMessage.Size(m)
+}
+func (m *PublicImportMessage) XXX_DiscardUnknown() {
+	xxx_messageInfo_PublicImportMessage.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_PublicImportMessage proto.InternalMessageInfo
+
+func init() {
+	proto.RegisterFile("test_public.proto", fileDescriptor_36dd44afd5b47374_gzipped)
+	proto.RegisterType((*PublicImportMessage)(nil), "goproto.proto.test.PublicImportMessage")
+}
+
+var fileDescriptor_36dd44afd5b47374 = []byte{
+	// 120 bytes of the wire-encoded FileDescriptorProto
+	0x0a, 0x11, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x2e, 0x70, 0x72,
+	0x6f, 0x74, 0x6f, 0x12, 0x12, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f,
+	0x74, 0x6f, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x22, 0x15, 0x0a, 0x13, 0x50, 0x75, 0x62, 0x6c, 0x69,
+	0x63, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x42, 0x38,
+	0x5a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c,
+	0x61, 0x6e, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x32, 0x2f,
+	0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f,
+	0x74, 0x6f, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74,
+}
+
+var fileDescriptor_36dd44afd5b47374_gzipped = func() []byte {
+	bb := new(bytes.Buffer)
+	zw, _ := gzip.NewWriterLevel(bb, gzip.NoCompression)
+	zw.Write(fileDescriptor_36dd44afd5b47374)
+	zw.Close()
+	return bb.Bytes()
+}()
+
+const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+
+var TestPublic_protoFile protoreflect.FileDescriptor
+
+var xxx_TestPublic_protoFile_messageTypes [1]protoimpl.MessageType
+var xxx_TestPublic_protoFile_goTypes = []interface{}{
+	(*PublicImportMessage)(nil), // 0: goproto.proto.test.PublicImportMessage
+}
+var xxx_TestPublic_protoFile_depIdxs = []int32{}
+
+func init() {
+	var messageTypes [1]protoreflect.MessageType
+	TestPublic_protoFile = protoimpl.FileBuilder{
+		RawDescriptor:      fileDescriptor_36dd44afd5b47374,
+		GoTypes:            xxx_TestPublic_protoFile_goTypes,
+		DependencyIndexes:  xxx_TestPublic_protoFile_depIdxs,
+		MessageOutputTypes: messageTypes[:],
+	}.Init()
+	messageGoTypes := xxx_TestPublic_protoFile_goTypes[0:][:1]
+	for i, mt := range messageTypes[:] {
+		xxx_TestPublic_protoFile_messageTypes[i].GoType = reflect.TypeOf(messageGoTypes[i])
+		xxx_TestPublic_protoFile_messageTypes[i].PBType = mt
+	}
+	xxx_TestPublic_protoFile_goTypes = nil
+	xxx_TestPublic_protoFile_depIdxs = nil
+}

+ 12 - 0
internal/testprotos/test/test_public.proto

@@ -0,0 +1,12 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+syntax = "proto2";
+
+package goproto.proto.test;
+
+option go_package = "github.com/golang/protobuf/v2/internal/testprotos/test";
+
+message PublicImportMessage {
+}

+ 105 - 0
internal/testprotos/test/test_weak.pb.go

@@ -0,0 +1,105 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// source: test_weak.proto
+
+package test
+
+import (
+	bytes "bytes"
+	gzip "compress/gzip"
+	proto "github.com/golang/protobuf/proto"
+	protoreflect "github.com/golang/protobuf/v2/reflect/protoreflect"
+	protoimpl "github.com/golang/protobuf/v2/runtime/protoimpl"
+	reflect "reflect"
+)
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the proto package it is being compiled against.
+// A compilation error at this line likely means your copy of the
+// proto package needs to be updated.
+const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
+
+type WeakImportMessage struct {
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *WeakImportMessage) ProtoReflect() protoreflect.Message {
+	return xxx_TestWeak_protoFile_messageTypes[0].MessageOf(m)
+}
+func (m *WeakImportMessage) Reset()         { *m = WeakImportMessage{} }
+func (m *WeakImportMessage) String() string { return proto.CompactTextString(m) }
+func (*WeakImportMessage) ProtoMessage()    {}
+func (*WeakImportMessage) Descriptor() ([]byte, []int) {
+	return fileDescriptor_c2b8edfebc4f71b3_gzipped, []int{0}
+}
+
+func (m *WeakImportMessage) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_WeakImportMessage.Unmarshal(m, b)
+}
+func (m *WeakImportMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_WeakImportMessage.Marshal(b, m, deterministic)
+}
+func (m *WeakImportMessage) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_WeakImportMessage.Merge(m, src)
+}
+func (m *WeakImportMessage) XXX_Size() int {
+	return xxx_messageInfo_WeakImportMessage.Size(m)
+}
+func (m *WeakImportMessage) XXX_DiscardUnknown() {
+	xxx_messageInfo_WeakImportMessage.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_WeakImportMessage proto.InternalMessageInfo
+
+func init() {
+	proto.RegisterFile("test_weak.proto", fileDescriptor_c2b8edfebc4f71b3_gzipped)
+	proto.RegisterType((*WeakImportMessage)(nil), "goproto.proto.test.WeakImportMessage")
+}
+
+var fileDescriptor_c2b8edfebc4f71b3 = []byte{
+	// 116 bytes of the wire-encoded FileDescriptorProto
+	0x0a, 0x0f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x77, 0x65, 0x61, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74,
+	0x6f, 0x12, 0x12, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
+	0x2e, 0x74, 0x65, 0x73, 0x74, 0x22, 0x13, 0x0a, 0x11, 0x57, 0x65, 0x61, 0x6b, 0x49, 0x6d, 0x70,
+	0x6f, 0x72, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x42, 0x38, 0x5a, 0x36, 0x67, 0x69,
+	0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2f,
+	0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x32, 0x2f, 0x69, 0x6e, 0x74, 0x65,
+	0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f,
+	0x74, 0x65, 0x73, 0x74,
+}
+
+var fileDescriptor_c2b8edfebc4f71b3_gzipped = func() []byte {
+	bb := new(bytes.Buffer)
+	zw, _ := gzip.NewWriterLevel(bb, gzip.NoCompression)
+	zw.Write(fileDescriptor_c2b8edfebc4f71b3)
+	zw.Close()
+	return bb.Bytes()
+}()
+
+const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+
+var TestWeak_protoFile protoreflect.FileDescriptor
+
+var xxx_TestWeak_protoFile_messageTypes [1]protoimpl.MessageType
+var xxx_TestWeak_protoFile_goTypes = []interface{}{
+	(*WeakImportMessage)(nil), // 0: goproto.proto.test.WeakImportMessage
+}
+var xxx_TestWeak_protoFile_depIdxs = []int32{}
+
+func init() {
+	var messageTypes [1]protoreflect.MessageType
+	TestWeak_protoFile = protoimpl.FileBuilder{
+		RawDescriptor:      fileDescriptor_c2b8edfebc4f71b3,
+		GoTypes:            xxx_TestWeak_protoFile_goTypes,
+		DependencyIndexes:  xxx_TestWeak_protoFile_depIdxs,
+		MessageOutputTypes: messageTypes[:],
+	}.Init()
+	messageGoTypes := xxx_TestWeak_protoFile_goTypes[0:][:1]
+	for i, mt := range messageTypes[:] {
+		xxx_TestWeak_protoFile_messageTypes[i].GoType = reflect.TypeOf(messageGoTypes[i])
+		xxx_TestWeak_protoFile_messageTypes[i].PBType = mt
+	}
+	xxx_TestWeak_protoFile_goTypes = nil
+	xxx_TestWeak_protoFile_depIdxs = nil
+}

+ 12 - 0
internal/testprotos/test/test_weak.proto

@@ -0,0 +1,12 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+syntax = "proto2";
+
+package goproto.proto.test;
+
+option go_package = "github.com/golang/protobuf/v2/internal/testprotos/test";
+
+message WeakImportMessage {
+}

+ 10 - 1
regenerate.bash

@@ -18,14 +18,23 @@ GOBIN=$tmpdir/bin go install ./cmd/protoc-gen-go-grpc
 # Generate various test protos.
 PROTO_DIRS=(
   cmd/protoc-gen-go/testdata
-  cmd/protoc-gen-go-grpc/testdata
   internal/testprotos/test
 )
+GRPC_PROTO_DIRS=(
+  cmd/protoc-gen-go-grpc/testdata
+)
 for dir in ${PROTO_DIRS[@]}; do
   for p in `find $dir -name "*.proto"`; do
     echo "# $p"
     PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc -I$dir \
       --go_out=paths=source_relative:$dir \
+      $p
+  done
+done
+for dir in ${GRPC_PROTO_DIRS[@]}; do
+  for p in `find $dir -name "*.proto"`; do
+    echo "# $p"
+    PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc -I$dir \
       --go-grpc_out=paths=source_relative:$dir \
       $p
   done

Некоторые файлы не были показаны из-за большого количества измененных файлов