From fe4d1e780f17e72125b87e10b803e05a6ab7653d Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Wed, 6 Aug 2025 13:55:17 -0700 Subject: [PATCH] migrate unittest_features.proto with java features PiperOrigin-RevId: 791831991 --- cmake/tests.cmake | 2 +- src/google/protobuf/BUILD.bazel | 8 ++++++-- .../compiler/command_line_interface_unittest.cc | 17 +++++++++++++++++ src/google/protobuf/descriptor_unittest.cc | 17 +++++++++++++++++ src/google/protobuf/unittest_features.proto | 4 ++++ 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 00a069b141055..9588e877ae2a1 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -26,7 +26,7 @@ foreach(proto_file ${lite_test_protos}) PROTOS ${proto_file} LANGUAGE cpp OUT_VAR pb_generated_files - IMPORT_DIRS ${protobuf_SOURCE_DIR}/src + IMPORT_DIRS ${protobuf_SOURCE_DIR}/src ${protobuf_SOURCE_DIR}/java/core/src/main/resources ) set(lite_test_proto_files ${lite_test_proto_files} ${pb_generated_files}) endforeach(proto_file) diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index 2af2f2913c9f3..a1b2cd19b35cf 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -1186,9 +1186,10 @@ cc_proto_library( deps = [":unittest_proto3_optional_proto"], ) -proto_library( +protobuf_test_proto_library( name = "unittest_features_proto", srcs = ["unittest_features.proto"], + option_deps = ["//:java_features_proto"], strip_import_prefix = "/src", visibility = ["//editions:__subpackages__"], deps = [ @@ -1205,7 +1206,10 @@ cc_proto_library( protobuf_test_proto_library( name = "generic_test_protos", srcs = [":test_proto_srcs"], - option_deps = [":cpp_features_proto"], + option_deps = [ + ":cpp_features_proto", + "//:java_features_proto", + ], strip_import_prefix = "/src", visibility = ["//:__subpackages__"], deps = [ diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index a20e15817113f..22452e68c4bce 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -22,6 +22,7 @@ #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/types/span.h" +#include "google/protobuf/compiler/java/java_features.pb.h" #include "google/protobuf/compiler/command_line_interface_tester.h" #include "google/protobuf/unittest_features.pb.h" #include "google/protobuf/unittest_invalid_features.pb.h" @@ -1539,6 +1540,8 @@ TEST_F(CommandLineInterfaceTest, FeatureTargetError) { TEST_F(CommandLineInterfaceTest, FeatureExtensionError) { CreateTempFile("google/protobuf/descriptor.proto", google::protobuf::DescriptorProto::descriptor()->file()->DebugString()); + CreateTempFile("third_party/java/protobuf/java_features.proto", + pb::JavaFeatures::descriptor()->file()->DebugString()); CreateTempFile("google/protobuf/unittest_features.proto", pb::TestInvalidFeatures::descriptor()->file()->DebugString()); CreateTempFile("foo.proto", @@ -1638,6 +1641,8 @@ TEST_F(CommandLineInterfaceTest, Plugin_DeprecatedEdition) { TEST_F(CommandLineInterfaceTest, Plugin_DeprecatedFeature) { CreateTempFile("google/protobuf/descriptor.proto", google::protobuf::DescriptorProto::descriptor()->file()->DebugString()); + CreateTempFile("third_party/java/protobuf/java_features.proto", + pb::JavaFeatures::descriptor()->file()->DebugString()); CreateTempFile("google/protobuf/unittest_features.proto", pb::TestFeatures::descriptor()->file()->DebugString()); CreateTempFile("foo.proto", @@ -1658,6 +1663,8 @@ TEST_F(CommandLineInterfaceTest, Plugin_DeprecatedFeature) { TEST_F(CommandLineInterfaceTest, Plugin_TransitiveDeprecatedFeature) { CreateTempFile("google/protobuf/descriptor.proto", google::protobuf::DescriptorProto::descriptor()->file()->DebugString()); + CreateTempFile("third_party/java/protobuf/java_features.proto", + pb::JavaFeatures::descriptor()->file()->DebugString()); CreateTempFile("google/protobuf/unittest_features.proto", pb::TestFeatures::descriptor()->file()->DebugString()); CreateTempFile("unused.proto", @@ -1843,6 +1850,8 @@ TEST_F(CommandLineInterfaceTest, Plugin_RuntimeFeatures) { TEST_F(CommandLineInterfaceTest, Plugin_SourceFeatures) { CreateTempFile("google/protobuf/descriptor.proto", google::protobuf::DescriptorProto::descriptor()->file()->DebugString()); + CreateTempFile("third_party/java/protobuf/java_features.proto", + pb::JavaFeatures::descriptor()->file()->DebugString()); CreateTempFile("google/protobuf/unittest_features.proto", pb::TestFeatures::descriptor()->file()->DebugString()); CreateTempFile("foo.proto", @@ -1903,6 +1912,8 @@ TEST_F(CommandLineInterfaceTest, Plugin_SourceFeatures) { TEST_F(CommandLineInterfaceTest, GeneratorFeatureLifetimeError) { CreateTempFile("google/protobuf/descriptor.proto", google::protobuf::DescriptorProto::descriptor()->file()->DebugString()); + CreateTempFile("third_party/java/protobuf/java_features.proto", + pb::JavaFeatures::descriptor()->file()->DebugString()); CreateTempFile("google/protobuf/unittest_features.proto", pb::TestFeatures::descriptor()->file()->DebugString()); CreateTempFile("foo.proto", @@ -1927,6 +1938,8 @@ TEST_F(CommandLineInterfaceTest, GeneratorFeatureLifetimeError) { TEST_F(CommandLineInterfaceTest, PluginFeatureLifetimeError) { CreateTempFile("google/protobuf/descriptor.proto", google::protobuf::DescriptorProto::descriptor()->file()->DebugString()); + CreateTempFile("third_party/java/protobuf/java_features.proto", + pb::JavaFeatures::descriptor()->file()->DebugString()); CreateTempFile("google/protobuf/unittest_features.proto", pb::TestFeatures::descriptor()->file()->DebugString()); CreateTempFile("foo.proto", @@ -2280,6 +2293,8 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithMinimum) { TEST_F(CommandLineInterfaceTest, EditionDefaultsWithExtension) { CreateTempFile("google/protobuf/descriptor.proto", google::protobuf::DescriptorProto::descriptor()->file()->DebugString()); + CreateTempFile("third_party/java/protobuf/java_features.proto", + pb::JavaFeatures::descriptor()->file()->DebugString()); CreateTempFile("google/protobuf/unittest_features.proto", pb::TestFeatures::descriptor()->file()->DebugString()); Run("protocol_compiler --proto_path=$tmpdir " @@ -2329,6 +2344,8 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithExtension) { TEST_F(CommandLineInterfaceTest, EditionDefaultsDependencyManifest) { CreateTempFile("google/protobuf/descriptor.proto", google::protobuf::DescriptorProto::descriptor()->file()->DebugString()); + CreateTempFile("third_party/java/protobuf/java_features.proto", + pb::JavaFeatures::descriptor()->file()->DebugString()); CreateTempFile("google/protobuf/unittest_features.proto", pb::TestFeatures::descriptor()->file()->DebugString()); diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index fe5f458eeb0dc..8378373c3522b 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -55,6 +55,7 @@ #include "absl/strings/strip.h" #include "absl/strings/substitute.h" #include "absl/synchronization/notification.h" +#include "google/protobuf/java_features.pb.h" #include "google/protobuf/compiler/importer.h" #include "google/protobuf/compiler/parser.h" #include "google/protobuf/cpp_features.pb.h" @@ -9076,6 +9077,7 @@ TEST_F(FeaturesTest, Edition2024Defaults) { TEST_F(FeaturesBaseTest, DefaultEdition2023Defaults) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -9134,6 +9136,7 @@ TEST_F(FeaturesTest, ClearsOptions) { TEST_F(FeaturesTest, RestoresOptionsRoundTrip) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -9356,6 +9359,7 @@ TEST_F(FeaturesTest, ReusesFeaturesFromDifferentFile) { TEST_F(FeaturesTest, ReusesFeaturesExtension) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file1 = BuildFile(R"pb( name: "foo.proto" @@ -9539,6 +9543,7 @@ TEST_F(FeaturesTest, FileFeatures) { TEST_F(FeaturesTest, FileFeaturesExtension) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -9564,6 +9569,7 @@ TEST_F(FeaturesTest, FileFeaturesExtension) { TEST_F(FeaturesTest, FileFeaturesExtensionOverride) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -9636,6 +9642,7 @@ TEST_F(FeaturesTest, MessageFeaturesInherit) { TEST_F(FeaturesTest, MessageFeaturesOverride) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -9664,6 +9671,7 @@ TEST_F(FeaturesTest, MessageFeaturesOverride) { TEST_F(FeaturesTest, NestedMessageFeaturesOverride) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -9735,6 +9743,7 @@ TEST_F(FeaturesTest, FieldFeaturesDefault) { TEST_F(FeaturesTest, FieldFeaturesInherit) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -9766,6 +9775,7 @@ TEST_F(FeaturesTest, FieldFeaturesInherit) { TEST_F(FeaturesTest, FieldFeaturesOverride) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -9810,6 +9820,7 @@ TEST_F(FeaturesTest, FieldFeaturesOverride) { TEST_F(FeaturesTest, OneofFieldFeaturesInherit) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -9855,6 +9866,7 @@ TEST_F(FeaturesTest, OneofFieldFeaturesInherit) { TEST_F(FeaturesTest, OneofFieldFeaturesOverride) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -9909,6 +9921,7 @@ TEST_F(FeaturesTest, OneofFieldFeaturesOverride) { TEST_F(FeaturesTest, MapFieldFeaturesOverride) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = ParseAndBuildFile("foo.proto", R"schema( edition = "2023"; @@ -10323,6 +10336,7 @@ TEST_F(FeaturesTest, MapFieldFeaturesInheritedMessageEncoding) { TEST_F(FeaturesTest, RootExtensionFeaturesOverride) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -10364,6 +10378,7 @@ TEST_F(FeaturesTest, RootExtensionFeaturesOverride) { TEST_F(FeaturesTest, MessageExtensionFeaturesOverride) { BuildDescriptorMessagesInTestPool(); + BuildFileInTestPool(pb::JavaFeatures::descriptor()->file()); BuildFileInTestPool(pb::TestFeatures::descriptor()->file()); const FileDescriptor* file = BuildFile(R"pb( name: "foo.proto" @@ -12511,6 +12526,8 @@ TEST_P(FeaturesDebugStringTest, RoundTrip) { LoadFile("google/protobuf/descriptor.proto", DescriptorProto::GetDescriptor()->file()->DebugString()); + LoadFile("third_party/java/protobuf/java_features.proto", + pb::JavaFeatures::GetDescriptor()->file()->DebugString()); LoadFile("google/protobuf/unittest_features.proto", pb::TestFeatures::GetDescriptor()->file()->DebugString()); const FileDescriptor* roundtripped = diff --git a/src/google/protobuf/unittest_features.proto b/src/google/protobuf/unittest_features.proto index dd0d4141ed0a9..36935fae1c503 100644 --- a/src/google/protobuf/unittest_features.proto +++ b/src/google/protobuf/unittest_features.proto @@ -13,6 +13,8 @@ import "google/protobuf/descriptor.proto"; option java_outer_classname = "UnittestFeatures"; +import option "google/protobuf/java_features.proto"; + extend google.protobuf.FeatureSet { TestFeatures test = 9999; } @@ -29,6 +31,8 @@ message TestMessage { } enum EnumFeature { + option features.(pb.java).nest_in_file_class = YES; + TEST_ENUM_FEATURE_UNKNOWN = 0; VALUE1 = 1; VALUE2 = 2;