Migrate internal C++-only test protos to editions.

This is some low hanging fruit that can increase our test coverage of editions.  Since only the C++ backend is implemented today, we can't yet migrate any protos that are public, are used outside C++, or are depended on by any proto outside C++.

PiperOrigin-RevId: 546076822
pull/13233/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent a5516ca6cc
commit c3b72b99b4
  1. 2
      pkg/BUILD.bazel
  2. 36
      src/google/protobuf/BUILD.bazel
  3. 2
      src/google/protobuf/compiler/allowlists/editions.cc
  4. 2
      src/google/protobuf/compiler/cpp/BUILD.bazel
  5. 5
      src/google/protobuf/map_proto3_unittest.proto
  6. 10
      src/google/protobuf/preserve_unknown_enum_test.cc
  7. 6
      src/google/protobuf/unittest_arena.proto
  8. 4
      src/google/protobuf/unittest_drop_unknown_fields.proto
  9. 4
      src/google/protobuf/unittest_lazy_dependencies.proto
  10. 6
      src/google/protobuf/unittest_lazy_dependencies_custom_option.proto
  11. 5
      src/google/protobuf/unittest_lazy_dependencies_enum.proto
  12. 5
      src/google/protobuf/unittest_no_field_presence.proto
  13. 10
      src/google/protobuf/unittest_preserve_unknown_enum.proto
  14. 12
      src/google/protobuf/unittest_preserve_unknown_enum2.proto

