Skip to content

Commit

Permalink
- Changes gtest from new_http_archive to new_git_repository
Browse files Browse the repository at this point in the history
  with latest 1.8 (closes #11).
- Updates cpp test with main entrypoint.
- Updates readme in relation to #10.
- Bump to v0.5.1.
  • Loading branch information
pcj committed Aug 25, 2016
1 parent 08284e0 commit 5f922b7
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 24 deletions.
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,38 @@ Build label: 0.3.1
# Quick Start

Require these rules your `WORKSPACE`:
## WORKSPACE

1. Add rules_go to your workspace

Note about golang: this project uses [rules-go][rules_go] for
`go_library`, `go_binary`, and `go_test`. Even if you're not using go
support in rules_protobuf, it is a current requirement for your
WORKSPACE file (see issue #10).

```python
git_repository(
name = "org_pubref_rules_protobuf",
remote = "https://github.com/pubref/rules_protobuf",
tag = "v0.5.0",
name = "io_bazel_rules_go",
tag = "0.0.4",
remote = "https://github.com/bazelbuild/rules_go.git",
)
load("@io_bazel_rules_go//go:def.bzl", "go_repositories")
go_repositories()
```

Trigger loading of external dependencies. Specify the language(s)
you'd like support for.

2. Require these rules your `WORKSPACE` and trigger loading of
external dependencies. Specify the language(s) you'd like support
for.:

```python
git_repository(
name = "org_pubref_rules_protobuf",
remote = "https://github.com/pubref/rules_protobuf",
tag = "v0.5.1",
)

load("@org_pubref_rules_protobuf//bzl:rules.bzl", "protobuf_repositories")

protobuf_repositories(
with_go = True,
with_java = True,
Expand All @@ -86,6 +102,8 @@ protobuf_repositories(
> the set of external dependencies that will be loaded into your
> project.
## BUILD

Build a java-based gRPC library:

```python
Expand Down
113 changes: 102 additions & 11 deletions bzl/build_file/gtest.BUILD
Original file line number Diff line number Diff line change
@@ -1,14 +1,105 @@
# Adapted from https://github.com/mzhaom/trunk/blob/master/third_party/gtest/BUILD
licenses(["notice"])

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"],
name = "gtest",
testonly = 1,
visibility = ["//visibility:public"],
includes = [
"googletest/include",
],
hdrs = [
"googletest/include/gtest/gtest-death-test.h",
"googletest/include/gtest/gtest-message.h",
"googletest/include/gtest/gtest_pred_impl.h",
"googletest/include/gtest/gtest-test-part.h",
"googletest/include/gtest/gtest.h",
"googletest/include/gtest/gtest-param-test.h",
"googletest/include/gtest/gtest-printers.h",
"googletest/include/gtest/gtest-spi.h",
"googletest/include/gtest/gtest-typed-test.h"
],
srcs = glob([
"googletest/include/gtest/internal/**/*.h"
]) + [
"googletest/src/gtest-internal-inl.h",
"googletest/src/gtest-death-test.cc",
"googletest/src/gtest-filepath.cc",
"googletest/src/gtest-port.cc",
"googletest/src/gtest-printers.cc",
"googletest/src/gtest-test-part.cc",
"googletest/src/gtest-typed-test.cc",
"googletest/src/gtest.cc",
],
copts = [
"-Iexternal/gtest/googletest"
],
deps = [
":gtest_prod",
],
)

cc_library(
name = "gtest_main",
testonly = 1,
visibility = ["//visibility:public"],
deps = [
":gtest",
],
srcs = [
"googletest/src/gtest_main.cc",
],
)

cc_library(
name = "gtest_prod",
visibility = ["//visibility:public"],
hdrs = [
"googletest/include/gtest/gtest_prod.h",
],
)

cc_library(
name = "googlemock",
testonly = 1,
visibility = ["//visibility:public"],
hdrs = [
"googlemock/include/gmock/gmock-actions.h",
"googlemock/include/gmock/gmock-cardinalities.h",
"googlemock/include/gmock/gmock-generated-actions.h",
"googlemock/include/gmock/gmock-generated-function-mockers.h",
"googlemock/include/gmock/gmock-generated-matchers.h",
"googlemock/include/gmock/gmock-generated-nice-strict.h",
"googlemock/include/gmock/gmock.h",
"googlemock/include/gmock/gmock-matchers.h",
"googlemock/include/gmock/gmock-more-actions.h",
"googlemock/include/gmock/gmock-more-matchers.h",
"googlemock/include/gmock/gmock-spec-builders.h",
],
srcs = glob([
"googlemock/include/gmock/internal/**/*.h"
]) + [
"googlemock/src/gmock-cardinalities.cc",
"googlemock/src/gmock.cc",
"googlemock/src/gmock-internal-utils.cc",
"googlemock/src/gmock-matchers.cc",
"googlemock/src/gmock-spec-builders.cc",
],
deps = [
":gtest",
],
includes = [
"googlemock/include",
],
)

cc_library(
name = "gmock_main",
visibility = ["//visibility:public"],
deps = [
":gmock",
],
srcs = [
"googlemock/src/gmock_main.cc",
],
)
7 changes: 3 additions & 4 deletions bzl/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,11 @@ REPOSITORIES = {

# GTest is for our own internal cc tests.
"gtest": {
"kind": "new_http_archive",
"kind": "new_git_repository",
"name": "gtest",
"url": "https://googletest.googlecode.com/files/gtest-1.7.0.zip",
"sha256": "247ca18dd83f53deb1328be17e4b1be31514cedfc1e3424f672bf11fd7e0d60d",
"remote": "https://github.com/google/googletest.git",
"commit": "ed9d1e1ff92ce199de5ca2667a667cd0a368482a",
"build_file": str(Label("//bzl:build_file/gtest.BUILD")),
"strip_prefix": "gtest-1.7.0",
},

# ****************************************************************
Expand Down
3 changes: 3 additions & 0 deletions bzl/util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def require(target, context):
# for ext in requires:
# require(ext, opts)

if not hasattr(native, kind):
fail("No native workspace rule named '%s' in dependency %s" % (kind, name))

rule = getattr(native, kind)
if not rule:
fail("During require (%s), kind '%s' has no matching native rule" % (target, dep.kind))
Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cc_test(
tags = ["exclusive"],
deps = [
":clientlib",
"@gtest//:main",
"@gtest//:gtest",
],
)

Expand Down
7 changes: 6 additions & 1 deletion examples/helloworld/cpp/greeter_client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ class GreeterClientTest : public ::testing::Test {
// so at some level, even if we can run a test that does nothing is a
// success.


TEST_F(GreeterClientTest, testHello) {
GreeterClient greeter(grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials()));
std::string user("world");
std::string reply = ("Hello world");
//std::string reply = greeter.SayHello(user);
EXPECT_EQ("Hello world", reply);
}


int main(int ac, char* av[]) {
testing::InitGoogleTest(&ac, av);
return RUN_ALL_TESTS();
}

0 comments on commit 5f922b7

Please sign in to comment.