Skip to content

Commit

Permalink
Add editions-specific conformance tests
Browse files Browse the repository at this point in the history
For now, these are limited to tests of text-form for delimited fields that locks down our problematic behavior in editions.  Follow up changes will adjust the behavior to behave better under editions.

PiperOrigin-RevId: 622211473
  • Loading branch information
mkruskal-google authored and Copybara-Service committed Apr 5, 2024
1 parent 7ab65a0 commit 8ab39ed
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 33 deletions.
16 changes: 12 additions & 4 deletions cmake/conformance.cmake
Expand Up @@ -18,10 +18,16 @@ add_custom_command(
OUTPUT
${protobuf_BINARY_DIR}/conformance/conformance.pb.h
${protobuf_BINARY_DIR}/conformance/conformance.pb.cc
DEPENDS ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/conformance/conformance.proto
COMMAND ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/conformance/conformance.proto
--proto_path=${protobuf_SOURCE_DIR}/conformance
--cpp_out=${protobuf_BINARY_DIR}/conformance
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.h
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.cc
DEPENDS ${protobuf_PROTOC_EXE}
${protobuf_SOURCE_DIR}/conformance/conformance.proto
${protobuf_SOURCE_DIR}/conformance/test_protos/test_messages_edition2023.proto
COMMAND ${protobuf_PROTOC_EXE}
${protobuf_SOURCE_DIR}/conformance/conformance.proto
${protobuf_SOURCE_DIR}/conformance/test_protos/test_messages_edition2023.proto
--proto_path=${protobuf_SOURCE_DIR}
--cpp_out=${protobuf_BINARY_DIR}
)