@ -119,7 +119,7 @@ gen_file_lists(
":test_util": "test_util", ":test_util": "test_util",
# Tests and test-only protos: # Tests and test-only protos:
"//src/google/protobuf:full_test_srcs": "protobuf_test", "//src/google/protobuf:full_test_srcs": "protobuf_test",
"//src/google/protobuf:test_proto_srcs": "protobuf_test_protos", "//src/google/protobuf:test_proto_all_srcs": "protobuf_test_protos",
"//src/google/protobuf:lite_test_srcs": "protobuf_lite_test", "//src/google/protobuf:lite_test_srcs": "protobuf_lite_test",
"//src/google/protobuf:lite_test_proto_srcs": "protobuf_lite_test_protos", "//src/google/protobuf:lite_test_proto_srcs": "protobuf_lite_test_protos",
"//src/google/protobuf/compiler:fake_plugin_srcs": "fake_plugin", "//src/google/protobuf/compiler:fake_plugin_srcs": "fake_plugin",

@ -665,12 +665,9 @@ filegroup(
srcs = [ srcs = [
"any_test.proto", "any_test.proto",
"map_proto2_unittest.proto", "map_proto2_unittest.proto",
"map_proto3_unittest.proto",
"map_unittest.proto", "map_unittest.proto",
"unittest.proto", "unittest.proto",
"unittest_arena.proto",
"unittest_custom_options.proto", "unittest_custom_options.proto",
"unittest_drop_unknown_fields.proto",
"unittest_embed_optimize_for.proto", "unittest_embed_optimize_for.proto",
"unittest_empty.proto", "unittest_empty.proto",
"unittest_enormous_descriptor.proto", "unittest_enormous_descriptor.proto",
@ -678,17 +675,11 @@ filegroup(
"unittest_import.proto", "unittest_import.proto",
"unittest_import_public.proto", "unittest_import_public.proto",
"unittest_invalid_features.proto", "unittest_invalid_features.proto",
"unittest_lazy_dependencies.proto",
"unittest_lazy_dependencies_custom_option.proto",
"unittest_lazy_dependencies_enum.proto",
"unittest_lite_imports_nonlite.proto", "unittest_lite_imports_nonlite.proto",
"unittest_mset.proto", "unittest_mset.proto",
"unittest_mset_wire_format.proto", "unittest_mset_wire_format.proto",
"unittest_no_field_presence.proto",
"unittest_no_generic_services.proto", "unittest_no_generic_services.proto",
"unittest_optimize_for.proto", "unittest_optimize_for.proto",
"unittest_preserve_unknown_enum.proto",
"unittest_preserve_unknown_enum2.proto",
"unittest_proto3.proto", "unittest_proto3.proto",
"unittest_proto3_arena.proto", "unittest_proto3_arena.proto",
"unittest_proto3_arena_lite.proto", "unittest_proto3_arena_lite.proto",
@ -701,9 +692,34 @@ filegroup(
visibility = ["//:__subpackages__"], visibility = ["//:__subpackages__"],
) )
filegroup(
name = "test_proto_editions_srcs",
srcs = [
"map_proto3_unittest.proto",
"unittest_arena.proto",
"unittest_drop_unknown_fields.proto",
"unittest_lazy_dependencies.proto",
"unittest_lazy_dependencies_custom_option.proto",
"unittest_lazy_dependencies_enum.proto",
"unittest_no_field_presence.proto",
"unittest_preserve_unknown_enum.proto",
"unittest_preserve_unknown_enum2.proto",
],
visibility = ["//:__subpackages__"],
)
filegroup(
name = "test_proto_all_srcs",
srcs = [
":test_proto_editions_srcs",
":test_proto_srcs",
],
visibility = ["//:__subpackages__"],
)
proto_library( proto_library(
name = "test_protos", name = "test_protos",
srcs = [":test_proto_srcs"], srcs = [":test_proto_all_srcs"],
strip_import_prefix = "/src", strip_import_prefix = "/src",
visibility = ["//:__subpackages__"], visibility = ["//:__subpackages__"],
deps = [ deps = [

@ -42,7 +42,7 @@ namespace compiler {
static constexpr auto kEarlyEditionsFile = internal::MakeAllowlist( static constexpr auto kEarlyEditionsFile = internal::MakeAllowlist(
{ {
// Intentionally left blank. // Intentionally left blank.
"google/protobuf/editions/", "google/protobuf/",
}, },
internal::AllowlistFlags::kMatchPrefix); internal::AllowlistFlags::kMatchPrefix);

@ -141,7 +141,7 @@ cc_test(
srcs = ["unittest.cc"], srcs = ["unittest.cc"],
copts = COPTS, copts = COPTS,
data = [ data = [
"//:test_proto_srcs", "//src/google/protobuf:test_proto_all_srcs",
"//src/google/protobuf:testdata", "//src/google/protobuf:testdata",
], ],
deps = [ deps = [

@ -28,7 +28,10 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto3"; edition = "2023";
// Treat all fields as implicit present by default (proto3 behavior).
option features.field_presence = IMPLICIT;
// This file contains definitions that have different behavior in proto3. // This file contains definitions that have different behavior in proto3.

@ -276,15 +276,5 @@ TEST(PreserveUnknownEnumTest, Proto2CatchesUnknownValues) {
EXPECT_EQ(message.unknown_fields().field(2).varint(), 4242); EXPECT_EQ(message.unknown_fields().field(2).varint(), 4242);
} }
TEST(PreserveUnknownEnumTest, SupportsUnknownEnumValuesAPI) {
protobuf_unittest::TestAllTypes proto2_message;
proto3_preserve_unknown_enum_unittest::MyMessage new_message;
const Reflection* proto2_reflection = proto2_message.GetReflection();
const Reflection* new_reflection = new_message.GetReflection();
EXPECT_FALSE(proto2_reflection->SupportsUnknownEnumValues());
EXPECT_TRUE(new_reflection->SupportsUnknownEnumValues());
}
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google

@ -28,14 +28,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto2"; edition = "2023";
package proto2_arena_unittest; package proto2_arena_unittest;
// Use expanded encoding for repeated fields by default (proto2 behavior).
option features.repeated_field_encoding = EXPANDED;
option cc_enable_arenas = true; option cc_enable_arenas = true;
message NestedMessage { message NestedMessage {
optional int32 d = 1; int32 d = 1;
} }
message ArenaMessage { message ArenaMessage {

@ -28,10 +28,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto3"; edition = "2023";
package unittest_drop_unknown_fields; package unittest_drop_unknown_fields;
// Treat all fields as implicit present by default (proto3 behavior).
option features.field_presence = IMPLICIT;
option objc_class_prefix = "DropUnknowns"; option objc_class_prefix = "DropUnknowns";
option csharp_namespace = "Google.Protobuf.TestProtos"; option csharp_namespace = "Google.Protobuf.TestProtos";

@ -34,7 +34,7 @@
// //
// A proto file we will use for unit testing. // A proto file we will use for unit testing.
syntax = "proto2"; edition = "2023";
import "google/protobuf/unittest_lazy_dependencies_custom_option.proto"; import "google/protobuf/unittest_lazy_dependencies_custom_option.proto";
@ -64,7 +64,7 @@ option java_outer_classname = "UnittestLazyImportsProto";
// descriptor lazily and return it. // descriptor lazily and return it.
message ImportedMessage { message ImportedMessage {
optional LazyMessage lazy_message = 1; LazyMessage lazy_message = 1;
} }
message MessageCustomOption {} message MessageCustomOption {}

@ -34,7 +34,7 @@
// //
// A proto file we will use for unit testing. // A proto file we will use for unit testing.
syntax = "proto2"; edition = "2023";
import "google/protobuf/descriptor.proto"; import "google/protobuf/descriptor.proto";
import "google/protobuf/unittest_lazy_dependencies_enum.proto"; import "google/protobuf/unittest_lazy_dependencies_enum.proto";
@ -59,9 +59,9 @@ option optimize_for = SPEED;
option java_outer_classname = "UnittestLazyImportsCustomOptionProto"; option java_outer_classname = "UnittestLazyImportsCustomOptionProto";
message LazyMessage { message LazyMessage {
optional int32 a = 1; int32 a = 1;
} }
extend google.protobuf.MessageOptions { extend google.protobuf.MessageOptions {
optional LazyEnum lazy_enum_option = 138596335 [default = LAZY_ENUM_1]; LazyEnum lazy_enum_option = 138596335 [default = LAZY_ENUM_1];
} }

@ -34,7 +34,10 @@
// //
// A proto file we will use for unit testing. // A proto file we will use for unit testing.
syntax = "proto2"; edition = "2023";
// Treat all enums as closed by default (proto2 behavior).
option features.enum_type = CLOSED;
// Some generic_services option(s) added automatically. // Some generic_services option(s) added automatically.
// See: http://go/proto2-generic-services-default // See: http://go/proto2-generic-services-default

@ -30,7 +30,10 @@
// A proto file used to test a message type with no explicit field presence. // A proto file used to test a message type with no explicit field presence.
syntax = "proto3"; edition = "2023";
// Treat all fields as implicit present by default (proto3 behavior).
option features.field_presence = IMPLICIT;
// We want to test embedded proto2 messages, so include some proto2 types. // We want to test embedded proto2 messages, so include some proto2 types.
package proto2_nofieldpresence_unittest; package proto2_nofieldpresence_unittest;

@ -28,10 +28,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto3"; edition = "2023";
package proto3_preserve_unknown_enum_unittest; package proto3_preserve_unknown_enum_unittest;
// Treat all fields as implicit present by default (proto3 behavior).
option features.field_presence = IMPLICIT;
option objc_class_prefix = "UnknownEnums"; option objc_class_prefix = "UnknownEnums";
option csharp_namespace = "Google.Protobuf.TestProtos"; option csharp_namespace = "Google.Protobuf.TestProtos";
@ -51,7 +53,7 @@ enum MyEnumPlusExtra {
message MyMessage { message MyMessage {
MyEnum e = 1; MyEnum e = 1;
repeated MyEnum repeated_e = 2; repeated MyEnum repeated_e = 2;
repeated MyEnum repeated_packed_e = 3 [packed = true]; repeated MyEnum repeated_packed_e = 3;
repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4; // not packed repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4; // not packed
oneof o { oneof o {
MyEnum oneof_e_1 = 5; MyEnum oneof_e_1 = 5;
@ -62,8 +64,8 @@ message MyMessage {
message MyMessagePlusExtra { message MyMessagePlusExtra {
MyEnumPlusExtra e = 1; MyEnumPlusExtra e = 1;
repeated MyEnumPlusExtra repeated_e = 2; repeated MyEnumPlusExtra repeated_e = 2;
repeated MyEnumPlusExtra repeated_packed_e = 3 [packed = true]; repeated MyEnumPlusExtra repeated_packed_e = 3;
repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4 [packed = true]; repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4;
oneof o { oneof o {
MyEnumPlusExtra oneof_e_1 = 5; MyEnumPlusExtra oneof_e_1 = 5;
MyEnumPlusExtra oneof_e_2 = 6; MyEnumPlusExtra oneof_e_2 = 6;

@ -28,10 +28,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto2"; edition = "2023";
package proto2_preserve_unknown_enum_unittest; package proto2_preserve_unknown_enum_unittest;
// Treat all enums as closed and use expanded encoding for repeated fields by
// default (proto2 behavior).
option features.enum_type = CLOSED;
option features.repeated_field_encoding = EXPANDED;
enum MyEnum { enum MyEnum {
FOO = 0; FOO = 0;
BAR = 1; BAR = 1;
@ -39,9 +44,10 @@ enum MyEnum {
} }
message MyMessage { message MyMessage {
optional MyEnum e = 1; MyEnum e = 1;
repeated MyEnum repeated_e = 2; repeated MyEnum repeated_e = 2;
repeated MyEnum repeated_packed_e = 3 [packed = true]; repeated MyEnum repeated_packed_e = 3
[features.repeated_field_encoding = PACKED];
repeated MyEnum repeated_packed_unexpected_e = 4; // not packed repeated MyEnum repeated_packed_unexpected_e = 4; // not packed
oneof o { oneof o {
MyEnum oneof_e_1 = 5; MyEnum oneof_e_1 = 5;

Loading…
Cancel
Save