@@ -3151,6 +3151,105 @@ TEST_F(CommandLineInterfaceTest, WriteTransitiveOptionImportDescriptorSet) {
3151
3151
EXPECT_EQ (" bar.proto" , descriptor_set.file (3 ).name ());
3152
3152
}
3153
3153
3154
+ TEST_F (CommandLineInterfaceTest, OptionImportWithDebugRedactFieldIsNotError) {
3155
+ CreateTempFile (" google/protobuf/descriptor.proto" ,
3156
+ google::protobuf::DescriptorProto::descriptor ()->file ()->DebugString ());
3157
+ CreateTempFile (" custom_option.proto" ,
3158
+ R"schema(
3159
+ syntax = "proto2";
3160
+ import "google/protobuf/descriptor.proto";
3161
+ extend .google.protobuf.FileOptions {
3162
+ optional int32 file_opt = 5000 [debug_redact = true];
3163
+ }
3164
+ )schema" );
3165
+ CreateTempFile (" bar.proto" ,
3166
+ R"schema(
3167
+ edition = "2024";
3168
+ import option "custom_option.proto";
3169
+ option (file_opt) = 1;
3170
+ message Bar {
3171
+ int32 foo = 1;
3172
+ }
3173
+ )schema" );
3174
+
3175
+ Run (" protocol_compiler --descriptor_set_out=$tmpdir/descriptor_set "
3176
+ " --include_imports --proto_path=$tmpdir bar.proto "
3177
+ " --experimental_editions" );
3178
+
3179
+ ExpectNoErrors ();
3180
+ }
3181
+
3182
+ TEST_F (CommandLineInterfaceTest, OptionImportWithDebugRedactIsError) {
3183
+ CreateTempFile (" google/protobuf/descriptor.proto" ,
3184
+ google::protobuf::DescriptorProto::descriptor ()->file ()->DebugString ());
3185
+ CreateTempFile (" custom_option.proto" ,
3186
+ R"schema(
3187
+ syntax = "proto2";
3188
+ import "google/protobuf/descriptor.proto";
3189
+ enum MyEnum {
3190
+ MY_ENUM_VALUE = 0 [debug_redact = true];
3191
+ }
3192
+ extend .google.protobuf.FieldOptions {
3193
+ optional MyEnum file_opt = 5000 [debug_redact = true];
3194
+ }
3195
+ )schema" );
3196
+ CreateTempFile (" bar.proto" ,
3197
+ R"schema(
3198
+ edition = "2024";
3199
+ import option "custom_option.proto";
3200
+ message Bar {
3201
+ int32 foo = 1 [(file_opt) = MY_ENUM_VALUE];
3202
+ }
3203
+ )schema" );
3204
+
3205
+ Run (" protocol_compiler --descriptor_set_out=$tmpdir/descriptor_set "
3206
+ " --include_imports --proto_path=$tmpdir bar.proto "
3207
+ " --experimental_editions" );
3208
+
3209
+ ExpectErrorSubstring (
3210
+ " bar.proto: Optional dependency custom_option.proto contains a custom "
3211
+ " option file_opt marked debug_redact" );
3212
+ }
3213
+
3214
+ TEST_F (CommandLineInterfaceTest, OptionImportWithDebugRedactDeeplyNested) {
3215
+ CreateTempFile (" google/protobuf/descriptor.proto" ,
3216
+ google::protobuf::DescriptorProto::descriptor ()->file ()->DebugString ());
3217
+ CreateTempFile (" custom_option.proto" ,
3218
+ R"schema(
3219
+ syntax = "proto2";
3220
+ import "google/protobuf/descriptor.proto";
3221
+ enum MyEnum {
3222
+ MY_ENUM_VALUE = 0 [debug_redact = true];
3223
+ }
3224
+ message Container {
3225
+ optional MyEnum enm = 1;
3226
+ }
3227
+ message MyMessage {
3228
+ optional MyMessage msg = 1;
3229
+ optional Container ctr = 2;
3230
+ }
3231
+ extend .google.protobuf.FieldOptions {
3232
+ optional MyMessage file_opt = 5000 [debug_redact = true];
3233
+ }
3234
+ )schema" );
3235
+ CreateTempFile (" bar.proto" ,
3236
+ R"schema(
3237
+ edition = "2024";
3238
+ import option "custom_option.proto";
3239
+ message Bar {
3240
+ int32 foo = 1 [(file_opt).msg = {}];
3241
+ }
3242
+ )schema" );
3243
+
3244
+ Run (" protocol_compiler --descriptor_set_out=$tmpdir/descriptor_set "
3245
+ " --include_imports --proto_path=$tmpdir bar.proto "
3246
+ " --experimental_editions" );
3247
+
3248
+ ExpectErrorSubstring (
3249
+ " bar.proto: Optional dependency custom_option.proto contains a custom "
3250
+ " option file_opt marked debug_redact" );
3251
+ }
3252
+
3154
3253
TEST_F (CommandLineInterfaceTest, DisallowMissingOptionImportsDescriptorSetIn) {
3155
3254
FileDescriptorSet file_descriptor_set;
3156
3255
0 commit comments