Skip to content

Commit

Permalink
Enable tests for bazel build.
Browse files Browse the repository at this point in the history
Change-Id: I63ed5fb58a45e098f2fd1fa457a219148de030bd
  • Loading branch information
liujisi committed Jun 18, 2015
1 parent 5b3a8e7 commit 7a0c431
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 77 deletions.
175 changes: 98 additions & 77 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@ PROTOS = LITE_TEST_PROTOS + TEST_PROTOS

INPUTS = PROTOS + WELL_KNOWN_PROTOS

OUTPUTS = ["src/" + x[:-5] + "pb.h" for x in PROTOS] + \
["src/" + x[:-5] + "pb.cc" for x in PROTOS]

genrule(
name = "gen_test_protos",
srcs = ["src/" + x for x in INPUTS],
outs = ["src/" + x[:-5] + "pb.h" for x in PROTOS] +
["src/" + x[:-5] + "pb.cc" for x in PROTOS],
outs = OUTPUTS,
cmd =
"$(location :protoc) --cpp_out=$(@D)/src" +
"".join([" -I" + x + "=$(location src/" + x + ")" for x in INPUTS]) +
Expand All @@ -307,78 +309,97 @@ COMMON_TEST_SRCS = [
"src/google/protobuf/testing/googletest.cc",
]

# TODO(liujisi): Add gtest dependency and enable tests.
# cc_test(
# name = "protobuf_test",
# srcs = OUTPUTS + COMMON_TEST_SRCS + [
# "src/google/protobuf/any_test.cc",
# "src/google/protobuf/arena_unittest.cc",
# "src/google/protobuf/arenastring_unittest.cc",
# "src/google/protobuf/compiler/command_line_interface_unittest.cc",
# "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
# "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
# "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
# "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
# "src/google/protobuf/compiler/importer_unittest.cc",
# "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
# "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
# "src/google/protobuf/compiler/mock_code_generator.cc",
# "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
# "src/google/protobuf/compiler/parser_unittest.cc",
# "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
# "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
# "src/google/protobuf/descriptor_database_unittest.cc",
# "src/google/protobuf/descriptor_unittest.cc",
# "src/google/protobuf/drop_unknown_fields_test.cc",
# "src/google/protobuf/dynamic_message_unittest.cc",
# "src/google/protobuf/extension_set_unittest.cc",
# "src/google/protobuf/generated_message_reflection_unittest.cc",
# "src/google/protobuf/io/coded_stream_unittest.cc",
# "src/google/protobuf/io/printer_unittest.cc",
# "src/google/protobuf/io/tokenizer_unittest.cc",
# "src/google/protobuf/io/zero_copy_stream_unittest.cc",
# "src/google/protobuf/map_field_test.cc",
# "src/google/protobuf/map_test.cc",
# "src/google/protobuf/message_unittest.cc",
# "src/google/protobuf/no_field_presence_test.cc",
# "src/google/protobuf/preserve_unknown_enum_test.cc",
# "src/google/protobuf/proto3_arena_unittest.cc",
# "src/google/protobuf/reflection_ops_unittest.cc",
# "src/google/protobuf/repeated_field_reflection_unittest.cc",
# "src/google/protobuf/repeated_field_unittest.cc",
# "src/google/protobuf/stubs/bytestream_unittest.cc",
# "src/google/protobuf/stubs/common_unittest.cc",
# "src/google/protobuf/stubs/once_unittest.cc",
# "src/google/protobuf/stubs/status_test.cc",
# "src/google/protobuf/stubs/statusor_test.cc",
# "src/google/protobuf/stubs/stringpiece_unittest.cc",
# "src/google/protobuf/stubs/stringprintf_unittest.cc",
# "src/google/protobuf/stubs/structurally_valid_unittest.cc",
# "src/google/protobuf/stubs/strutil_unittest.cc",
# "src/google/protobuf/stubs/template_util_unittest.cc",
# "src/google/protobuf/stubs/time_test.cc",
# "src/google/protobuf/stubs/type_traits_unittest.cc",
# "src/google/protobuf/text_format_unittest.cc",
# "src/google/protobuf/unknown_field_set_unittest.cc",
# "src/google/protobuf/util/field_comparator_test.cc",
# "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
# "src/google/protobuf/util/internal/json_objectwriter_test.cc",
# "src/google/protobuf/util/internal/json_stream_parser_test.cc",
# "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
# "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
# "src/google/protobuf/util/internal/type_info_test_helper.cc",
# "src/google/protobuf/util/json_util_test.cc",
# "src/google/protobuf/util/type_resolver_util_test.cc",
# "src/google/protobuf/well_known_types_unittest.cc",
# "src/google/protobuf/wire_format_unittest.cc",
# ],
# copts = COPTS,
# includes = [
# "src/",
# ],
# linkopts = LINK_OPTS,
# deps = [
# ":protobuf",
# ":protoc_lib",
# ],
# )
cc_binary(
name = "test_plugin",
srcs = [
# AUTOGEN(test_plugin_srcs)
"src/google/protobuf/compiler/mock_code_generator.cc",
"src/google/protobuf/compiler/test_plugin.cc",
"src/google/protobuf/testing/file.cc",
],
deps = [
":protobuf",
":protoc_lib",
"//external:gtest",
],
)

cc_test(
name = "protobuf_test",
srcs = OUTPUTS + COMMON_TEST_SRCS + [
# AUTOGEN(test_srcs)
"src/google/protobuf/any_test.cc",
"src/google/protobuf/arena_unittest.cc",
"src/google/protobuf/arenastring_unittest.cc",
"src/google/protobuf/compiler/command_line_interface_unittest.cc",
"src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
"src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
"src/google/protobuf/compiler/cpp/cpp_unittest.cc",
"src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
"src/google/protobuf/compiler/importer_unittest.cc",
"src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
"src/google/protobuf/compiler/java/java_plugin_unittest.cc",
"src/google/protobuf/compiler/mock_code_generator.cc",
"src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
"src/google/protobuf/compiler/parser_unittest.cc",
"src/google/protobuf/compiler/python/python_plugin_unittest.cc",
"src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
"src/google/protobuf/descriptor_database_unittest.cc",
"src/google/protobuf/descriptor_unittest.cc",
"src/google/protobuf/drop_unknown_fields_test.cc",
"src/google/protobuf/dynamic_message_unittest.cc",
"src/google/protobuf/extension_set_unittest.cc",
"src/google/protobuf/generated_message_reflection_unittest.cc",
"src/google/protobuf/io/coded_stream_unittest.cc",
"src/google/protobuf/io/printer_unittest.cc",
"src/google/protobuf/io/tokenizer_unittest.cc",
"src/google/protobuf/io/zero_copy_stream_unittest.cc",
"src/google/protobuf/map_field_test.cc",
"src/google/protobuf/map_test.cc",
"src/google/protobuf/message_unittest.cc",
"src/google/protobuf/no_field_presence_test.cc",
"src/google/protobuf/preserve_unknown_enum_test.cc",
"src/google/protobuf/proto3_arena_unittest.cc",
"src/google/protobuf/reflection_ops_unittest.cc",
"src/google/protobuf/repeated_field_reflection_unittest.cc",
"src/google/protobuf/repeated_field_unittest.cc",
"src/google/protobuf/stubs/bytestream_unittest.cc",
"src/google/protobuf/stubs/common_unittest.cc",
"src/google/protobuf/stubs/once_unittest.cc",
"src/google/protobuf/stubs/status_test.cc",
"src/google/protobuf/stubs/statusor_test.cc",
"src/google/protobuf/stubs/stringpiece_unittest.cc",
"src/google/protobuf/stubs/stringprintf_unittest.cc",
"src/google/protobuf/stubs/structurally_valid_unittest.cc",
"src/google/protobuf/stubs/strutil_unittest.cc",
"src/google/protobuf/stubs/template_util_unittest.cc",
"src/google/protobuf/stubs/time_test.cc",
"src/google/protobuf/stubs/type_traits_unittest.cc",
"src/google/protobuf/text_format_unittest.cc",
"src/google/protobuf/unknown_field_set_unittest.cc",
"src/google/protobuf/util/field_comparator_test.cc",
"src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
"src/google/protobuf/util/internal/json_objectwriter_test.cc",
"src/google/protobuf/util/internal/json_stream_parser_test.cc",
"src/google/protobuf/util/internal/protostream_objectsource_test.cc",
"src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
"src/google/protobuf/util/internal/type_info_test_helper.cc",
"src/google/protobuf/util/json_util_test.cc",
"src/google/protobuf/util/type_resolver_util_test.cc",
"src/google/protobuf/well_known_types_unittest.cc",
"src/google/protobuf/wire_format_unittest.cc",
],
copts = COPTS,
data = [
":test_plugin",
],
includes = [
"src/",
],
linkopts = LINK_OPTS,
deps = [
":protobuf",
":protoc_lib",
"//external:gtest_main",
],
)
16 changes: 16 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
new_http_archive(
name = "gmock_archive",
url = "https://googlemock.googlecode.com/files/gmock-1.7.0.zip",
sha256 = "26fcbb5925b74ad5fc8c26b0495dfc96353f4d553492eb97e85a8a6d2f43095b",
build_file = "gmock.BUILD",
)

bind(
name = "gtest",
actual = "@gmock_archive//:gtest",
)

bind(
name = "gtest_main",
actual = "@gmock_archive//:gtest_main",
)
23 changes: 23 additions & 0 deletions gmock.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cc_library(
name = "gtest",
srcs = [
"gmock-1.7.0/gtest/src/gtest-all.cc",
"gmock-1.7.0/src/gmock-all.cc",
],
includes = [
"gmock-1.7.0",
"gmock-1.7.0/gtest",
"gmock-1.7.0/gtest/include",
"gmock-1.7.0/include",
],
linkopts = ["-pthread"],
visibility = ["//visibility:public"],
)

cc_library(
name = "gtest_main",
srcs = ["gmock-1.7.0/src/gmock_main.cc"],
linkopts = ["-pthread"],
visibility = ["//visibility:public"],
deps = [":gtest"],
)
3 changes: 3 additions & 0 deletions update_file_lists.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ WKT_PROTOS=$(get_variable_value $MAKEFILE nobase_dist_proto_DATA)
COMMON_TEST_SOURCES=$(get_source_files $MAKEFILE COMMON_TEST_SOURCES)
TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_test_SOURCES)
LITE_TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_lite_test_SOURCES)
TEST_PLUGIN_SOURCES=$(get_source_files $MAKEFILE test_plugin_SOURCES)

################################################################################
# Update cmake files.
Expand Down Expand Up @@ -177,3 +178,5 @@ set_bazel_value $BAZEL_BUILD well_known_protos "" $WKT_PROTOS
set_bazel_value $BAZEL_BUILD test_protos "" $PROTOS
set_bazel_value $BAZEL_BUILD common_test_srcs $BAZEL_PREFIX $COMMON_TEST_SOURCES
set_bazel_value $BAZEL_BUILD test_srcs $BAZEL_PREFIX $TEST_SOURCES
set_bazel_value $BAZEL_BUILD test_plugin_srcs $BAZEL_PREFIX $TEST_PLUGIN_SOURCES

0 comments on commit 7a0c431

Please sign in to comment.