Add dedicated tests to lock down that overridable defaults never change.
Once an edition is released these should be fixed forever. On the other hand, the fixed defaults may see new features included as we change legacy behaviors in future editions. PiperOrigin-RevId: 625842071pull/16553/head v27-dev
parent
f76b28e535
commit
57a6e8df1c
|
@ -10,6 +10,18 @@ bzl_library(
|
|||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# Aggregate all the features owned by the Protobuf repo.
|
||||
compile_edition_defaults(
|
||||
name = "protobuf_defaults",
|
||||
testonly = True,
|
||||
srcs = [
|
||||
"//java/core:java_features_proto",
|
||||
"//src/google/protobuf:cpp_features_proto",
|
||||
],
|
||||
maximum_edition = "2023",
|
||||
minimum_edition = "2023",
|
||||
)
|
||||
|
||||
compile_edition_defaults(
|
||||
name = "test_defaults_2023",
|
||||
testonly = True,
|
||||
|
@ -75,18 +87,36 @@ cc_library(
|
|||
],
|
||||
)
|
||||
|
||||
cc_proto_library(
|
||||
name = "cpp_features_cc_proto",
|
||||
testonly = True,
|
||||
deps = ["//src/google/protobuf:cpp_features_proto"],
|
||||
)
|
||||
|
||||
cc_proto_library(
|
||||
name = "java_features_cc_proto",
|
||||
testonly = True,
|
||||
deps = ["//java/core:java_features_proto"],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "defaults_test",
|
||||
srcs = ["defaults_test.cc"],
|
||||
data = [
|
||||
":protobuf_defaults",
|
||||
":test_defaults_2023",
|
||||
":test_defaults_far_future",
|
||||
":test_defaults_future",
|
||||
],
|
||||
deps = [
|
||||
":cpp_features_cc_proto",
|
||||
":defaults_test_embedded",
|
||||
":java_features_cc_proto",
|
||||
"//:protobuf",
|
||||
"//src/google/protobuf",
|
||||
"//src/google/protobuf:port",
|
||||
"//src/google/protobuf:protobuf_lite",
|
||||
"//src/google/protobuf:test_textproto",
|
||||
"//src/google/protobuf:unittest_features_cc_proto",
|
||||
"//src/google/protobuf/stubs",
|
||||
"//src/google/protobuf/testing",
|
||||
|
|
|
@ -12,11 +12,17 @@
|
|||
#include "absl/strings/escaping.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "google/protobuf/java_features.pb.h"
|
||||
#include "google/protobuf/cpp_features.pb.h"
|
||||
#include "editions/defaults_test_embedded.h"
|
||||
#include "editions/defaults_test_embedded_base64.h"
|
||||
#include "google/protobuf/extension_set.h"
|
||||
#include "google/protobuf/message.h"
|
||||
#include "google/protobuf/test_textproto.h"
|
||||
#include "google/protobuf/unittest_features.pb.h"
|
||||
#include "google/protobuf/stubs/status_macros.h"
|
||||
|
||||
|
||||
// Must be included last.
|
||||
#include "google/protobuf/port_def.inc"
|
||||
|
||||
|
@ -182,6 +188,63 @@ TEST(DefaultsTest, EmbeddedBase64) {
|
|||
pb::VALUE3);
|
||||
}
|
||||
|
||||
// Lock down that overridable defaults never change in released editions. After
|
||||
// an edition has been released these tests should never need to be touched.
|
||||
class OverridableDefaultsTest : public ::testing::Test {
|
||||
public:
|
||||
OverridableDefaultsTest() = default;
|
||||
static void SetUpTestSuite() {
|
||||
google::protobuf::LinkExtensionReflection(pb::cpp);
|
||||
google::protobuf::LinkExtensionReflection(pb::java);
|
||||
DescriptorPool::generated_pool();
|
||||
}
|
||||
};
|
||||
|
||||
// TODO Enable these once they become fixed internally.
|
||||
TEST_F(OverridableDefaultsTest, Proto2) {
|
||||
auto feature_defaults = ReadDefaults("protobuf_defaults");
|
||||
ASSERT_OK(feature_defaults);
|
||||
ASSERT_GE(feature_defaults->defaults().size(), 1);
|
||||
const auto& defaults = feature_defaults->defaults(0);
|
||||
ASSERT_EQ(defaults.edition(), EDITION_PROTO2);
|
||||
|
||||
EXPECT_THAT(defaults.overridable_features(), EqualsProto(R"pb([pb.cpp] {}
|
||||
[pb.java] {}
|
||||
)pb"));
|
||||
}
|
||||
TEST_F(OverridableDefaultsTest, Proto3) {
|
||||
auto feature_defaults = ReadDefaults("protobuf_defaults");
|
||||
ASSERT_OK(feature_defaults);
|
||||
ASSERT_GE(feature_defaults->defaults().size(), 2);
|
||||
const auto& defaults = feature_defaults->defaults(1);
|
||||
ASSERT_EQ(defaults.edition(), EDITION_PROTO3);
|
||||
|
||||
EXPECT_THAT(defaults.overridable_features(), EqualsProto(R"pb([pb.cpp] {}
|
||||
[pb.java] {}
|
||||
)pb"));
|
||||
}
|
||||
|
||||
// Lock down that 2023 overridable defaults never change. Once Edition 2023 has
|
||||
// been released this test should never need to be touched.
|
||||
TEST_F(OverridableDefaultsTest, Edition2023) {
|
||||
auto feature_defaults = ReadDefaults("protobuf_defaults");
|
||||
ASSERT_OK(feature_defaults);
|
||||
ASSERT_GE(feature_defaults->defaults().size(), 3);
|
||||
const auto& defaults = feature_defaults->defaults(2);
|
||||
ASSERT_EQ(defaults.edition(), EDITION_2023);
|
||||
|
||||
EXPECT_THAT(defaults.overridable_features(), EqualsProto(R"pb(
|
||||
field_presence: EXPLICIT
|
||||
enum_type: OPEN
|
||||
repeated_field_encoding: PACKED
|
||||
utf8_validation: VERIFY
|
||||
message_encoding: LENGTH_PREFIXED
|
||||
json_format: ALLOW
|
||||
[pb.cpp] { legacy_closed_enum: false string_type: STRING }
|
||||
[pb.java] { legacy_closed_enum: false utf8_validation: DEFAULT }
|
||||
)pb"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
|
|
@ -187,6 +187,7 @@ proto_library(
|
|||
strip_import_prefix = "/java/core/src/main/resources",
|
||||
visibility = [
|
||||
"//:__pkg__",
|
||||
"//editions:__pkg__",
|
||||
"//java/__subpackages__",
|
||||
"//pkg:__pkg__",
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue