Skip to content

Commit 9b94773

Browse files
committed
Add gtest
1 parent 8013d17 commit 9b94773

File tree

8 files changed

+72
-6
lines changed

8 files changed

+72
-6
lines changed

WORKSPACE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
# External dependency to grpc-enabled Google-styleprotobuf bulding
2+
# rules. This method comes from
3+
# https://github.com/pubref/rules_protobuf#usage.
14
git_repository(
25
name = "org_pubref_rules_protobuf",
36
remote = "https://github.com/pubref/rules_protobuf",
47
tag = "v0.7.1",
58
)
69

10+
# External dependency to gtest 1.7.0. This method comes from
11+
# https://www.bazel.io/versions/master/docs/tutorial/cpp.html.
12+
new_http_archive(
13+
name = "gtest",
14+
url = "https://github.com/google/googletest/archive/release-1.7.0.zip",
15+
sha256 = "b58cb7547a28b2c718d1e38aee18a3659c9e3ff52440297e965f5edffe34b6d0",
16+
build_file = "third_party/gtest.BUILD",
17+
strip_prefix = "googletest-release-1.7.0",
18+
)
19+
20+
721
load("@org_pubref_rules_protobuf//cpp:rules.bzl", "cpp_proto_repositories")
822
cpp_proto_repositories()

doc/getstarted/build_and_install/docker_install_en.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,13 @@ The general development workflow with Docker and Bazel is as follows:
161161
cd /paddle # where paddle source code has been mounted into the container
162162
mkdir -p build
163163
cd build
164-
cmake ..
164+
cmake -DWITH_TESTING=ON ..
165165
make -j `nproc`
166+
CTEST_OUTPUT_ON_FAILURE=1 ctest
166167
167168
or Bazel in the container:
168169

169170
.. code-block:: bash
170171
171172
cd /paddle
172-
bazel build ...
173+
bazel test ...

third_party/gtest.BUILD

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cc_library(
2+
name = "main",
3+
srcs = glob(
4+
["src/*.cc"],
5+
exclude = ["src/gtest-all.cc"]
6+
),
7+
hdrs = glob([
8+
"include/**/*.h",
9+
"src/*.h"
10+
]),
11+
copts = ["-Iexternal/gtest/include"],
12+
linkopts = ["-pthread"],
13+
visibility = ["//visibility:public"],
14+
)

third_party/protobuf_test/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ cpp_proto_library(
77
protos = [
88
"example.proto"
99
],
10+
with_grpc = True,
1011
)
1112

1213
cc_library(
@@ -15,3 +16,13 @@ cc_library(
1516
hdrs = ["example_lib.h"],
1617
deps = [":example_proto"],
1718
)
19+
20+
cc_test(
21+
name = "example_lib_test",
22+
srcs = ["example_lib_test.cc"],
23+
copts = ["-Iexternal/gtest/include"],
24+
deps =[
25+
"@gtest//:main",
26+
":example_lib",
27+
],
28+
)

third_party/protobuf_test/example.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
syntax = "proto3";
22

3-
package protos;
3+
package third_party.protobuf_test;
44

55
message Greeting {
66
string name = 1;
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#include "third_party/protobuf_test/example_lib.h"
2-
#include <string>
32

4-
std::string get_greet(const ::protos::Greeting& who) {
3+
namespace third_party {
4+
namespace protobuf_test {
5+
6+
std::string get_greet(const Greeting& who) {
57
return "Hello " + who.name();
68
}
9+
10+
} // namespace protobuf_test
11+
} // namespace thrid_party

third_party/protobuf_test/example_lib.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44

55
#include <string>
66

7-
std::string get_greet(const ::protos::Greeting &who);
7+
namespace third_party {
8+
namespace protobuf_test {
9+
10+
std::string get_greet(const Greeting &who);
11+
12+
} // namespace protobuf_test
13+
} // namespace third_party
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "third_party/protobuf_test/example_lib.h"
2+
3+
#include "gtest/gtest.h"
4+
5+
namespace third_party {
6+
namespace protobuf_test {
7+
8+
TEST(ProtobufTest, GetGreet) {
9+
Greeting g;
10+
g.set_name("Paddle");
11+
EXPECT_EQ("Hello Paddle", get_greet(g));
12+
}
13+
14+
} // namespace protobuf_test
15+
} // namespace third_party

0 commit comments

Comments
 (0)