@@ -2481,6 +2481,27 @@ TEST_F(CommandLineInterfaceTest, DirectDependencies_Missing) {
24812481 " bar.proto\n " );
24822482}
24832483
2484+ TEST_F (CommandLineInterfaceTest,
2485+ DirectDependencies_Missing_WithOptionDependencies) {
2486+ CreateTempFile (" foo.proto" , R"schema(
2487+ syntax = "proto2";
2488+ import "bar.proto";
2489+ message Foo { optional Bar bar = 1; }
2490+ )schema" );
2491+ CreateTempFile (" bar.proto" , R"schema(
2492+ syntax = "proto2";
2493+ message Bar { optional string text = 1; }
2494+ )schema" );
2495+
2496+ Run (" protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir "
2497+ " --direct_dependencies= "
2498+ " --option_dependencies=bar.proto foo.proto" );
2499+
2500+ ExpectErrorText (
2501+ " foo.proto: File is imported but not declared in --direct_dependencies: "
2502+ " bar.proto\n " );
2503+ }
2504+
24842505TEST_F (CommandLineInterfaceTest, DirectDependencies_NoViolation) {
24852506 CreateTempFile (" foo.proto" ,
24862507 " syntax = \" proto2\" ;\n "
@@ -2549,6 +2570,93 @@ TEST_F(CommandLineInterfaceTest, DirectDependencies_CustomErrorMessage) {
25492570 ExpectErrorText (" foo.proto: Bla \" bar.proto\" Bla\n " );
25502571}
25512572
2573+ TEST_F (CommandLineInterfaceTest, OptionDependencies_Missing_EmptyList) {
2574+ CreateTempFile (" foo.proto" , R"schema(
2575+ edition = "2024";
2576+ import option "bar.proto";
2577+
2578+ option (bar_opt) = 1;
2579+ )schema" );
2580+ CreateTempFile (" bar.proto" , R"schema(
2581+ syntax = "proto2";
2582+ import "google/protobuf/descriptor.proto";
2583+ extend google.protobuf.FileOptions {
2584+ optional int32 bar_opt = 99990;
2585+ }
2586+ )schema" );
2587+ CreateTempFile (" google/protobuf/descriptor.proto" ,
2588+ google::protobuf::DescriptorProto::descriptor ()->file ()->DebugString ());
2589+
2590+ Run (" protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir "
2591+ " --option_dependencies= foo.proto "
2592+ " --experimental_editions" );
2593+ ExpectErrorText (
2594+ " foo.proto: File is option imported but not declared in "
2595+ " --option_dependencies: "
2596+ " bar.proto\n " );
2597+ }
2598+
2599+ TEST_F (CommandLineInterfaceTest, OptionDependencies_Missing) {
2600+ CreateTempFile (" foo.proto" , R"schema(
2601+ edition = "2024";
2602+ import option "bar.proto";
2603+ import option "bla.proto";
2604+
2605+ option (bar_opt) = 1;
2606+ option (bla_opt) = 2;
2607+ )schema" );
2608+ CreateTempFile (" bar.proto" , R"schema(
2609+ syntax = "proto2";
2610+ import "google/protobuf/descriptor.proto";
2611+ extend google.protobuf.FileOptions {
2612+ optional int32 bar_opt = 99990;
2613+ }
2614+ )schema" );
2615+ CreateTempFile (" bla.proto" , R"schema(
2616+ syntax = "proto2";
2617+ import "google/protobuf/descriptor.proto";
2618+ extend google.protobuf.FileOptions {
2619+ optional int32 bla_opt = 99991;
2620+ }
2621+ )schema" );
2622+ CreateTempFile (" google/protobuf/descriptor.proto" ,
2623+ google::protobuf::DescriptorProto::descriptor ()->file ()->DebugString ());
2624+
2625+ Run (" protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir "
2626+ " --option_dependencies=bla.proto foo.proto" );
2627+ ExpectErrorText (
2628+ " foo.proto: File is option imported but not declared in "
2629+ " --option_dependencies: bar.proto\n " );
2630+ }
2631+
2632+ TEST_F (CommandLineInterfaceTest,
2633+ OptionDependencies_Missing_WithDirectDependencies) {
2634+ CreateTempFile (" foo.proto" , R"schema(
2635+ edition = "2024";
2636+ import option "bar.proto";
2637+
2638+ option (bar_opt) = 1;
2639+ )schema" );
2640+ CreateTempFile (" bar.proto" , R"schema(
2641+ syntax = "proto2";
2642+ import "google/protobuf/descriptor.proto";
2643+ extend google.protobuf.FileOptions {
2644+ optional int32 bar_opt = 99990;
2645+ }
2646+ )schema" );
2647+ CreateTempFile (" google/protobuf/descriptor.proto" ,
2648+ google::protobuf::DescriptorProto::descriptor ()->file ()->DebugString ());
2649+
2650+ Run (" protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir "
2651+ " --direct_dependencies=bar.proto "
2652+ " --option_dependencies= foo.proto" );
2653+
2654+ ExpectErrorText (
2655+ " foo.proto: File is option imported but not declared in "
2656+ " --option_dependencies: "
2657+ " bar.proto\n " );
2658+ }
2659+
25522660TEST_F (CommandLineInterfaceTest, CwdRelativeInputs) {
25532661 // Test that we can accept working-directory-relative input files.
25542662
0 commit comments