From ca476f48560a39e37ef0f5c4f8e0e25d30a150ff Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Mon, 12 Dec 2016 06:07:37 +0000 Subject: [PATCH] Add dependency to gflags and related tests --- WORKSPACE | 8 ++++++ third_party/gflags_test/BUILD | 11 ++++++++ third_party/gflags_test/gflags_test.cc | 36 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 third_party/gflags_test/BUILD create mode 100644 third_party/gflags_test/gflags_test.cc diff --git a/WORKSPACE b/WORKSPACE index d6ae2af8eb..8060047744 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -15,3 +15,11 @@ new_http_archive( build_file = "third_party/gtest.BUILD", strip_prefix = "googletest-release-1.7.0", ) + +# External dependency to gflags. This method comes from +# https://github.com/gflags/example/blob/master/WORKSPACE. +git_repository( + name = "gflags", + tag = "v2.2.0", + remote = "https://github.com/gflags/gflags.git" +) diff --git a/third_party/gflags_test/BUILD b/third_party/gflags_test/BUILD new file mode 100644 index 0000000000..c3e53afb40 --- /dev/null +++ b/third_party/gflags_test/BUILD @@ -0,0 +1,11 @@ +licenses(["notice"]) # Apache 2.0 + +cc_test( + name = "gflags_test", + srcs = ["gflags_test.cc"], + copts = ["-Iexternal/gtest/include"], + deps = [ + "@gtest//:main", + "@gflags//:gflags", + ], +) diff --git a/third_party/gflags_test/gflags_test.cc b/third_party/gflags_test/gflags_test.cc new file mode 100644 index 0000000000..5e588c2279 --- /dev/null +++ b/third_party/gflags_test/gflags_test.cc @@ -0,0 +1,36 @@ +#include +#include + +#include "gflags/gflags.h" +#include "gtest/gtest.h" + + +DEFINE_bool(verbose, false, "Display program name before message"); +DEFINE_string(message, "Hello world!", "Message to print"); + +static bool IsNonEmptyMessage(const char *flagname, const std::string &value) +{ + return value[0] != '\0'; +} +DEFINE_validator(message, &IsNonEmptyMessage); + + +namespace third_party { +namespace gflags_test { + +TEST(GflagsTest, ParseAndPrint) { + gflags::SetUsageMessage("some usage message"); + gflags::SetVersionString("1.0.0"); + int argc = 1; + char program_name[] = "gflags_test"; + char** argv = new char*[2]; + argv[0] = program_name; + argv[1] = NULL; + gflags::ParseCommandLineFlags(&argc, reinterpret_cast(&argv), true); + EXPECT_EQ("gflags_test", std::string(gflags::ProgramInvocationShortName())); + EXPECT_EQ("Hello world!", FLAGS_message); + gflags::ShutDownCommandLineFlags(); +} + +} // namespace gflags_test +} // namespace third_party -- GitLab