file(MAKE_DIRECTORY ${protobuf_BINARY_DIR}/src)
Expand Down Expand Up @@ -53,6 +59,8 @@ add_custom_command(
add_library(libconformance_common STATIC
${protobuf_BINARY_DIR}/conformance/conformance.pb.h
${protobuf_BINARY_DIR}/conformance/conformance.pb.cc
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.h
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.cc
${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto2.pb.h
${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto2.pb.cc
${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto3.pb.h
Expand Down
9 changes: 8 additions & 1 deletion conformance/BUILD.bazel
Expand Up @@ -29,7 +29,6 @@ exports_files([
"failure_list_jruby.txt",
"failure_list_jruby_ffi.txt",
"text_format_failure_list_cpp.txt",
"text_format_failure_list_csharp.txt",
"text_format_failure_list_java.txt",
"text_format_failure_list_java_lite.txt",
"text_format_failure_list_php.txt",
Expand Down Expand Up @@ -191,6 +190,7 @@ cc_library(
":conformance_test",
":test_messages_proto2_proto_cc",
":test_messages_proto3_proto_cc",
"//conformance/test_protos:test_messages_edition2023_cc_proto",
"//src/google/protobuf",
"//src/google/protobuf/editions:test_messages_proto2_editions_cc_proto",
"//src/google/protobuf/editions:test_messages_proto3_editions_cc_proto",
Expand Down Expand Up @@ -224,6 +224,7 @@ cc_binary(
"//:protobuf",
"//:test_messages_proto2_cc_proto",
"//:test_messages_proto3_cc_proto",
"//conformance/test_protos:test_messages_edition2023_cc_proto",
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf:protobuf_lite",
Expand Down Expand Up @@ -254,6 +255,7 @@ java_binary(
"//:protobuf_java_util",
"//:test_messages_proto2_java_proto",
"//:test_messages_proto3_java_proto",
"//conformance/test_protos:test_messages_edition2023_java_proto",
"//src/google/protobuf/editions:test_messages_proto2_editions_java_proto",
"//src/google/protobuf/editions:test_messages_proto3_editions_java_proto",
],
Expand All @@ -273,6 +275,7 @@ java_binary(
"//:protobuf_javalite",
"//:test_messages_proto2_java_proto_lite",
"//:test_messages_proto3_java_proto_lite",
"//conformance/test_protos:test_messages_edition2023_java_proto_lite",
"//src/google/protobuf/editions:test_messages_proto2_editions_java_proto_lite",
"//src/google/protobuf/editions:test_messages_proto3_editions_java_proto_lite",
],
Expand All @@ -291,6 +294,7 @@ py_binary(
deps = [
":conformance_py_proto",
"//:protobuf_python",
"//conformance/test_protos:test_messages_edition2023_py_proto",
"//python:_message", # Make upb visible if we need it.
"//python:conformance_test_py_proto",
],
Expand Down Expand Up @@ -342,6 +346,7 @@ inline_sh_binary(
cmd = "dotnet $(rootpath //csharp/src/Google.Protobuf.Conformance:conformance_dll)",
visibility = ["//csharp:__subpackages__"],
deps = [
"//conformance/test_protos:test_messages_edition2023_csharp_proto",
"//csharp/src/Google.Protobuf.Conformance:conformance_runfiles",
],
)
Expand All @@ -356,6 +361,7 @@ objc_library(
":conformance_objc_proto",
"//:test_messages_proto2_objc_proto",
"//:test_messages_proto3_objc_proto",
"//conformance/test_protos:test_messages_edition2023_objc_proto",
"//src/google/protobuf/editions:test_messages_proto2_editions_objc_proto",
"//src/google/protobuf/editions:test_messages_proto3_editions_objc_proto",
],
Expand All @@ -377,6 +383,7 @@ ruby_binary(
visibility = ["//ruby:__subpackages__"],
deps = [
":conformance_ruby_proto",
"//conformance/test_protos:test_messages_edition2023_ruby_proto",
"//ruby:conformance_test_ruby_proto",
"//ruby:protobuf",
],
Expand Down
6 changes: 6 additions & 0 deletions conformance/ConformanceJava.java
Expand Up @@ -15,6 +15,8 @@
import com.google.protobuf.conformance.Conformance;
import com.google.protobuf.util.JsonFormat;
import com.google.protobuf.util.JsonFormat.TypeRegistry;
import com.google.protobuf_test_messages.edition2023.TestAllTypesEdition2023;
import com.google.protobuf_test_messages.edition2023.TestMessagesEdition2023;
import com.google.protobuf_test_messages.editions.proto2.TestMessagesProto2Editions;
import com.google.protobuf_test_messages.editions.proto3.TestMessagesProto3Editions;
import com.google.protobuf_test_messages.proto2.TestMessagesProto2;
Expand Down Expand Up @@ -213,6 +215,8 @@ private Class<? extends AbstractMessage> createTestMessage(String messageType) {
return TestAllTypesProto3.class;
case "protobuf_test_messages.proto2.TestAllTypesProto2":
return TestAllTypesProto2.class;
case "protobuf_test_messages.editions.TestAllTypesEdition2023":
return TestAllTypesEdition2023.class;
case "protobuf_test_messages.editions.proto3.TestAllTypesProto3":
return TestMessagesProto3Editions.TestAllTypesProto3.class;
case "protobuf_test_messages.editions.proto2.TestAllTypesProto2":
Expand All @@ -229,6 +233,8 @@ private Class<?> createTestFile(String messageType) {
return TestMessagesProto3.class;
case "protobuf_test_messages.proto2.TestAllTypesProto2":
return TestMessagesProto2.class;
case "protobuf_test_messages.editions.TestAllTypesEdition2023":
return TestMessagesEdition2023.class;
case "protobuf_test_messages.editions.proto3.TestAllTypesProto3":
return TestMessagesProto3Editions.class;
case "protobuf_test_messages.editions.proto2.TestAllTypesProto2":
Expand Down
10 changes: 8 additions & 2 deletions conformance/ConformanceJavaLite.java
Expand Up @@ -13,11 +13,13 @@
import com.google.protobuf.MessageLite;
import com.google.protobuf.Parser;
import com.google.protobuf.conformance.Conformance;
import com.google.protobuf_test_messages.edition2023.TestAllTypesEdition2023;
import com.google.protobuf_test_messages.edition2023.TestMessagesEdition2023;
import com.google.protobuf_test_messages.editions.proto2.TestMessagesProto2Editions;
import com.google.protobuf_test_messages.editions.proto3.TestMessagesProto3Editions;
import com.google.protobuf_test_messages.proto2.TestMessagesProto2;
import com.google.protobuf_test_messages.proto2.TestMessagesProto2.TestAllTypesProto2;
import com.google.protobuf_test_messages.proto3.TestMessagesProto3;
import com.google.protobuf_test_messages.editions.proto2.TestMessagesProto2Editions;
import com.google.protobuf_test_messages.editions.proto3.TestMessagesProto3Editions;
import com.google.protobuf_test_messages.proto3.TestMessagesProto3.TestAllTypesProto3;
import java.nio.ByteBuffer;
import java.util.ArrayList;
Expand Down Expand Up @@ -212,6 +214,8 @@ private Class<? extends AbstractMessageLite> createTestMessage(String messageTyp
return TestAllTypesProto3.class;
case "protobuf_test_messages.proto2.TestAllTypesProto2":
return TestAllTypesProto2.class;
case "protobuf_test_messages.edition2023.TestAllTypesEdition2023":
return TestAllTypesEdition2023.class;
case "protobuf_test_messages.editions.proto3.TestAllTypesProto3":
return TestMessagesProto3Editions.TestAllTypesProto3.class;
case "protobuf_test_messages.editions.proto2.TestAllTypesProto2":
Expand All @@ -228,6 +232,8 @@ private Class<?> createTestFile(String messageType) {
return TestMessagesProto3.class;
case "protobuf_test_messages.proto2.TestAllTypesProto2":
return TestMessagesProto2.class;
case "protobuf_test_messages.edition2023.TestAllTypesEdition2023":
return TestMessagesEdition2023.class;
case "protobuf_test_messages.editions.proto3.TestAllTypesProto3":
return TestMessagesProto3Editions.class;
case "protobuf_test_messages.editions.proto2.TestAllTypesProto2":
Expand Down
3 changes: 3 additions & 0 deletions conformance/conformance_cpp.cc
Expand Up @@ -23,6 +23,7 @@
#include "absl/strings/str_cat.h"
#include "conformance/conformance.pb.h"
#include "conformance/conformance.pb.h"
#include "conformance/test_protos/test_messages_edition2023.pb.h"
#include "google/protobuf/editions/golden/test_messages_proto2_editions.pb.h"
#include "google/protobuf/editions/golden/test_messages_proto3_editions.pb.h"
#include "google/protobuf/endian.h"
Expand All @@ -47,6 +48,7 @@ using ::google::protobuf::util::JsonParseOptions;
using ::google::protobuf::util::JsonToBinaryString;
using ::google::protobuf::util::NewTypeResolverForDescriptorPool;
using ::google::protobuf::util::TypeResolver;
using ::protobuf_test_messages::editions::TestAllTypesEdition2023;
using ::protobuf_test_messages::proto2::TestAllTypesProto2;
using ::protobuf_test_messages::proto3::TestAllTypesProto3;
using TestAllTypesProto2Editions =
Expand Down Expand Up @@ -84,6 +86,7 @@ class Harness {
Harness() {
google::protobuf::LinkMessageReflection<TestAllTypesProto2>();
google::protobuf::LinkMessageReflection<TestAllTypesProto3>();
google::protobuf::LinkMessageReflection<TestAllTypesEdition2023>();
google::protobuf::LinkMessageReflection<TestAllTypesProto2Editions>();
google::protobuf::LinkMessageReflection<TestAllTypesProto3Editions>();

Expand Down
3 changes: 3 additions & 0 deletions conformance/conformance_objc.m
Expand Up @@ -12,6 +12,7 @@
#import "google/protobuf/TestMessagesProto3.pbobjc.h"
#import "google/protobuf/editions/golden/TestMessagesProto2Editions.pbobjc.h"
#import "google/protobuf/editions/golden/TestMessagesProto3Editions.pbobjc.h"
#import "test_protos/TestMessagesEdition2023.pbobjc.h"

static void Die(NSString *format, ...) __dead2;

Expand Down Expand Up @@ -54,6 +55,8 @@ static void Die(NSString *format, ...) {
NSDictionary *mappings = @{
@"protobuf_test_messages.proto2.TestAllTypesProto2" : [Proto2TestAllTypesProto2 class],
@"protobuf_test_messages.proto3.TestAllTypesProto3" : [Proto3TestAllTypesProto3 class],
@"protobuf_test_messages.editions.TestAllTypesEdition2023" :
[EditionsTestAllTypesEdition2023 class],
@"protobuf_test_messages.editions.proto2.TestAllTypesProto2" :
[EditionsProto2TestAllTypesProto2 class],
@"protobuf_test_messages.editions.proto3.TestAllTypesProto3" :
Expand Down
3 changes: 3 additions & 0 deletions conformance/conformance_python.py
Expand Up @@ -19,6 +19,7 @@
from google.protobuf import test_messages_proto2_pb2
from google.protobuf import test_messages_proto3_pb2
from conformance import conformance_pb2
from conformance.test_protos import test_messages_edition2023_pb2
from google.protobuf.editions.golden import test_messages_proto2_editions_pb2
from google.protobuf.editions.golden import test_messages_proto3_editions_pb2

Expand All @@ -35,6 +36,8 @@ def _create_test_message(type):
return test_messages_proto2_pb2.TestAllTypesProto2()
if type == "protobuf_test_messages.proto3.TestAllTypesProto3":
return test_messages_proto3_pb2.TestAllTypesProto3()
if type == "protobuf_test_messages.editions.TestAllTypesEdition2023":
return test_messages_edition2023_pb2.TestAllTypesEdition2023()
if type == "protobuf_test_messages.editions.proto2.TestAllTypesProto2":
return test_messages_proto2_editions_pb2.TestAllTypesProto2()
if type == "protobuf_test_messages.editions.proto3.TestAllTypesProto3":
Expand Down
2 changes: 2 additions & 0 deletions conformance/conformance_ruby.rb
Expand Up @@ -8,6 +8,7 @@
# https://developers.google.com/open-source/licenses/bsd

require 'conformance/conformance_pb'
require 'conformance/test_protos/test_messages_edition2023_pb'
require 'google/protobuf'
require 'google/protobuf/test_messages_proto3_pb'
require 'google/protobuf/test_messages_proto2_pb'
Expand All @@ -24,6 +25,7 @@ def do_test(request)

unless descriptor
response.runtime_error = "Unknown message type: " + request.message_type
return response
end

if request.test_category == :TEXT_FORMAT_TEST
Expand Down
9 changes: 9 additions & 0 deletions conformance/conformance_rust.rs
Expand Up @@ -15,6 +15,7 @@ use protobuf_upb as kernel;
use kernel::Optional::{Set, Unset};

use std::io::{self, ErrorKind, Read, Write};
use test_messages_edition2023_proto::TestAllTypesEdition2023;
use test_messages_proto2::TestAllTypesProto2;
use test_messages_proto2_editions_proto::TestAllTypesProto2 as EditionsTestAllTypesProto2;
use test_messages_proto3::TestAllTypesProto3;
Expand Down Expand Up @@ -89,6 +90,14 @@ fn do_test(req: &ConformanceRequest) -> ConformanceResponse {
return resp;
}
}
b"protobuf_test_messages.editions.TestAllTypesEdition2023" => {
if let Ok(msg) = TestAllTypesEdition2023::parse(bytes) {
msg.serialize()
} else {
resp.set_parse_error("failed to parse bytes");
return resp;
}
}
b"protobuf_test_messages.editions.proto2.TestAllTypesProto2" => {
if let Ok(msg) = EditionsTestAllTypesProto2::parse(bytes) {
msg.serialize()
Expand Down
18 changes: 18 additions & 0 deletions conformance/failure_list_csharp.txt
Expand Up @@ -15,3 +15,21 @@ Recommended.Proto3.ValueRejectInfNumberValue.JsonOutput
Recommended.Proto3.ValueRejectNanNumberValue.JsonOutput
Required.Proto2.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.Proto3.ProtobufInput.UnknownOrdering.ProtobufOutput

Recommended.Editions_Proto2.JsonInput.FieldNameExtension.Validator
Recommended.Editions_Proto2.JsonInput.BytesFieldBase64Url.JsonOutput
Recommended.Editions_Proto2.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.Editions_Proto3.JsonInput.BytesFieldBase64Url.JsonOutput
Recommended.Editions_Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Required.Editions_Proto2.JsonInput.OneofFieldNullFirst.JsonOutput
Required.Editions_Proto2.JsonInput.OneofFieldNullFirst.ProtobufOutput
Required.Editions_Proto2.JsonInput.OneofFieldNullSecond.JsonOutput
Required.Editions_Proto2.JsonInput.OneofFieldNullSecond.ProtobufOutput
Required.Editions_Proto3.JsonInput.OneofFieldNullFirst.JsonOutput
Required.Editions_Proto3.JsonInput.OneofFieldNullFirst.ProtobufOutput
Required.Editions_Proto3.JsonInput.OneofFieldNullSecond.JsonOutput
Required.Editions_Proto3.JsonInput.OneofFieldNullSecond.ProtobufOutput
Recommended.Editions_Proto3.ValueRejectInfNumberValue.JsonOutput
Recommended.Editions_Proto3.ValueRejectNanNumberValue.JsonOutput
Required.Editions_Proto2.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.Editions_Proto3.ProtobufInput.UnknownOrdering.ProtobufOutput
50 changes: 50 additions & 0 deletions conformance/test_protos/BUILD.bazel
@@ -0,0 +1,50 @@
load("@rules_cc//cc:defs.bzl", "cc_proto_library", "objc_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_py_proto_library")
load("//ruby:defs.bzl", "internal_ruby_proto_library")

package(
default_testonly = True,
default_visibility = ["//conformance:__pkg__"],
)

proto_library(
name = "test_messages_edition2023_proto",
srcs = ["test_messages_edition2023.proto"],
visibility = ["//visibility:public"],
)

cc_proto_library(
name = "test_messages_edition2023_cc_proto",
deps = [":test_messages_edition2023_proto"],
)

internal_csharp_proto_library(
name = "test_messages_edition2023_csharp_proto",
srcs = ["test_messages_edition2023.proto"],
)

java_proto_library(
name = "test_messages_edition2023_java_proto",
deps = [":test_messages_edition2023_proto"],
)

java_lite_proto_library(
name = "test_messages_edition2023_java_proto_lite",
deps = [":test_messages_edition2023_proto"],
)

internal_py_proto_library(
name = "test_messages_edition2023_py_proto",
srcs = ["test_messages_edition2023.proto"],
srcs_version = "PY2AND3",
)

internal_objc_proto_library(
name = "test_messages_edition2023_objc_proto",
srcs = ["test_messages_edition2023.proto"],
)

internal_ruby_proto_library(
name = "test_messages_edition2023_ruby_proto",
srcs = ["test_messages_edition2023.proto"],
)

0 comments on commit 8ab39ed

Please sign in to comment.