Skip to content

Commit da04d80

Browse files
zhangskzcopybara-github
authored andcommitted
migrate unittest_features.proto with java features
PiperOrigin-RevId: 791831991
1 parent 4a5a788 commit da04d80

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

cmake/tests.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ foreach(proto_file ${lite_test_protos})
2626
PROTOS ${proto_file}
2727
LANGUAGE cpp
2828
OUT_VAR pb_generated_files
29-
IMPORT_DIRS ${protobuf_SOURCE_DIR}/src
29+
IMPORT_DIRS ${protobuf_SOURCE_DIR}/src ${protobuf_SOURCE_DIR}/java/core/src/main/resources
3030
)
3131
set(lite_test_proto_files ${lite_test_proto_files} ${pb_generated_files})
3232
endforeach(proto_file)

src/google/protobuf/BUILD.bazel

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,9 +1186,10 @@ cc_proto_library(
11861186
deps = [":unittest_proto3_optional_proto"],
11871187
)
11881188

1189-
proto_library(
1189+
protobuf_test_proto_library(
11901190
name = "unittest_features_proto",
11911191
srcs = ["unittest_features.proto"],
1192+
option_deps = ["//:java_features_proto"],
11921193
strip_import_prefix = "/src",
11931194
visibility = ["//editions:__subpackages__"],
11941195
deps = [
@@ -1205,7 +1206,10 @@ cc_proto_library(
12051206
protobuf_test_proto_library(
12061207
name = "generic_test_protos",
12071208
srcs = [":test_proto_srcs"],
1208-
option_deps = [":cpp_features_proto"],
1209+
option_deps = [
1210+
":cpp_features_proto",
1211+
"//:java_features_proto",
1212+
],
12091213
strip_import_prefix = "/src",
12101214
visibility = ["//:__subpackages__"],
12111215
deps = [

src/google/protobuf/compiler/command_line_interface_unittest.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "absl/strings/match.h"
2323
#include "absl/strings/str_cat.h"
2424
#include "absl/types/span.h"
25+
#include "google/protobuf/compiler/java/java_features.pb.h"
2526
#include "google/protobuf/compiler/command_line_interface_tester.h"
2627
#include "google/protobuf/unittest_features.pb.h"
2728
#include "google/protobuf/unittest_invalid_features.pb.h"
@@ -1539,6 +1540,8 @@ TEST_F(CommandLineInterfaceTest, FeatureTargetError) {
15391540
TEST_F(CommandLineInterfaceTest, FeatureExtensionError) {
15401541
CreateTempFile("google/protobuf/descriptor.proto",
15411542
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());
1543+
CreateTempFile("third_party/java/protobuf/java_features.proto",
1544+
pb::JavaFeatures::descriptor()->file()->DebugString());
15421545
CreateTempFile("google/protobuf/unittest_features.proto",
15431546
pb::TestInvalidFeatures::descriptor()->file()->DebugString());
15441547
CreateTempFile("foo.proto",
@@ -1638,6 +1641,8 @@ TEST_F(CommandLineInterfaceTest, Plugin_DeprecatedEdition) {
16381641
TEST_F(CommandLineInterfaceTest, Plugin_DeprecatedFeature) {
16391642
CreateTempFile("google/protobuf/descriptor.proto",
16401643
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());
1644+
CreateTempFile("third_party/java/protobuf/java_features.proto",
1645+
pb::JavaFeatures::descriptor()->file()->DebugString());
16411646
CreateTempFile("google/protobuf/unittest_features.proto",
16421647
pb::TestFeatures::descriptor()->file()->DebugString());
16431648
CreateTempFile("foo.proto",
@@ -1658,6 +1663,8 @@ TEST_F(CommandLineInterfaceTest, Plugin_DeprecatedFeature) {
16581663
TEST_F(CommandLineInterfaceTest, Plugin_TransitiveDeprecatedFeature) {
16591664
CreateTempFile("google/protobuf/descriptor.proto",
16601665
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());
1666+
CreateTempFile("third_party/java/protobuf/java_features.proto",
1667+
pb::JavaFeatures::descriptor()->file()->DebugString());
16611668
CreateTempFile("google/protobuf/unittest_features.proto",
16621669
pb::TestFeatures::descriptor()->file()->DebugString());
16631670
CreateTempFile("unused.proto",
@@ -1843,6 +1850,8 @@ TEST_F(CommandLineInterfaceTest, Plugin_RuntimeFeatures) {
18431850
TEST_F(CommandLineInterfaceTest, Plugin_SourceFeatures) {
18441851
CreateTempFile("google/protobuf/descriptor.proto",
18451852
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());
1853+
CreateTempFile("third_party/java/protobuf/java_features.proto",
1854+
pb::JavaFeatures::descriptor()->file()->DebugString());
18461855
CreateTempFile("google/protobuf/unittest_features.proto",
18471856
pb::TestFeatures::descriptor()->file()->DebugString());
18481857
CreateTempFile("foo.proto",
@@ -1903,6 +1912,8 @@ TEST_F(CommandLineInterfaceTest, Plugin_SourceFeatures) {
19031912
TEST_F(CommandLineInterfaceTest, GeneratorFeatureLifetimeError) {
19041913
CreateTempFile("google/protobuf/descriptor.proto",
19051914
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());
1915+
CreateTempFile("third_party/java/protobuf/java_features.proto",
1916+
pb::JavaFeatures::descriptor()->file()->DebugString());
19061917
CreateTempFile("google/protobuf/unittest_features.proto",
19071918
pb::TestFeatures::descriptor()->file()->DebugString());
19081919
CreateTempFile("foo.proto",
@@ -1927,6 +1938,8 @@ TEST_F(CommandLineInterfaceTest, GeneratorFeatureLifetimeError) {
19271938
TEST_F(CommandLineInterfaceTest, PluginFeatureLifetimeError) {
19281939
CreateTempFile("google/protobuf/descriptor.proto",
19291940
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());
1941+
CreateTempFile("third_party/java/protobuf/java_features.proto",
1942+
pb::JavaFeatures::descriptor()->file()->DebugString());
19301943
CreateTempFile("google/protobuf/unittest_features.proto",
19311944
pb::TestFeatures::descriptor()->file()->DebugString());
19321945
CreateTempFile("foo.proto",
@@ -2280,6 +2293,8 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithMinimum) {
22802293
TEST_F(CommandLineInterfaceTest, EditionDefaultsWithExtension) {
22812294
CreateTempFile("google/protobuf/descriptor.proto",
22822295
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());
2296+
CreateTempFile("third_party/java/protobuf/java_features.proto",
2297+
pb::JavaFeatures::descriptor()->file()->DebugString());
22832298
CreateTempFile("google/protobuf/unittest_features.proto",
22842299
pb::TestFeatures::descriptor()->file()->DebugString());
22852300
Run("protocol_compiler --proto_path=$tmpdir "
@@ -2329,6 +2344,8 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithExtension) {
23292344
TEST_F(CommandLineInterfaceTest, EditionDefaultsDependencyManifest) {
23302345
CreateTempFile("google/protobuf/descriptor.proto",
23312346
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());
2347+
CreateTempFile("third_party/java/protobuf/java_features.proto",
2348+
pb::JavaFeatures::descriptor()->file()->DebugString());
23322349
CreateTempFile("google/protobuf/unittest_features.proto",
23332350
pb::TestFeatures::descriptor()->file()->DebugString());
23342351

src/google/protobuf/descriptor_unittest.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "absl/strings/strip.h"
5656
#include "absl/strings/substitute.h"
5757
#include "absl/synchronization/notification.h"
58+
#include "google/protobuf/java_features.pb.h"
5859
#include "google/protobuf/compiler/importer.h"
5960
#include "google/protobuf/compiler/parser.h"
6061
#include "google/protobuf/cpp_features.pb.h"
@@ -9076,6 +9077,7 @@ TEST_F(FeaturesTest, Edition2024Defaults) {
90769077

90779078
TEST_F(FeaturesBaseTest, DefaultEdition2023Defaults) {
90789079
BuildDescriptorMessagesInTestPool();
9080+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
90799081
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
90809082
const FileDescriptor* file = BuildFile(R"pb(
90819083
name: "foo.proto"
@@ -9134,6 +9136,7 @@ TEST_F(FeaturesTest, ClearsOptions) {
91349136

91359137
TEST_F(FeaturesTest, RestoresOptionsRoundTrip) {
91369138
BuildDescriptorMessagesInTestPool();
9139+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
91379140
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
91389141
const FileDescriptor* file = BuildFile(R"pb(
91399142
name: "foo.proto"
@@ -9356,6 +9359,7 @@ TEST_F(FeaturesTest, ReusesFeaturesFromDifferentFile) {
93569359

93579360
TEST_F(FeaturesTest, ReusesFeaturesExtension) {
93589361
BuildDescriptorMessagesInTestPool();
9362+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
93599363
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
93609364
const FileDescriptor* file1 = BuildFile(R"pb(
93619365
name: "foo.proto"
@@ -9539,6 +9543,7 @@ TEST_F(FeaturesTest, FileFeatures) {
95399543

95409544
TEST_F(FeaturesTest, FileFeaturesExtension) {
95419545
BuildDescriptorMessagesInTestPool();
9546+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
95429547
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
95439548
const FileDescriptor* file = BuildFile(R"pb(
95449549
name: "foo.proto"
@@ -9564,6 +9569,7 @@ TEST_F(FeaturesTest, FileFeaturesExtension) {
95649569

95659570
TEST_F(FeaturesTest, FileFeaturesExtensionOverride) {
95669571
BuildDescriptorMessagesInTestPool();
9572+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
95679573
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
95689574
const FileDescriptor* file = BuildFile(R"pb(
95699575
name: "foo.proto"
@@ -9636,6 +9642,7 @@ TEST_F(FeaturesTest, MessageFeaturesInherit) {
96369642

96379643
TEST_F(FeaturesTest, MessageFeaturesOverride) {
96389644
BuildDescriptorMessagesInTestPool();
9645+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
96399646
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
96409647
const FileDescriptor* file = BuildFile(R"pb(
96419648
name: "foo.proto"
@@ -9664,6 +9671,7 @@ TEST_F(FeaturesTest, MessageFeaturesOverride) {
96649671

96659672
TEST_F(FeaturesTest, NestedMessageFeaturesOverride) {
96669673
BuildDescriptorMessagesInTestPool();
9674+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
96679675
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
96689676
const FileDescriptor* file = BuildFile(R"pb(
96699677
name: "foo.proto"
@@ -9735,6 +9743,7 @@ TEST_F(FeaturesTest, FieldFeaturesDefault) {
97359743

97369744
TEST_F(FeaturesTest, FieldFeaturesInherit) {
97379745
BuildDescriptorMessagesInTestPool();
9746+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
97389747
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
97399748
const FileDescriptor* file = BuildFile(R"pb(
97409749
name: "foo.proto"
@@ -9766,6 +9775,7 @@ TEST_F(FeaturesTest, FieldFeaturesInherit) {
97669775

97679776
TEST_F(FeaturesTest, FieldFeaturesOverride) {
97689777
BuildDescriptorMessagesInTestPool();
9778+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
97699779
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
97709780
const FileDescriptor* file = BuildFile(R"pb(
97719781
name: "foo.proto"
@@ -9810,6 +9820,7 @@ TEST_F(FeaturesTest, FieldFeaturesOverride) {
98109820

98119821
TEST_F(FeaturesTest, OneofFieldFeaturesInherit) {
98129822
BuildDescriptorMessagesInTestPool();
9823+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
98139824
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
98149825
const FileDescriptor* file = BuildFile(R"pb(
98159826
name: "foo.proto"
@@ -9855,6 +9866,7 @@ TEST_F(FeaturesTest, OneofFieldFeaturesInherit) {
98559866

98569867
TEST_F(FeaturesTest, OneofFieldFeaturesOverride) {
98579868
BuildDescriptorMessagesInTestPool();
9869+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
98589870
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
98599871
const FileDescriptor* file = BuildFile(R"pb(
98609872
name: "foo.proto"
@@ -9909,6 +9921,7 @@ TEST_F(FeaturesTest, OneofFieldFeaturesOverride) {
99099921

99109922
TEST_F(FeaturesTest, MapFieldFeaturesOverride) {
99119923
BuildDescriptorMessagesInTestPool();
9924+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
99129925
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
99139926
const FileDescriptor* file = ParseAndBuildFile("foo.proto", R"schema(
99149927
edition = "2023";
@@ -10323,6 +10336,7 @@ TEST_F(FeaturesTest, MapFieldFeaturesInheritedMessageEncoding) {
1032310336

1032410337
TEST_F(FeaturesTest, RootExtensionFeaturesOverride) {
1032510338
BuildDescriptorMessagesInTestPool();
10339+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
1032610340
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
1032710341
const FileDescriptor* file = BuildFile(R"pb(
1032810342
name: "foo.proto"
@@ -10364,6 +10378,7 @@ TEST_F(FeaturesTest, RootExtensionFeaturesOverride) {
1036410378

1036510379
TEST_F(FeaturesTest, MessageExtensionFeaturesOverride) {
1036610380
BuildDescriptorMessagesInTestPool();
10381+
BuildFileInTestPool(pb::JavaFeatures::descriptor()->file());
1036710382
BuildFileInTestPool(pb::TestFeatures::descriptor()->file());
1036810383
const FileDescriptor* file = BuildFile(R"pb(
1036910384
name: "foo.proto"
@@ -12511,6 +12526,8 @@ TEST_P(FeaturesDebugStringTest, RoundTrip) {
1251112526

1251212527
LoadFile("google/protobuf/descriptor.proto",
1251312528
DescriptorProto::GetDescriptor()->file()->DebugString());
12529+
LoadFile("third_party/java/protobuf/java_features.proto",
12530+
pb::JavaFeatures::GetDescriptor()->file()->DebugString());
1251412531
LoadFile("google/protobuf/unittest_features.proto",
1251512532
pb::TestFeatures::GetDescriptor()->file()->DebugString());
1251612533
const FileDescriptor* roundtripped =

src/google/protobuf/unittest_features.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import "google/protobuf/descriptor.proto";
1313

1414
option java_outer_classname = "UnittestFeatures";
1515

16+
import option "google/protobuf/java_features.proto";
17+
1618
extend google.protobuf.FeatureSet {
1719
TestFeatures test = 9999;
1820
}
@@ -29,6 +31,8 @@ message TestMessage {
2931
}
3032

3133
enum EnumFeature {
34+
option features.(pb.java).nest_in_file_class = YES;
35+
3236
TEST_ENUM_FEATURE_UNKNOWN = 0;
3337
VALUE1 = 1;
3438
VALUE2 = 2;

0 commit comments

Comments
 (0)