提交 9b94773a 编写于 作者: Y Yi Wang

Add gtest

上级 8013d17d
# External dependency to grpc-enabled Google-styleprotobuf bulding
# rules. This method comes from
# https://github.com/pubref/rules_protobuf#usage.
git_repository( git_repository(
name = "org_pubref_rules_protobuf", name = "org_pubref_rules_protobuf",
remote = "https://github.com/pubref/rules_protobuf", remote = "https://github.com/pubref/rules_protobuf",
tag = "v0.7.1", tag = "v0.7.1",
) )
# External dependency to gtest 1.7.0. This method comes from
# https://www.bazel.io/versions/master/docs/tutorial/cpp.html.
new_http_archive(
name = "gtest",
url = "https://github.com/google/googletest/archive/release-1.7.0.zip",
sha256 = "b58cb7547a28b2c718d1e38aee18a3659c9e3ff52440297e965f5edffe34b6d0",
build_file = "third_party/gtest.BUILD",
strip_prefix = "googletest-release-1.7.0",
)
load("@org_pubref_rules_protobuf//cpp:rules.bzl", "cpp_proto_repositories") load("@org_pubref_rules_protobuf//cpp:rules.bzl", "cpp_proto_repositories")
cpp_proto_repositories() cpp_proto_repositories()
...@@ -161,12 +161,13 @@ The general development workflow with Docker and Bazel is as follows: ...@@ -161,12 +161,13 @@ The general development workflow with Docker and Bazel is as follows:
cd /paddle # where paddle source code has been mounted into the container cd /paddle # where paddle source code has been mounted into the container
mkdir -p build mkdir -p build
cd build cd build
cmake .. cmake -DWITH_TESTING=ON ..
make -j `nproc` make -j `nproc`
CTEST_OUTPUT_ON_FAILURE=1 ctest
or Bazel in the container: or Bazel in the container:
.. code-block:: bash .. code-block:: bash
cd /paddle cd /paddle
bazel build ... bazel test ...
cc_library(
name = "main",
srcs = glob(
["src/*.cc"],
exclude = ["src/gtest-all.cc"]
),
hdrs = glob([
"include/**/*.h",
"src/*.h"
]),
copts = ["-Iexternal/gtest/include"],
linkopts = ["-pthread"],
visibility = ["//visibility:public"],
)
...@@ -7,6 +7,7 @@ cpp_proto_library( ...@@ -7,6 +7,7 @@ cpp_proto_library(
protos = [ protos = [
"example.proto" "example.proto"
], ],
with_grpc = True,
) )
cc_library( cc_library(
...@@ -15,3 +16,13 @@ cc_library( ...@@ -15,3 +16,13 @@ cc_library(
hdrs = ["example_lib.h"], hdrs = ["example_lib.h"],
deps = [":example_proto"], deps = [":example_proto"],
) )
cc_test(
name = "example_lib_test",
srcs = ["example_lib_test.cc"],
copts = ["-Iexternal/gtest/include"],
deps =[
"@gtest//:main",
":example_lib",
],
)
syntax = "proto3"; syntax = "proto3";
package protos; package third_party.protobuf_test;
message Greeting { message Greeting {
string name = 1; string name = 1;
......
#include "third_party/protobuf_test/example_lib.h" #include "third_party/protobuf_test/example_lib.h"
#include <string>
std::string get_greet(const ::protos::Greeting& who) { namespace third_party {
namespace protobuf_test {
std::string get_greet(const Greeting& who) {
return "Hello " + who.name(); return "Hello " + who.name();
} }
} // namespace protobuf_test
} // namespace thrid_party
...@@ -4,4 +4,10 @@ ...@@ -4,4 +4,10 @@
#include <string> #include <string>
std::string get_greet(const ::protos::Greeting &who); namespace third_party {
namespace protobuf_test {
std::string get_greet(const Greeting &who);
} // namespace protobuf_test
} // namespace third_party
#include "third_party/protobuf_test/example_lib.h"
#include "gtest/gtest.h"
namespace third_party {
namespace protobuf_test {
TEST(ProtobufTest, GetGreet) {
Greeting g;
g.set_name("Paddle");
EXPECT_EQ("Hello Paddle", get_greet(g));
}
} // namespace protobuf_test
} // namespace third_party
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册