Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions src/google/protobuf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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 = [
Expand Down
17 changes: 17 additions & 0 deletions src/google/protobuf/compiler/command_line_interface_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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());

Expand Down
17 changes: 17 additions & 0 deletions src/google/protobuf/descriptor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 =
Expand Down
4 changes: 4 additions & 0 deletions src/google/protobuf/unittest_features.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
Loading