From b98c7c7b50668cbfe5e41f372385e668c3b703f1 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Fri, 2 Dec 2022 12:39:06 -0800 Subject: [PATCH] move non-conformance tests and protos into upb/test/ create upb/test/BUILD PiperOrigin-RevId: 492534429 --- BUILD | 158 ++--------------- upb/conformance_upb.c | 2 +- upb/message/accessors_test.cc | 2 +- upb/message/test.cc | 2 +- upb/test/BUILD | 172 +++++++++++++++++++ upb/{ => test}/empty.proto | 1 + upb/{fuzz_test_util.cc => test/fuzz_util.cc} | 2 +- upb/{fuzz_test_util.h => test/fuzz_util.h} | 6 +- upb/{ => test}/proto3_test.cc | 4 +- upb/{ => test}/proto3_test.proto | 0 upb/{ => test}/test.proto | 0 upb/{ => test}/test_cpp.cc | 4 +- upb/{ => test}/test_cpp.proto | 0 upb/{ => test}/test_generated_code.cc | 2 +- 14 files changed, 198 insertions(+), 157 deletions(-) create mode 100644 upb/test/BUILD rename upb/{ => test}/empty.proto (51%) rename upb/{fuzz_test_util.cc => test/fuzz_util.cc} (99%) rename upb/{fuzz_test_util.h => test/fuzz_util.h} (96%) rename upb/{ => test}/proto3_test.cc (95%) rename upb/{ => test}/proto3_test.proto (100%) rename upb/{ => test}/test.proto (100%) rename upb/{ => test}/test_cpp.cc (98%) rename upb/{ => test}/test_cpp.proto (100%) rename upb/{ => test}/test_generated_code.cc (99%) diff --git a/BUILD b/BUILD index 85eb88d055..d0a1da5c42 100644 --- a/BUILD +++ b/BUILD @@ -300,10 +300,10 @@ cc_test( ":collections", ":message_accessors", ":mini_table_internal", - ":test_messages_proto2_proto_upb", - ":test_messages_proto3_proto_upb", - ":test_upb_proto", ":upb", + "//upb/test:test_messages_proto2_upb_proto", + "//upb/test:test_messages_proto3_upb_proto", + "//upb/test:test_upb_proto", "@com_google_absl//absl/container:flat_hash_set", "@com_google_googletest//:gtest_main", "@com_google_protobuf//:protobuf", @@ -634,55 +634,6 @@ cc_test( ], ) -cc_test( - name = "test_generated_code", - srcs = ["upb/test_generated_code.cc"], - deps = [ - ":empty_upbdefs_proto", - ":port", - ":test_messages_proto2_proto_upb", - ":test_messages_proto3_proto_upb", - ":test_upb_proto", - ":upb", - "@com_google_googletest//:gtest_main", - ], -) - -proto_library( - name = "test_proto", - testonly = 1, - srcs = ["upb/test.proto"], -) - -upb_proto_library( - name = "test_upb_proto", - testonly = 1, - deps = [":test_proto"], -) - -proto_library( - name = "empty_proto", - srcs = ["upb/empty.proto"], -) - -upb_proto_reflection_library( - name = "empty_upbdefs_proto", - testonly = 1, - deps = [":empty_proto"], -) - -upb_proto_library( - name = "test_messages_proto2_proto_upb", - testonly = 1, - deps = ["@com_google_protobuf//src/google/protobuf:test_messages_proto2_proto"], -) - -upb_proto_library( - name = "test_messages_proto3_proto_upb", - testonly = 1, - deps = ["@com_google_protobuf//src/google/protobuf:test_messages_proto3_proto"], -) - proto_library( name = "json_test_proto", testonly = 1, @@ -734,13 +685,13 @@ cc_test( name = "message_test", srcs = ["upb/message/test.cc"], deps = [ - ":fuzz_test_util", ":json", ":message_test_upb_proto", ":message_test_upb_proto_reflection", ":reflection", - ":test_messages_proto3_proto_upb", ":upb", + "//upb/test:fuzz_util", + "//upb/test:test_messages_proto3_upb_proto", "@com_google_googletest//:gtest_main", ], ) @@ -758,62 +709,17 @@ upb_proto_library( deps = [":message_test_proto"], ) -proto_library( - name = "proto3_test_proto", - testonly = 1, - srcs = ["upb/proto3_test.proto"], - deps = ["@com_google_protobuf//:descriptor_proto"], -) - -upb_proto_library( - name = "proto3_test_upb_proto", - testonly = 1, - deps = [":proto3_test_proto"], -) - -upb_proto_reflection_library( - name = "proto3_test_upb_proto_reflection", - testonly = 1, - deps = [":proto3_test_proto"], -) - upb_proto_reflection_library( name = "message_test_upb_proto_reflection", testonly = 1, deps = [":message_test_proto"], ) -proto_library( - name = "test_cpp_proto", - srcs = ["upb/test_cpp.proto"], - deps = ["@com_google_protobuf//:timestamp_proto"], -) - -upb_proto_library( - name = "test_cpp_upb_proto", - deps = ["test_cpp_proto"], -) - -upb_proto_reflection_library( - name = "test_cpp_upb_proto_reflection", - deps = ["test_cpp_proto"], -) - upb_proto_library( name = "struct_upb_proto", deps = ["@com_google_protobuf//:struct_proto"], ) -upb_proto_library( - name = "timestamp_upb_proto", - deps = ["@com_google_protobuf//:timestamp_proto"], -) - -upb_proto_reflection_library( - name = "timestamp_upb_proto_reflection", - deps = ["@com_google_protobuf//:timestamp_proto"], -) - cc_test( name = "atoi_test", srcs = ["upb/lex/atoi_test.cc"], @@ -825,35 +731,6 @@ cc_test( ], ) -cc_test( - name = "proto3_test", - srcs = ["upb/proto3_test.cc"], - copts = UPB_DEFAULT_CPPOPTS, - deps = [ - ":proto3_test_upb_proto", - ":proto3_test_upb_proto_reflection", - ":reflection", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "test_cpp", - srcs = ["upb/test_cpp.cc"], - copts = UPB_DEFAULT_CPPOPTS, - deps = [ - ":json", - ":port", - ":reflection", - ":test_cpp_upb_proto", - ":test_cpp_upb_proto_reflection", - ":timestamp_upb_proto", - ":timestamp_upb_proto_reflection", - ":upb", - "@com_google_googletest//:gtest_main", - ], -) - cc_test( name = "hash_test", srcs = ["upb/hash/test.cc"], @@ -867,13 +744,13 @@ cc_test( ) upb_proto_library( - name = "conformance_proto_upb", + name = "conformance_upb_proto", testonly = 1, deps = ["@com_google_protobuf//conformance:conformance_proto"], ) upb_proto_reflection_library( - name = "conformance_proto_upbdefs", + name = "conformance_upb_proto_reflection", testonly = 1, deps = ["@com_google_protobuf//conformance:conformance_proto"], ) @@ -881,12 +758,14 @@ upb_proto_reflection_library( upb_proto_reflection_library( name = "test_messages_proto2_upbdefs", testonly = 1, + visibility = ["//:__subpackages__"], deps = ["@com_google_protobuf//src/google/protobuf:test_messages_proto2_proto"], ) upb_proto_reflection_library( name = "test_messages_proto3_upbdefs", testonly = 1, + visibility = ["//:__subpackages__"], deps = ["@com_google_protobuf//src/google/protobuf:test_messages_proto3_proto"], ) @@ -901,8 +780,8 @@ cc_binary( "//conditions:default": [], }), deps = [ - ":conformance_proto_upb", - ":conformance_proto_upbdefs", + ":conformance_upb_proto", + ":conformance_upb_proto_reflection", ":json", ":port", ":reflection", @@ -950,8 +829,8 @@ cc_binary( "//conditions:default": [], }), deps = [ - ":conformance_proto_upb", - ":conformance_proto_upbdefs", + ":conformance_upb_proto", + ":conformance_upb_proto_reflection", ":json", ":port", ":reflection", @@ -982,17 +861,6 @@ sh_test( deps = ["@bazel_tools//tools/bash/runfiles"], ) -cc_library( - name = "fuzz_test_util", - testonly = 1, - srcs = ["upb/fuzz_test_util.cc"], - hdrs = ["upb/fuzz_test_util.h"], - deps = [ - ":mini_table_internal", - ":upb", - ], -) - # Internal C/C++ libraries ##################################################### cc_library( diff --git a/upb/conformance_upb.c b/upb/conformance_upb.c index 8708da0938..c124e1b4cf 100644 --- a/upb/conformance_upb.c +++ b/upb/conformance_upb.c @@ -41,7 +41,7 @@ #include "upb/json/decode.h" #include "upb/json/encode.h" #include "upb/reflection/message.h" -#include "upb/text_encode.h" +#include "upb/text/encode.h" #include "upb/wire/decode.h" #include "upb/wire/encode.h" diff --git a/upb/message/accessors_test.cc b/upb/message/accessors_test.cc index fcc4bf2e5a..d4b322f9f4 100644 --- a/upb/message/accessors_test.cc +++ b/upb/message/accessors_test.cc @@ -40,7 +40,7 @@ #include "upb/collections/array.h" #include "upb/mini_table/decode.h" #include "upb/mini_table/encode_internal.hpp" -#include "upb/test.upb.h" +#include "upb/test/test.upb.h" #include "upb/upb.h" #include "upb/wire/decode.h" diff --git a/upb/message/test.cc b/upb/message/test.cc index 8c967612c7..8944c855e7 100644 --- a/upb/message/test.cc +++ b/upb/message/test.cc @@ -28,12 +28,12 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" #include "google/protobuf/test_messages_proto3.upb.h" -#include "upb/fuzz_test_util.h" #include "upb/json/decode.h" #include "upb/json/encode.h" #include "upb/message/test.upb.h" #include "upb/message/test.upbdefs.h" #include "upb/reflection/def.hpp" +#include "upb/test/fuzz_util.h" #include "upb/upb.hpp" // begin:google_only diff --git a/upb/test/BUILD b/upb/test/BUILD new file mode 100644 index 0000000000..f3e53ad048 --- /dev/null +++ b/upb/test/BUILD @@ -0,0 +1,172 @@ +# Copyright (c) 2009-2021, Google LLC +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of Google LLC nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +load( + "//bazel:build_defs.bzl", + "UPB_DEFAULT_CPPOPTS", +) +load( + "//bazel:upb_proto_library.bzl", + "upb_proto_library", + "upb_proto_reflection_library", +) + +proto_library( + name = "empty_proto", + srcs = ["empty.proto"], +) + +upb_proto_reflection_library( + name = "empty_upb_proto_reflection", + testonly = 1, + deps = [":empty_proto"], +) + +proto_library( + name = "proto3_test_proto", + testonly = 1, + srcs = ["proto3_test.proto"], + deps = ["@com_google_protobuf//:descriptor_proto"], +) + +upb_proto_library( + name = "proto3_test_upb_proto", + testonly = 1, + deps = [":proto3_test_proto"], +) + +upb_proto_reflection_library( + name = "proto3_test_upb_proto_reflection", + testonly = 1, + deps = [":proto3_test_proto"], +) + +proto_library( + name = "test_proto", + testonly = 1, + srcs = ["test.proto"], +) + +upb_proto_library( + name = "test_upb_proto", + testonly = 1, + visibility = ["//:__subpackages__"], + deps = [":test_proto"], +) + +proto_library( + name = "test_cpp_proto", + srcs = ["test_cpp.proto"], + deps = ["@com_google_protobuf//:timestamp_proto"], +) + +upb_proto_library( + name = "test_cpp_upb_proto", + deps = ["test_cpp_proto"], +) + +upb_proto_reflection_library( + name = "test_cpp_upb_proto_reflection", + deps = ["test_cpp_proto"], +) + +upb_proto_library( + name = "test_messages_proto2_upb_proto", + testonly = 1, + visibility = ["//:__subpackages__"], + deps = ["@com_google_protobuf//src/google/protobuf:test_messages_proto2_proto"], +) + +upb_proto_library( + name = "test_messages_proto3_upb_proto", + testonly = 1, + visibility = ["//:__subpackages__"], + deps = ["@com_google_protobuf//src/google/protobuf:test_messages_proto3_proto"], +) + +upb_proto_library( + name = "timestamp_upb_proto", + deps = ["@com_google_protobuf//:timestamp_proto"], +) + +upb_proto_reflection_library( + name = "timestamp_upb_proto_reflection", + deps = ["@com_google_protobuf//:timestamp_proto"], +) + +cc_library( + name = "fuzz_util", + testonly = 1, + srcs = ["fuzz_util.cc"], + hdrs = ["fuzz_util.h"], + visibility = ["//:__subpackages__"], + deps = [ + "//:upb", + "//:mini_table_internal", + ], +) + +cc_test( + name = "proto3_test", + srcs = ["proto3_test.cc"], + copts = UPB_DEFAULT_CPPOPTS, + deps = [ + ":proto3_test_upb_proto", + ":proto3_test_upb_proto_reflection", + "//:reflection", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "test_cpp", + srcs = ["test_cpp.cc"], + copts = UPB_DEFAULT_CPPOPTS, + deps = [ + ":test_cpp_upb_proto", + ":test_cpp_upb_proto_reflection", + ":timestamp_upb_proto", + ":timestamp_upb_proto_reflection", + "//:upb", + "//:json", + "//:port", + "//:reflection", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "test_generated_code", + srcs = ["test_generated_code.cc"], + deps = [ + ":empty_upb_proto_reflection", + ":test_messages_proto2_upb_proto", + ":test_messages_proto3_upb_proto", + ":test_upb_proto", + "//:upb", + "//:port", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/upb/empty.proto b/upb/test/empty.proto similarity index 51% rename from upb/empty.proto rename to upb/test/empty.proto index fddb20b36c..7e54f1bd46 100644 --- a/upb/empty.proto +++ b/upb/test/empty.proto @@ -1 +1,2 @@ syntax = "proto2"; +package upb_test; diff --git a/upb/fuzz_test_util.cc b/upb/test/fuzz_util.cc similarity index 99% rename from upb/fuzz_test_util.cc rename to upb/test/fuzz_util.cc index 6963efdad2..1fe323eaf7 100644 --- a/upb/fuzz_test_util.cc +++ b/upb/test/fuzz_util.cc @@ -25,7 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "upb/fuzz_test_util.h" +#include "upb/test/fuzz_util.h" #include "upb/message/message.h" #include "upb/mini_table/decode.h" diff --git a/upb/fuzz_test_util.h b/upb/test/fuzz_util.h similarity index 96% rename from upb/fuzz_test_util.h rename to upb/test/fuzz_util.h index 95a31fa324..301dfcb006 100644 --- a/upb/fuzz_test_util.h +++ b/upb/test/fuzz_util.h @@ -25,8 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef UPB_FUZZ_TEST_UTIL_H_ -#define UPB_FUZZ_TEST_UTIL_H_ +#ifndef UPB_TEST_FUZZ_UTIL_H_ +#define UPB_TEST_FUZZ_UTIL_H_ #include #include @@ -78,4 +78,4 @@ const upb_MiniTable* BuildMiniTable(const MiniTableFuzzInput& input, } // namespace fuzz } // namespace upb -#endif // THIRD_PARTY_UPB_UPB_FUZZ_TEST_UTIL_H_ +#endif // UPB_TEST_FUZZ_UTIL_H_ diff --git a/upb/proto3_test.cc b/upb/test/proto3_test.cc similarity index 95% rename from upb/proto3_test.cc rename to upb/test/proto3_test.cc index 76700f86b1..9c202a9139 100644 --- a/upb/proto3_test.cc +++ b/upb/test/proto3_test.cc @@ -26,9 +26,9 @@ */ #include "gtest/gtest.h" -#include "upb/proto3_test.upb.h" -#include "upb/proto3_test.upbdefs.h" #include "upb/reflection/def.hpp" +#include "upb/test/proto3_test.upb.h" +#include "upb/test/proto3_test.upbdefs.h" TEST(Proto3Test, SyntheticOneofExtension) { upb::DefPool defpool; diff --git a/upb/proto3_test.proto b/upb/test/proto3_test.proto similarity index 100% rename from upb/proto3_test.proto rename to upb/test/proto3_test.proto diff --git a/upb/test.proto b/upb/test/test.proto similarity index 100% rename from upb/test.proto rename to upb/test/test.proto diff --git a/upb/test_cpp.cc b/upb/test/test_cpp.cc similarity index 98% rename from upb/test_cpp.cc rename to upb/test/test_cpp.cc index cd18370ea4..57dee8c160 100644 --- a/upb/test_cpp.cc +++ b/upb/test/test_cpp.cc @@ -39,8 +39,8 @@ #include "upb/json/encode.h" #include "upb/reflection/def.h" #include "upb/reflection/def.hpp" -#include "upb/test_cpp.upb.h" -#include "upb/test_cpp.upbdefs.h" +#include "upb/test/test_cpp.upb.h" +#include "upb/test/test_cpp.upbdefs.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/test_cpp.proto b/upb/test/test_cpp.proto similarity index 100% rename from upb/test_cpp.proto rename to upb/test/test_cpp.proto diff --git a/upb/test_generated_code.cc b/upb/test/test_generated_code.cc similarity index 99% rename from upb/test_generated_code.cc rename to upb/test/test_generated_code.cc index 3f9a66de3a..4b9d2b8627 100644 --- a/upb/test_generated_code.cc +++ b/upb/test/test_generated_code.cc @@ -33,7 +33,7 @@ #include "gtest/gtest.h" #include "google/protobuf/test_messages_proto2.upb.h" #include "google/protobuf/test_messages_proto3.upb.h" -#include "upb/test.upb.h" +#include "upb/test/test.upb.h" #include "upb/upb.hpp" // Must be last.