Skip to content

Commit

Permalink
Merge branch 'main' into php-editions
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored May 2, 2024
2 parents e06a8db + 05afdc2 commit 0814036
Show file tree
Hide file tree
Showing 139 changed files with 3,687 additions and 4,776 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ on:
permissions:
contents: read

concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: ${{ contains(fromJSON('["pull_request", "pull_request_target", "workflow_dispatch"]'), github.event_name) }}

jobs:
check-tag:
name: Check for Safety
Expand Down
7 changes: 0 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,6 @@ http_archive(
patch_cmds = ["find google -type f -name BUILD.bazel -delete"],
)

load("//python/dist:system_python.bzl", "system_python")

system_python(
name = "system_python",
minimum_python_version = "3.7",
)

load("@system_python//:pip.bzl", "pip_parse")

pip_parse(
Expand Down
4 changes: 2 additions & 2 deletions conformance/conformance_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ConformanceResponse doTest(ConformanceRequest request) {
switch (request.requestedOutputFormat) {
case WireFormat.PROTOBUF:
try {
response.protobufPayload = pb.GeneratedMessage.toBuffer(testMessage);
response.protobufPayload = pb.GeneratedMessage.toBinary(testMessage);
} catch (e) {
response.serializeError = '$e';
}
Expand All @@ -86,7 +86,7 @@ Future<bool> doTestIo() async {
}
final request = ConformanceRequest.fromBuffer(serializedMsg);
final response = doTest(request);
final serializedOutput = pb.GeneratedMessage.toBuffer(response);
final serializedOutput = pb.GeneratedMessage.toBinary(response);
writeLittleEndianIntToStdout(serializedOutput.length);
stdout.add(serializedOutput);
await stdout.flush();
Expand Down
255 changes: 233 additions & 22 deletions conformance/text_format_conformance_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <cstddef>
#include <string>
#include <utility>
#include <vector>

#include "absl/log/absl_log.h"
Expand Down Expand Up @@ -321,6 +322,44 @@ void TextFormatConformanceTestSuiteImpl<MessageType>::RunAllTests() {
"optional_int64: -9223372036854775808");
RunValidTextFormatTest("Uint64FieldMaxValue", REQUIRED,
"optional_uint64: 18446744073709551615");
// Integer fields - Hex
RunValidTextFormatTestWithExpected("Int32FieldMaxValueHex", REQUIRED,
"optional_int32: 0x7FFFFFFF",
"optional_int32: 2147483647");
RunValidTextFormatTestWithExpected("Int32FieldMinValueHex", REQUIRED,
"optional_int32: -0x80000000",
"optional_int32: -2147483648");
RunValidTextFormatTestWithExpected("Uint32FieldMaxValueHex", REQUIRED,
"optional_uint32: 0xFFFFFFFF",
"optional_uint32: 4294967295");
RunValidTextFormatTestWithExpected("Int64FieldMaxValueHex", REQUIRED,
"optional_int64: 0x7FFFFFFFFFFFFFFF",
"optional_int64: 9223372036854775807");
RunValidTextFormatTestWithExpected("Int64FieldMinValueHex", REQUIRED,
"optional_int64: -0x8000000000000000",
"optional_int64: -9223372036854775808");
RunValidTextFormatTestWithExpected("Uint64FieldMaxValueHex", REQUIRED,
"optional_uint64: 0xFFFFFFFFFFFFFFFF",
"optional_uint64: 18446744073709551615");
// Integer fields - Octal
RunValidTextFormatTestWithExpected("Int32FieldMaxValueOctal", REQUIRED,
"optional_int32: 017777777777",
"optional_int32: 2147483647");
RunValidTextFormatTestWithExpected("Int32FieldMinValueOctal", REQUIRED,
"optional_int32: -020000000000",
"optional_int32: -2147483648");
RunValidTextFormatTestWithExpected("Uint32FieldMaxValueOctal", REQUIRED,
"optional_uint32: 037777777777",
"optional_uint32: 4294967295");
RunValidTextFormatTestWithExpected("Int64FieldMaxValueOctal", REQUIRED,
"optional_int64: 0777777777777777777777",
"optional_int64: 9223372036854775807");
RunValidTextFormatTestWithExpected("Int64FieldMinValueOctal", REQUIRED,
"optional_int64: -01000000000000000000000",
"optional_int64: -9223372036854775808");
RunValidTextFormatTestWithExpected("Uint64FieldMaxValueOctal", REQUIRED,
"optional_uint64: 01777777777777777777777",
"optional_uint64: 18446744073709551615");

// Parsers reject out-of-bound integer values.
ExpectParseFailure("Int32FieldTooLarge", REQUIRED,
Expand All @@ -335,30 +374,113 @@ void TextFormatConformanceTestSuiteImpl<MessageType>::RunAllTests() {
"optional_int64: -9223372036854775809");
ExpectParseFailure("Uint64FieldTooLarge", REQUIRED,
"optional_uint64: 18446744073709551616");
// Parsers reject out-of-bound integer values - Hex
ExpectParseFailure("Int32FieldTooLargeHex", REQUIRED,
"optional_int32: 0x80000000");
ExpectParseFailure("Int32FieldTooSmallHex", REQUIRED,
"optional_int32: -0x80000001");
ExpectParseFailure("Uint32FieldTooLargeHex", REQUIRED,
"optional_uint32: 0x100000000");
ExpectParseFailure("Int64FieldTooLargeHex", REQUIRED,
"optional_int64: 0x8000000000000000");
ExpectParseFailure("Int64FieldTooSmallHex", REQUIRED,
"optional_int64: -0x8000000000000001");
ExpectParseFailure("Uint64FieldTooLargeHex", REQUIRED,
"optional_uint64: 0x10000000000000000");
// Parsers reject out-of-bound integer values - Octal
ExpectParseFailure("Int32FieldTooLargeOctal", REQUIRED,
"optional_int32: 020000000000");
ExpectParseFailure("Int32FieldTooSmallOctal", REQUIRED,
"optional_int32: -020000000001");
ExpectParseFailure("Uint32FieldTooLargeOctal", REQUIRED,
"optional_uint32: 040000000000");
ExpectParseFailure("Int64FieldTooLargeOctal", REQUIRED,
"optional_int64: 01000000000000000000000");
ExpectParseFailure("Int64FieldTooSmallOctal", REQUIRED,
"optional_int64: -01000000000000000000001");
ExpectParseFailure("Uint64FieldTooLargeOctal", REQUIRED,
"optional_uint64: 02000000000000000000000");

// Floating point fields
RunValidTextFormatTest("FloatField", REQUIRED, "optional_float: 3.192837");
RunValidTextFormatTest("FloatFieldWithVeryPreciseNumber", REQUIRED,
"optional_float: 3.123456789123456789");
RunValidTextFormatTest("FloatFieldMaxValue", REQUIRED,
"optional_float: 3.4028235e+38");
RunValidTextFormatTest("FloatFieldMinValue", REQUIRED,
"optional_float: 1.17549e-38");
RunValidTextFormatTest("FloatFieldNaNValue", REQUIRED, "optional_float: NaN");
RunValidTextFormatTest("FloatFieldPosInfValue", REQUIRED,
"optional_float: inf");
RunValidTextFormatTest("FloatFieldNegInfValue", REQUIRED,
"optional_float: -inf");
RunValidTextFormatTest("FloatFieldWithInt32Max", REQUIRED,
"optional_float: 4294967296");
RunValidTextFormatTest("FloatFieldLargerThanInt64", REQUIRED,
"optional_float: 9223372036854775808");
RunValidTextFormatTest("FloatFieldTooLarge", REQUIRED,
"optional_float: 3.4028235e+39");
RunValidTextFormatTest("FloatFieldTooSmall", REQUIRED,
"optional_float: 1.17549e-39");
RunValidTextFormatTest("FloatFieldLargerThanUint64", REQUIRED,
"optional_float: 18446744073709551616");
for (const auto& suffix : std::vector<std::string>{"", "f", "F"}) {
const std::string name_suffix =
suffix.empty() ? "" : absl::StrCat("_", suffix);

RunValidTextFormatTest(absl::StrCat("FloatField", name_suffix), REQUIRED,
absl::StrCat("optional_float: 3.192837", suffix));
RunValidTextFormatTestWithExpected(
absl::StrCat("FloatFieldZero", name_suffix), REQUIRED,
absl::StrCat("optional_float: 0", suffix),
"" /* implicit presence, so zero means unset*/);
RunValidTextFormatTest(absl::StrCat("FloatFieldNegative", name_suffix),
REQUIRED,
absl::StrCat("optional_float: -3.192837", suffix));
RunValidTextFormatTest(
absl::StrCat("FloatFieldWithVeryPreciseNumber", name_suffix), REQUIRED,
absl::StrCat("optional_float: 3.123456789123456789", suffix));
RunValidTextFormatTest(
absl::StrCat("FloatFieldMaxValue", name_suffix), REQUIRED,
absl::StrCat("optional_float: 3.4028235e+38", suffix));
RunValidTextFormatTest(absl::StrCat("FloatFieldMinValue", name_suffix),
REQUIRED,
absl::StrCat("optional_float: 1.17549e-38", suffix));
RunValidTextFormatTest(absl::StrCat("FloatFieldWithInt32Max", name_suffix),
REQUIRED,
absl::StrCat("optional_float: 4294967296", suffix));
RunValidTextFormatTest(
absl::StrCat("FloatFieldLargerThanInt64", name_suffix), REQUIRED,
absl::StrCat("optional_float: 9223372036854775808", suffix));
RunValidTextFormatTest(
absl::StrCat("FloatFieldTooLarge", name_suffix), REQUIRED,
absl::StrCat("optional_float: 3.4028235e+39", suffix));
RunValidTextFormatTest(absl::StrCat("FloatFieldTooSmall", name_suffix),
REQUIRED,
absl::StrCat("optional_float: 1.17549e-39", suffix));
RunValidTextFormatTest(
absl::StrCat("FloatFieldLargerThanUint64", name_suffix), REQUIRED,
absl::StrCat("optional_float: 18446744073709551616", suffix));
// https://protobuf.dev/reference/protobuf/textformat-spec/#literals says
// "-0" is a valid float literal.
// TODO: Figure out if this should count as not setting
// presence or if -0 should be reflected back.
// RunValidTextFormatTestWithExpected(
// absl::StrCat("FloatFieldNegativeZero", name_suffix), REQUIRED,
// absl::StrCat("optional_float: -0", suffix),
// "" /* implicit presence, so zero means unset*/);
// https://protobuf.dev/reference/protobuf/textformat-spec/#literals says
// ".123", "-.123", ".123e2" are a valid float literal.
RunValidTextFormatTest(absl::StrCat("FloatFieldNoLeadingZero", name_suffix),
REQUIRED,
absl::StrCat("optional_float: .123", suffix));
RunValidTextFormatTest(
absl::StrCat("FloatFieldNegativeNoLeadingZero", name_suffix), REQUIRED,
absl::StrCat("optional_float: -.123", suffix));
RunValidTextFormatTest(
absl::StrCat("FloatFieldNoLeadingZeroWithExponent", name_suffix),
REQUIRED, absl::StrCat("optional_float: .123e2", suffix));
}
// https://protobuf.dev/reference/protobuf/textformat-spec/#value say case
// doesn't matter for special values, test a few
for (const auto& value : std::vector<std::string>{"nan", "NaN", "nAn"}) {
RunValidTextFormatTest(absl::StrCat("FloatFieldValue_", value), REQUIRED,
absl::StrCat("optional_float: ", value));
}
for (const auto& value : std::vector<std::string>{
"inf", "infinity", "INF", "INFINITY", "iNF", "inFINITY"}) {
RunValidTextFormatTest(absl::StrCat("FloatFieldValue_Pos", value), REQUIRED,
absl::StrCat("optional_float: ", value));
RunValidTextFormatTest(absl::StrCat("FloatFieldValue_Neg", value), REQUIRED,
absl::StrCat("optional_float: -", value));
}
// https://protobuf.dev/reference/protobuf/textformat-spec/#numeric and
// https://protobuf.dev/reference/protobuf/textformat-spec/#value says
// hex or octal float literals are invalid.
ExpectParseFailure("FloatFieldNoHex", REQUIRED, "optional_float: 0x1");
ExpectParseFailure("FloatFieldNoNegativeHex", REQUIRED,
"optional_float: -0x1");
ExpectParseFailure("FloatFieldNoOctal", REQUIRED, "optional_float: 012");
ExpectParseFailure("FloatFieldNoNegativeOctal", REQUIRED,
"optional_float: -012");

// String literals x {Strings, Bytes}
for (const auto& field_type : std::vector<std::string>{"String", "Bytes"}) {
Expand Down Expand Up @@ -438,6 +560,95 @@ void TextFormatConformanceTestSuiteImpl<MessageType>::RunAllTests() {
absl::StrCat(field_name, ": '\\xc0'"));
}

// Separators
for (const auto& test_case : std::vector<std::pair<std::string, std::string>>{
{"string", "\"abc\""},
{"bytes", "\"abc\""},
{"int32", "123"},
{"bool", "true"},
{"double", "1.23"},
{"fixed32", "0x123"},
}) {
// Optional Field Separators
for (const auto& field_type :
std::vector<std::string>{"Single", "Repeated"}) {
std::string field_name, field_value;
if (field_type == "Single") {
field_name = absl::StrCat("optional_", test_case.first);
field_value = test_case.second;
} else {
field_name = absl::StrCat("repeated_", test_case.first);
field_value = absl::StrCat("[", test_case.second, "]");
}

RunValidTextFormatTest(absl::StrCat("FieldSeparatorCommaTopLevel",
field_type, "_", test_case.first),
REQUIRED,
absl::StrCat(field_name, ": ", field_value, ","));
RunValidTextFormatTest(absl::StrCat("FieldSeparatorSemiTopLevelSingle",
field_type, "_", test_case.first),
REQUIRED,
absl::StrCat(field_name, ": ", field_value, ";"));

ExpectParseFailure(
absl::StrCat("FieldSeparatorCommaTopLevelDuplicatesFails", field_type,
"_", test_case.first),
REQUIRED, absl::StrCat(field_name, ": ", field_value, ",,"));
ExpectParseFailure(
absl::StrCat("FieldSeparatorSemiTopLevelDuplicateFails", field_type,
"_", test_case.first),
REQUIRED, absl::StrCat(field_name, ": ", field_value, ";;"));
}

// Required List Separators
RunValidTextFormatTest(
absl::StrCat("ListSeparator_", test_case.first), REQUIRED,
absl::StrCat("repeated_", test_case.first, ": [", test_case.second, ",",
test_case.second, "]"));
ExpectParseFailure(
absl::StrCat("ListSeparatorSemiFails_", test_case.first), REQUIRED,
absl::StrCat("repeated_", test_case.first, ": [", test_case.second, ";",
test_case.second, "]"));
// For string and bytes, if we skip the separator, the parser will treat
// the two values as a single value.
if (test_case.first == "string" || test_case.first == "bytes") {
RunValidTextFormatTest(
absl::StrCat("ListSeparatorMissingIsOneValue_", test_case.first),
REQUIRED,
absl::StrCat("repeated_", test_case.first, ": [", test_case.second,
" ", test_case.second, "]"));
} else {
ExpectParseFailure(
absl::StrCat("ListSeparatorMissingFails_", test_case.first), REQUIRED,
absl::StrCat("repeated_", test_case.first, ": [", test_case.second,
" ", test_case.second, "]"));
}
ExpectParseFailure(
absl::StrCat("ListSeparatorDuplicateFails_", test_case.first), REQUIRED,
absl::StrCat("repeated_", test_case.first, ": [", test_case.second,
",,", test_case.second, "]"));
ExpectParseFailure(
absl::StrCat("ListSeparatorSingleTrailingFails_", test_case.first),
REQUIRED,
absl::StrCat("repeated_", test_case.first, ": [", test_case.second,
",]"));
ExpectParseFailure(
absl::StrCat("ListSeparatorTwoValuesTrailingFails_", test_case.first),
REQUIRED,
absl::StrCat("repeated_", test_case.first, ": [", test_case.second, ",",
test_case.second, ",]"));
}
// The test message don't really have all types nested, so just check one
// data type for the nested field separator support
RunValidTextFormatTest("FieldSeparatorCommaNested", REQUIRED,
"optional_nested_message: { a: 123, }");
RunValidTextFormatTest("FieldSeparatorSemiNested", REQUIRED,
"optional_nested_message: { a: 123; }");
ExpectParseFailure("FieldSeparatorCommaNestedDuplicates", REQUIRED,
"optional_nested_message: { a: 123,, }");
ExpectParseFailure("FieldSeparatorSemiNestedDuplicates", REQUIRED,
"optional_nested_message: { a: 123;; }");

// Unknown Fields
UnknownToTestAllTypes message;
// Unable to print unknown Fixed32/Fixed64 fields as if they are known.
Expand Down
21 changes: 12 additions & 9 deletions conformance/text_format_failure_list_java.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
Recommended.Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput
Recommended.Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput
Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput
Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput
Required.Proto3.TextFormatInput.AnyField.ProtobufOutput
Required.Proto3.TextFormatInput.AnyField.TextFormatOutput
Recommended.Editions_Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput
Recommended.Editions_Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput
Recommended.Editions_Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput
Recommended.Editions_Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput
Recommended.Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput
Recommended.Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput
Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput
Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput
Required.Editions_Proto3.TextFormatInput.AnyField.ProtobufOutput
Required.Editions_Proto3.TextFormatInput.AnyField.TextFormatOutput

Required.Editions_Proto3.TextFormatInput.FloatFieldNoNegativeOctal
Required.Editions_Proto3.TextFormatInput.FloatFieldNoOctal
Required.Editions_Proto3.TextFormatInput.StringFieldBadUTF8Hex
Required.Editions_Proto3.TextFormatInput.StringFieldBadUTF8Octal
Required.Proto3.TextFormatInput.AnyField.ProtobufOutput
Required.Proto3.TextFormatInput.AnyField.TextFormatOutput
Required.Proto3.TextFormatInput.FloatFieldNoNegativeOctal
Required.Proto3.TextFormatInput.FloatFieldNoOctal
Required.Proto3.TextFormatInput.StringFieldBadUTF8Hex
Required.Proto3.TextFormatInput.StringFieldBadUTF8Octal
Required.Editions_Proto3.TextFormatInput.StringFieldBadUTF8Hex
Required.Editions_Proto3.TextFormatInput.StringFieldBadUTF8Octal
Loading

0 comments on commit 0814036

Please sign in to comment.