-
Notifications
You must be signed in to change notification settings - Fork 168
/
linker_test.go
1353 lines (1316 loc) · 45.8 KB
/
linker_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package protoparse
import (
"errors"
"fmt"
"io"
"io/ioutil"
"strings"
"testing"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
dpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/jhump/protoreflect/desc"
_ "github.com/jhump/protoreflect/internal/testprotos"
"github.com/jhump/protoreflect/internal/testutil"
)
func TestSimpleLink(t *testing.T) {
fds, err := Parser{ImportPaths: []string{"../../internal/testprotos"}}.ParseFiles("desc_test_complex.proto")
testutil.Ok(t, err)
b, err := ioutil.ReadFile("../../internal/testprotos/desc_test_complex.protoset")
testutil.Ok(t, err)
var files dpb.FileDescriptorSet
err = proto.Unmarshal(b, &files)
testutil.Ok(t, err)
testutil.Require(t, proto.Equal(files.File[0], fds[0].AsProto()), "linked descriptor did not match output from protoc:\nwanted: %s\ngot: %s", toString(files.File[0]), toString(fds[0].AsProto()))
}
func TestMultiFileLink(t *testing.T) {
for _, name := range []string{"desc_test2.proto", "desc_test_defaults.proto", "desc_test_field_types.proto", "desc_test_options.proto", "desc_test_proto3.proto", "desc_test_wellknowntypes.proto"} {
fds, err := Parser{ImportPaths: []string{"../../internal/testprotos"}}.ParseFiles(name)
testutil.Ok(t, err)
exp, err := desc.LoadFileDescriptor(name)
testutil.Ok(t, err)
checkFiles(t, fds[0], exp, map[string]struct{}{})
}
}
func TestProto3Optional(t *testing.T) {
data, err := ioutil.ReadFile("../../internal/testprotos/proto3_optional/desc_test_proto3_optional.protoset")
testutil.Ok(t, err)
var fdset dpb.FileDescriptorSet
err = proto.Unmarshal(data, &fdset)
testutil.Ok(t, err)
var descriptorProto *dpb.FileDescriptorProto
for _, fd := range fdset.File {
// not comparing source code info
fd.SourceCodeInfo = nil
// we want to use the same descriptor.proto as in protoset, so we don't have to
// worry about this test breaking when updating to newer versions of the Go
// descriptor package (which may have a different version of descriptor.proto
// compiled in).
if fd.GetName() == "google/protobuf/descriptor.proto" {
descriptorProto = fd
}
}
testutil.Require(t, descriptorProto != nil, "failed to find google/protobuf/descriptor.proto in protoset")
exp, err := desc.CreateFileDescriptorFromSet(&fdset)
testutil.Ok(t, err)
fds, err := Parser{
ImportPaths: []string{"../../internal/testprotos"},
LookupImportProto: func(name string) (*dpb.FileDescriptorProto, error) {
if name == "google/protobuf/descriptor.proto" {
return descriptorProto, nil
}
return nil, errors.New("not found")
},
}.ParseFiles("proto3_optional/desc_test_proto3_optional.proto")
testutil.Ok(t, err)
checkFiles(t, fds[0], exp, map[string]struct{}{})
}
func checkFiles(t *testing.T, act, exp *desc.FileDescriptor, checked map[string]struct{}) {
if _, ok := checked[act.GetName()]; ok {
// already checked
return
}
checked[act.GetName()] = struct{}{}
// remove any source code info from expected value, since actual won't have any
exp.AsFileDescriptorProto().SourceCodeInfo = nil
testutil.Require(t, proto.Equal(exp.AsFileDescriptorProto(), act.AsProto()), "linked descriptor did not match output from protoc:\nwanted: %s\ngot: %s", toString(exp.AsProto()), toString(act.AsProto()))
for i, dep := range act.GetDependencies() {
checkFiles(t, dep, exp.GetDependencies()[i], checked)
}
}
func toString(m proto.Message) string {
msh := jsonpb.Marshaler{Indent: " "}
s, err := msh.MarshalToString(m)
if err != nil {
panic(err)
}
return s
}
func TestLinkerValidation(t *testing.T) {
testCases := []struct {
input map[string]string
errMsg string
}{
{
map[string]string{
"foo.proto": `syntax = "proto3"; package namespace.a; import "foo2.proto"; import "foo3.proto"; import "foo4.proto"; message Foo{ b.Bar a = 1; b.Baz b = 2; b.Buzz c = 3; }`,
"foo2.proto": `syntax = "proto3"; package namespace.b; message Bar{}`,
"foo3.proto": `syntax = "proto3"; package namespace.b; message Baz{}`,
"foo4.proto": `syntax = "proto3"; package namespace.b; message Buzz{}`,
},
"", // should succeed
},
{
map[string]string{
"foo.proto": "import \"foo2.proto\"; message fubar{}",
},
`foo.proto:1:8: file not found: foo2.proto`,
},
{
map[string]string{
"foo.proto": "import \"foo2.proto\"; message fubar{}",
"foo2.proto": "import \"foo.proto\"; message baz{}",
},
`foo.proto:1:8: cycle found in imports: "foo.proto" -> "foo2.proto" -> "foo.proto"`,
},
{
map[string]string{
"foo.proto": "enum foo { bar = 1; baz = 2; } enum fu { bar = 1; baz = 2; }",
},
`foo.proto:1:42: duplicate symbol bar: already defined as an enum value; protobuf uses C++ scoping rules for enum values, so they exist in the scope enclosing the enum`,
},
{
map[string]string{
"foo.proto": "message foo {} enum foo { V = 0; }",
},
"foo.proto:1:16: duplicate symbol foo: already defined as a message",
},
{
map[string]string{
"foo.proto": "message foo { optional string a = 1; optional string a = 2; }",
},
"foo.proto:1:38: duplicate symbol foo.a: already defined as a field",
},
{
map[string]string{
"foo.proto": "message foo {}",
"foo2.proto": "enum foo { V = 0; }",
},
"foo2.proto:1:1: duplicate symbol foo: already defined as a message in \"foo.proto\"",
},
{
map[string]string{
"foo.proto": "message foo { optional blah a = 1; }",
},
"foo.proto:1:24: field foo.a: unknown type blah",
},
{
map[string]string{
"foo.proto": "message foo { optional bar.baz a = 1; } service bar { rpc baz (foo) returns (foo); }",
},
"foo.proto:1:24: field foo.a: invalid type: bar.baz is a method, not a message or enum",
},
{
map[string]string{
"foo.proto": "message foo { extensions 1 to 2; } extend foo { optional string a = 1; } extend foo { optional int32 b = 1; }",
},
"foo.proto:1:106: field b: duplicate extension: a and b are both using tag 1",
},
{
map[string]string{
"foo.proto": `
syntax = "proto3";
import "google/protobuf/descriptor.proto";
package google.protobuf;
message DescriptorProto { }
`,
},
`google/protobuf/descriptor.proto: duplicate symbol google.protobuf.DescriptorProto: already defined as a message in "foo.proto"`,
},
{
map[string]string{
"foo.proto": "package fu.baz; extend foobar { optional string a = 1; }",
},
"foo.proto:1:24: unknown extendee type foobar",
},
{
map[string]string{
"foo.proto": "package fu.baz; service foobar{} extend foobar { optional string a = 1; }",
},
"foo.proto:1:41: extendee is invalid: fu.baz.foobar is a service, not a message",
},
{
map[string]string{
"foo.proto": "message foo{} message bar{} service foobar{ rpc foo(foo) returns (bar); }",
},
"foo.proto:1:53: method foobar.foo: invalid request type: foobar.foo is a method, not a message",
},
{
map[string]string{
"foo.proto": "message foo{} message bar{} service foobar{ rpc foo(bar) returns (foo); }",
},
"foo.proto:1:67: method foobar.foo: invalid response type: foobar.foo is a method, not a message",
},
{
map[string]string{
"foo.proto": "package fu.baz; message foobar{ extensions 1; } extend foobar { optional string a = 2; }",
},
"foo.proto:1:85: field fu.baz.a: tag 2 is not in valid range for extended type fu.baz.foobar",
},
{
map[string]string{
"foo.proto": "package fu.baz; import public \"foo2.proto\"; message foobar{ optional baz a = 1; }",
"foo2.proto": "package fu.baz; import \"foo3.proto\"; message fizzle{ }",
"foo3.proto": "package fu.baz; message baz{ }",
},
"foo.proto:1:70: field fu.baz.foobar.a: unknown type baz; resolved to fu.baz which is not defined; consider using a leading dot",
},
{
map[string]string{
"foo.proto": `
syntax = "proto2";
package foo;
import "google/protobuf/descriptor.proto";
extend google.protobuf.FileOptions { optional string fil_foo = 12000; }
extend google.protobuf.MessageOptions { optional string msg_foo = 12000; }
extend google.protobuf.FieldOptions { optional string fld_foo = 12000 [(fld_foo) = "extension"]; }
extend google.protobuf.OneofOptions { optional string oof_foo = 12000; }
extend google.protobuf.EnumOptions { optional string enm_foo = 12000; }
extend google.protobuf.EnumValueOptions { optional string env_foo = 12000; }
extend google.protobuf.ExtensionRangeOptions { optional string ext_foo = 12000; }
extend google.protobuf.ServiceOptions { optional string svc_foo = 12000; }
extend google.protobuf.MethodOptions { optional string mtd_foo = 12000; }
option (fil_foo) = "file";
message Foo {
option (msg_foo) = "message";
oneof foo {
option (oof_foo) = "oneof";
string bar = 1 [(fld_foo) = "field"];
}
extensions 100 to 200 [(ext_foo) = "extensionrange"];
}
enum Baz {
option (enm_foo) = "enum";
ZERO = 0 [(env_foo) = "enumvalue"];
}
service FooService {
option (svc_foo) = "service";
rpc Bar(Foo) returns (Foo) {
option (mtd_foo) = "method";
}
}
`,
},
"", // should success
},
{
map[string]string{
"foo.proto": "package fu.baz; message foobar{ repeated string a = 1 [default = \"abc\"]; }",
},
"foo.proto:1:56: field fu.baz.foobar.a: default value cannot be set because field is repeated",
},
{
map[string]string{
"foo.proto": "package fu.baz; message foobar{ optional foobar a = 1 [default = { a: {} }]; }",
},
"foo.proto:1:56: field fu.baz.foobar.a: default value cannot be set because field is a message",
},
{
map[string]string{
"foo.proto": "package fu.baz; message foobar{ optional string a = 1 [default = { a: \"abc\" }]; }",
},
"foo.proto:1:66: field fu.baz.foobar.a: default value cannot be a message",
},
{
map[string]string{
"foo.proto": "package fu.baz; message foobar{ optional string a = 1 [default = 1.234]; }",
},
"foo.proto:1:66: field fu.baz.foobar.a: option default: expecting string, got double",
},
{
map[string]string{
"foo.proto": "package fu.baz; enum abc { OK=0; NOK=1; } message foobar{ optional abc a = 1 [default = NACK]; }",
},
"foo.proto:1:89: field fu.baz.foobar.a: option default: enum fu.baz.abc has no value named NACK",
},
{
map[string]string{
"foo.proto": "option b = 123;",
},
"foo.proto:1:8: option b: field b of google.protobuf.FileOptions does not exist",
},
{
map[string]string{
"foo.proto": "option (foo.bar) = 123;",
},
"foo.proto:1:8: unknown extension foo.bar",
},
{
map[string]string{
"foo.proto": "option uninterpreted_option = { };",
},
"foo.proto:1:8: invalid option 'uninterpreted_option'",
},
{
map[string]string{
"foo.proto": "import \"google/protobuf/descriptor.proto\";\n" +
"message foo { optional string a = 1; extensions 10 to 20; }\n" +
"extend foo { optional int32 b = 10; }\n" +
"extend google.protobuf.FileOptions { optional foo f = 20000; }\n" +
"option (f).b = 123;",
},
"foo.proto:5:12: option (f).b: field b of foo does not exist",
},
{
map[string]string{
"foo.proto": "import \"google/protobuf/descriptor.proto\";\n" +
"message foo { optional string a = 1; extensions 10 to 20; }\n" +
"extend foo { optional int32 b = 10; }\n" +
"extend google.protobuf.FileOptions { optional foo f = 20000; }\n" +
"option (f).a = 123;",
},
"foo.proto:5:16: option (f).a: expecting string, got integer",
},
{
map[string]string{
"foo.proto": "import \"google/protobuf/descriptor.proto\";\n" +
"message foo { optional string a = 1; extensions 10 to 20; }\n" +
"extend foo { optional int32 b = 10; }\n" +
"extend google.protobuf.FileOptions { optional foo f = 20000; }\n" +
"option (b) = 123;",
},
"foo.proto:5:8: option (b): extension b should extend google.protobuf.FileOptions but instead extends foo",
},
{
map[string]string{
"foo.proto": "import \"google/protobuf/descriptor.proto\";\n" +
"message foo { optional string a = 1; extensions 10 to 20; }\n" +
"extend foo { optional int32 b = 10; }\n" +
"extend google.protobuf.FileOptions { optional foo f = 20000; }\n" +
"option (foo) = 123;",
},
"foo.proto:5:8: invalid extension: foo is a message, not an extension",
},
{
map[string]string{
"foo.proto": "import \"google/protobuf/descriptor.proto\";\n" +
"message foo { optional string a = 1; extensions 10 to 20; }\n" +
"extend foo { optional int32 b = 10; }\n" +
"extend google.protobuf.FileOptions { optional foo f = 20000; }\n" +
"option (foo.a) = 123;",
},
"foo.proto:5:8: invalid extension: foo.a is a field but not an extension",
},
{
map[string]string{
"foo.proto": "import \"google/protobuf/descriptor.proto\";\n" +
"message foo { optional string a = 1; extensions 10 to 20; }\n" +
"extend foo { optional int32 b = 10; }\n" +
"extend google.protobuf.FileOptions { optional foo f = 20000; }\n" +
"option (f) = { a: [ 123 ] };",
},
"foo.proto:5:19: option (f): value is an array but field is not repeated",
},
{
map[string]string{
"foo.proto": "import \"google/protobuf/descriptor.proto\";\n" +
"message foo { repeated string a = 1; extensions 10 to 20; }\n" +
"extend foo { optional int32 b = 10; }\n" +
"extend google.protobuf.FileOptions { optional foo f = 20000; }\n" +
"option (f) = { a: [ \"a\", \"b\", 123 ] };",
},
"foo.proto:5:31: option (f): expecting string, got integer",
},
{
map[string]string{
"foo.proto": "import \"google/protobuf/descriptor.proto\";\n" +
"message foo { optional string a = 1; extensions 10 to 20; }\n" +
"extend foo { optional int32 b = 10; }\n" +
"extend google.protobuf.FileOptions { optional foo f = 20000; }\n" +
"option (f) = { a: \"a\" };\n" +
"option (f) = { a: \"b\" };",
},
"foo.proto:6:8: option (f): non-repeated option field f already set",
},
{
map[string]string{
"foo.proto": "import \"google/protobuf/descriptor.proto\";\n" +
"message foo { optional string a = 1; extensions 10 to 20; }\n" +
"extend foo { optional int32 b = 10; }\n" +
"extend google.protobuf.FileOptions { optional foo f = 20000; }\n" +
"option (f) = { a: \"a\" };\n" +
"option (f).a = \"b\";",
},
"foo.proto:6:12: option (f).a: non-repeated option field a already set",
},
{
map[string]string{
"foo.proto": "import \"google/protobuf/descriptor.proto\";\n" +
"message foo { optional string a = 1; extensions 10 to 20; }\n" +
"extend foo { optional int32 b = 10; }\n" +
"extend google.protobuf.FileOptions { optional foo f = 20000; }\n" +
"option (f) = { a: \"a\" };\n" +
"option (f).(b) = \"b\";",
},
"foo.proto:6:18: option (f).(b): expecting int32, got string",
},
{
map[string]string{
"foo.proto": "import \"google/protobuf/descriptor.proto\";\n" +
"message foo { required string a = 1; required string b = 2; }\n" +
"extend google.protobuf.FileOptions { optional foo f = 20000; }\n" +
"option (f) = { a: \"a\" };\n",
},
"foo.proto:1:1: error in file options: some required fields missing: (f).b",
},
{
map[string]string{
"foo.proto": "message Foo { option message_set_wire_format = true; extensions 1 to 100; } extend Foo { optional int32 bar = 1; }",
},
"foo.proto:1:99: messages with message-set wire format cannot contain scalar extensions, only messages",
},
{
map[string]string{
"foo.proto": "message Foo { option message_set_wire_format = true; extensions 1 to 100; } extend Foo { optional Foo bar = 1; }",
},
"", // should succeed
},
{
map[string]string{
"foo.proto": "message Foo { option message_set_wire_format = true; extensions 1 to 100; } extend Foo { repeated Foo bar = 1; }",
},
"foo.proto:1:90: messages with message-set wire format cannot contain repeated extensions, only optional",
},
{
map[string]string{
"foo.proto": "message Foo { extensions 1 to max; } extend Foo { optional int32 bar = 536870912; }",
},
"foo.proto:1:72: field bar: tag 536870912 is not in valid range for extended type Foo",
},
{
map[string]string{
"foo.proto": "message Foo { option message_set_wire_format = true; extensions 1 to max; } extend Foo { optional Foo bar = 536870912; }",
},
"", // should succeed
},
{
map[string]string{
"foo.proto": `syntax = "proto3"; package com.google; import "google/protobuf/wrappers.proto"; message Foo { google.protobuf.StringValue str = 1; }`,
},
"foo.proto:1:95: field com.google.Foo.str: unknown type google.protobuf.StringValue; resolved to com.google.protobuf.StringValue which is not defined; consider using a leading dot",
},
{
map[string]string{
"foo.proto": "syntax = \"proto2\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo {\n" +
" optional group Bar = 1 { optional string name = 1; }\n" +
"}\n" +
"extend google.protobuf.MessageOptions { optional Foo foo = 10001; }\n" +
"message Baz { option (foo).bar.name = \"abc\"; }\n",
},
"", // should succeed
},
{
map[string]string{
"foo.proto": "syntax = \"proto2\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo {\n" +
" optional group Bar = 1 { optional string name = 1; }\n" +
"}\n" +
"extend google.protobuf.MessageOptions { optional Foo foo = 10001; }\n" +
"message Baz { option (foo).Bar.name = \"abc\"; }\n",
},
"foo.proto:7:28: message Baz: option (foo).Bar.name: field Bar of Foo does not exist",
},
{
map[string]string{
"foo.proto": "syntax = \"proto2\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"extend google.protobuf.MessageOptions {\n" +
" optional group Foo = 10001 { optional string name = 1; }\n" +
"}\n" +
"message Bar { option (foo).name = \"abc\"; }\n",
},
"", // should succeed
},
{
map[string]string{
"foo.proto": "syntax = \"proto2\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"extend google.protobuf.MessageOptions {\n" +
" optional group Foo = 10001 { optional string name = 1; }\n" +
"}\n" +
"message Bar { option (Foo).name = \"abc\"; }\n",
},
"foo.proto:6:22: message Bar: invalid extension: Foo is a message, not an extension",
},
{
map[string]string{
"foo.proto": "syntax = \"proto2\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo {\n" +
" optional group Bar = 1 { optional string name = 1; }\n" +
"}\n" +
"extend google.protobuf.MessageOptions { optional Foo foo = 10001; }\n" +
"message Baz { option (foo) = { Bar< name: \"abc\" > }; }\n",
},
"", // should succeed
},
{
map[string]string{
"foo.proto": "syntax = \"proto2\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo {\n" +
" optional group Bar = 1 { optional string name = 1; }\n" +
"}\n" +
"extend google.protobuf.MessageOptions { optional Foo foo = 10001; }\n" +
"message Baz { option (foo) = { bar< name: \"abc\" > }; }\n",
},
"foo.proto:7:32: message Baz: option (foo): field bar not found (did you mean the group named Bar?)",
},
{
map[string]string{
"foo.proto": "syntax = \"proto2\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { extensions 1 to 10; }\n" +
"extend Foo { optional group Bar = 10 { optional string name = 1; } }\n" +
"extend google.protobuf.MessageOptions { optional Foo foo = 10001; }\n" +
"message Baz { option (foo) = { [bar]< name: \"abc\" > }; }\n",
},
"", // should succeed
},
{
map[string]string{
"foo.proto": "syntax = \"proto2\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { extensions 1 to 10; }\n" +
"extend Foo { optional group Bar = 10 { optional string name = 1; } }\n" +
"extend google.protobuf.MessageOptions { optional Foo foo = 10001; }\n" +
"message Baz { option (foo) = { [Bar]< name: \"abc\" > }; }\n",
},
"foo.proto:6:33: message Baz: option (foo): invalid extension: Bar is a message, not an extension",
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { oneof bar { string baz = 1; string buzz = 2; } }\n" +
"extend google.protobuf.MessageOptions { optional Foo foo = 10001; }\n" +
"message Baz { option (foo) = { baz: \"abc\" buzz: \"xyz\" }; }\n",
},
`foo.proto:5:43: message Baz: option (foo): oneof "bar" already has field "baz" set`,
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { oneof bar { string baz = 1; string buzz = 2; } }\n" +
"extend google.protobuf.MessageOptions { optional Foo foo = 10001; }\n" +
"message Baz {\n" +
" option (foo).baz = \"abc\";\n" +
" option (foo).buzz = \"xyz\";\n" +
"}",
},
`foo.proto:7:16: message Baz: option (foo).buzz: oneof "bar" already has field "baz" set`,
},
{
map[string]string{
"a.proto": "syntax = \"proto3\";\n" +
"message m{\n" +
" oneof z{\n" +
" int64 z=1;\n" +
" }\n" +
"}",
},
`a.proto:4:5: duplicate symbol m.z: already defined as a oneof`,
},
{
map[string]string{
"a.proto": "syntax=\"proto3\";\n" +
"message m{\n" +
" string z = 1;\n" +
" oneof z{int64 b=2;}\n" +
"}",
},
`a.proto:3:3: duplicate symbol m.z: already defined as a oneof`,
},
{
map[string]string{
"test.proto": "syntax=\"proto2\";\n" +
"package foo.bar;\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message a { extensions 1 to 100; }\n" +
"extend google.protobuf.MessageOptions { optional a msga = 10000; }\n" +
"message b {\n" +
" message c {\n" +
" extend a { repeated int32 i = 1; repeated float f = 2; }\n" +
" }\n" +
" option (msga) = {\n" +
" [foo.bar.b.c.i]: 123\n" +
" [bar.b.c.i]: 234\n" +
" [b.c.i]: 345\n" +
" };\n" +
" option (msga).(foo.bar.b.c.f) = 1.23;\n" +
" option (msga).(bar.b.c.f) = 2.34;\n" +
" option (msga).(b.c.f) = 3.45;\n" +
"}",
},
"", // should succeed
},
{
map[string]string{
"test.proto": "syntax=\"proto2\";\n" +
"package foo.bar;\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message a { extensions 1 to 100; }\n" +
"message b { extensions 1 to 100; }\n" +
"extend google.protobuf.MessageOptions { optional a msga = 10000; }\n" +
"message c {\n" +
" extend a { optional b b = 1; }\n" +
" extend b { repeated int32 i = 1; repeated float f = 2; }\n" +
" option (msga) = {\n" +
" [foo.bar.c.b] {\n" +
" [foo.bar.c.i]: 123\n" +
" [bar.c.i]: 234\n" +
" [c.i]: 345\n" +
" }\n" +
" };\n" +
" option (msga).(foo.bar.c.b).(foo.bar.c.f) = 1.23;\n" +
" option (msga).(foo.bar.c.b).(bar.c.f) = 2.34;\n" +
" option (msga).(foo.bar.c.b).(c.f) = 3.45;\n" +
"}",
},
"", // should succeed
},
{
map[string]string{
"test.proto": "syntax=\"proto2\";\n" +
"package foo.bar;\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message a { extensions 1 to 100; }\n" +
"extend google.protobuf.MessageOptions { optional a msga = 10000; }\n" +
"message b {\n" +
" message c {\n" +
" extend a { repeated int32 i = 1; repeated float f = 2; }\n" +
" }\n" +
" option (msga) = {\n" +
" [c.i]: 456\n" +
" };\n" +
"}",
},
"test.proto:11:6: message foo.bar.b: option (foo.bar.msga): unknown extension c.i",
},
{
map[string]string{
"test.proto": "syntax=\"proto2\";\n" +
"package foo.bar;\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message a { extensions 1 to 100; }\n" +
"extend google.protobuf.MessageOptions { optional a msga = 10000; }\n" +
"message b {\n" +
" message c {\n" +
" extend a { repeated int32 i = 1; repeated float f = 2; }\n" +
" }\n" +
" option (msga) = {\n" +
" [i]: 567\n" +
" };\n" +
"}",
},
"test.proto:11:6: message foo.bar.b: option (foo.bar.msga): unknown extension i",
},
{
map[string]string{
"test.proto": "syntax=\"proto2\";\n" +
"package foo.bar;\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message a { extensions 1 to 100; }\n" +
"extend google.protobuf.MessageOptions { optional a msga = 10000; }\n" +
"message b {\n" +
" message c {\n" +
" extend a { repeated int32 i = 1; repeated float f = 2; }\n" +
" }\n" +
" option (msga).(c.f) = 4.56;\n" +
"}",
},
"test.proto:10:17: message foo.bar.b: unknown extension c.f",
},
{
map[string]string{
"test.proto": "syntax=\"proto2\";\n" +
"package foo.bar;\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message a { extensions 1 to 100; }\n" +
"extend google.protobuf.MessageOptions { optional a msga = 10000; }\n" +
"message b {\n" +
" message c {\n" +
" extend a { repeated int32 i = 1; repeated float f = 2; }\n" +
" }\n" +
" option (msga).(f) = 5.67;\n" +
"}",
},
"test.proto:10:17: message foo.bar.b: unknown extension f",
},
{
map[string]string{
"a.proto": "syntax=\"proto3\";\nmessage m{\n" +
" oneof z{int64 a=1;}\n" +
" oneof z{int64 b=2;}\n" +
"}",
},
`a.proto:4:3: duplicate symbol m.z: already defined as a oneof`,
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { oneof bar { google.protobuf.DescriptorProto baz = 1; google.protobuf.DescriptorProto buzz = 2; } }\n" +
"extend google.protobuf.MessageOptions { optional Foo foo = 10001; }\n" +
"message Baz {\n" +
" option (foo).baz.name = \"abc\";\n" +
" option (foo).buzz.name = \"xyz\";\n" +
"}",
},
`foo.proto:7:16: message Baz: option (foo).buzz.name: oneof "bar" already has field "baz" set`,
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { oneof bar { google.protobuf.DescriptorProto baz = 1; google.protobuf.DescriptorProto buzz = 2; } }\n" +
"extend google.protobuf.MessageOptions { optional Foo foo = 10001; }\n" +
"message Baz {\n" +
" option (foo).baz.options.(foo).baz.name = \"abc\";\n" +
" option (foo).baz.options.(foo).buzz.name = \"xyz\";\n" +
"}",
},
`foo.proto:7:34: message Baz: option (foo).baz.options.(foo).buzz.name: oneof "bar" already has field "baz" set`,
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"enum Foo { true = 0; false = 1; t = 2; f = 3; True = 4; False = 5; inf = 6; nan = 7; }\n" +
"extend google.protobuf.MessageOptions { repeated Foo foo = 10001; }\n" +
"message Baz {\n" +
" option (foo) = true; option (foo) = false;\n" +
" option (foo) = t; option (foo) = f;\n" +
" option (foo) = True; option (foo) = False;\n" +
" option (foo) = inf; option (foo) = nan;\n" +
"}\n",
},
"", // should succeed
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"extend google.protobuf.MessageOptions { repeated bool foo = 10001; }\n" +
"message Baz {\n" +
" option (foo) = true; option (foo) = false;\n" +
" option (foo) = t; option (foo) = f;\n" +
" option (foo) = True; option (foo) = False;\n" +
"}\n",
},
"foo.proto:6:18: message Baz: option (foo): expecting bool, got identifier",
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { repeated bool b = 1; }\n" +
"extend google.protobuf.MessageOptions { Foo foo = 10001; }\n" +
"message Baz {\n" +
" option (foo) = {\n" +
" b: t b: f\n" +
" b: true b: false\n" +
" b: True b: False\n" +
" };\n" +
"}\n",
},
"", // should succeed
},
{
map[string]string{
"foo.proto": "syntax = \"proto2\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { extensions 1 to 10; }\n" +
"extend Foo { optional bool b = 10; }\n" +
"extend google.protobuf.MessageOptions { optional Foo foo = 10001; }\n" +
"message Baz {\n" +
" option (foo) = {\n" +
" [.b]: true\n" +
" };\n" +
"}\n",
},
"foo.proto:8:6: syntax error: unexpected '.'",
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"package foo.bar;\n" +
"import \"google/protobuf/any.proto\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { string a = 1; int32 b = 2; }\n" +
"extend google.protobuf.MessageOptions { optional google.protobuf.Any any = 10001; }\n" +
"message Baz {\n" +
" option (any) = {\n" +
" [type.googleapis.com/foo.bar.Foo] <\n" +
" a: \"abc\"\n" +
" b: 123\n" +
" >\n" +
" };\n" +
"}\n",
},
"", // should succeed
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"package foo.bar;\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { string a = 1; int32 b = 2; }\n" +
"extend google.protobuf.MessageOptions { optional Foo f = 10001; }\n" +
"message Baz {\n" +
" option (f) = {\n" +
" [type.googleapis.com/foo.bar.Foo] <\n" +
" a: \"abc\"\n" +
" b: 123\n" +
" >\n" +
" };\n" +
"}\n",
},
"foo.proto:8:6: message foo.bar.Baz: option (foo.bar.f): type references are only allowed for google.protobuf.Any, but this type is foo.bar.Foo",
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"package foo.bar;\n" +
"import \"google/protobuf/any.proto\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { string a = 1; int32 b = 2; }\n" +
"extend google.protobuf.MessageOptions { optional google.protobuf.Any any = 10001; }\n" +
"message Baz {\n" +
" option (any) = {\n" +
" [types.custom.io/foo.bar.Foo] <\n" +
" a: \"abc\"\n" +
" b: 123\n" +
" >\n" +
" };\n" +
"}\n",
},
"foo.proto:9:6: message foo.bar.Baz: option (foo.bar.any): could not resolve type reference types.custom.io/foo.bar.Foo",
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"package foo.bar;\n" +
"import \"google/protobuf/any.proto\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { string a = 1; int32 b = 2; }\n" +
"extend google.protobuf.MessageOptions { optional google.protobuf.Any any = 10001; }\n" +
"message Baz {\n" +
" option (any) = {\n" +
" [type.googleapis.com/foo.bar.Foo]: 123\n" +
" };\n" +
"}\n",
},
"foo.proto:9:40: message foo.bar.Baz: option (foo.bar.any): type references for google.protobuf.Any must have message literal value",
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"package foo.bar;\n" +
"import \"google/protobuf/any.proto\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo { string a = 1; int32 b = 2; }\n" +
"extend google.protobuf.MessageOptions { optional google.protobuf.Any any = 10001; }\n" +
"message Baz {\n" +
" option (any) = {\n" +
" [type.googleapis.com/Foo] <\n" +
" a: \"abc\"\n" +
" b: 123\n" +
" >\n" +
" };\n" +
"}\n",
},
"foo.proto:9:6: message foo.bar.Baz: option (foo.bar.any): could not resolve type reference type.googleapis.com/Foo",
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"extend google.protobuf.MessageOptions {\n" +
" string foobar = 10001 [json_name=\"FooBar\"];\n" +
"}\n",
},
"foo.proto:4:26: field foobar: option json_name is not allowed on extensions",
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"package foo.foo;\n" +
"import \"other.proto\";\n" +
"service Foo { rpc Bar (Baz) returns (Baz); }\n" +
"message Baz {\n" +
" foo.Foo.Bar f = 1;\n" +
"}\n",
"other.proto": "syntax = \"proto3\";\n" +
"package foo;\n" +
"message Foo {\n" +
" enum Bar { ZED = 0; }\n" +
"}\n",
},
"foo.proto:6:3: field foo.foo.Baz.f: invalid type: foo.foo.Foo.Bar is a method, not a message or enum",
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"message Foo {\n" +
" enum Bar { ZED = 0; }\n" +
" message Foo {\n" +
" extend google.protobuf.MessageOptions {\n" +
" string Bar = 30000;\n" +
" }\n" +
" Foo.Bar f = 1;\n" +
" }\n" +
"}\n",
},
"foo.proto:9:5: field Foo.Foo.f: invalid type: Foo.Foo.Bar is an extension, not a message or enum",
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"extend google.protobuf.ServiceOptions {\n" +
" string Bar = 30000;\n" +
"}\n" +
"message Empty {}\n" +
"service Foo {\n" +
" option (Bar) = \"blah\";\n" +
" rpc Bar (Empty) returns (Empty);\n" +
"}\n",
},
"", // should succeed
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"extend google.protobuf.MethodOptions {\n" +
" string Bar = 30000;\n" +
"}\n" +
"message Empty {}\n" +
"service Foo {\n" +
" rpc Bar (Empty) returns (Empty) { option (Bar) = \"blah\"; }\n" +
"}\n",
},
"foo.proto:8:44: method Foo.Bar: invalid extension: Bar is a method, not an extension",
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"import \"google/protobuf/descriptor.proto\";\n" +
"enum Bar { ZED = 0; }\n" +
"message Foo {\n" +
" extend google.protobuf.MessageOptions {\n" +
" string Bar = 30000;\n" +
" }\n" +
" message Foo {\n" +
" Bar f = 1;\n" +
" }\n" +
"}\n",
},
"", // should succeed
},
{
map[string]string{
"foo.proto": "syntax = \"proto3\";\n" +
"message Foo {\n" +
" map<string,string> bar = 1;\n" +
"}\n" +
"message Baz {\n" +
" Foo.BarEntry e = 1;\n" +
"}\n",
},
"foo.proto:6:3: field Baz.e: Foo.BarEntry is a synthetic map entry and may not be referenced explicitly",
},
{
map[string]string{