From 4762ae46c5895f6911d11d87c9d0b1c540f75686 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 17 Nov 2020 20:44:32 +0100 Subject: [PATCH] bin: consolidate clients --- src/bin/memerror.cc | 10 ++++++++-- test/tests/bin/memdump.cpp | 16 ++++++++-------- test/tests/bin/memerror.cpp | 15 ++++++++------- test/tests/bin/memexist.cpp | 17 +++++++++-------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/bin/memerror.cc b/src/bin/memerror.cc index f78afed7..3948ff3e 100644 --- a/src/bin/memerror.cc +++ b/src/bin/memerror.cc @@ -52,6 +52,7 @@ int main(int argc, char *argv[]) { exit(EXIT_FAILURE); } + auto exit_code = EXIT_SUCCESS; for (auto arg = argp; *arg; ++arg) { auto code = std::stoul(*arg); auto rc = static_cast(code); @@ -60,8 +61,13 @@ int main(int argc, char *argv[]) { std::cout << "code: " << code << "\n"; std::cout << "name: "; } - std::cout << memcached_strerror(nullptr, rc) << std::endl; + if (rc >= MEMCACHED_MAXIMUM_RETURN) { + exit_code = EXIT_FAILURE; + std::cerr << memcached_strerror(nullptr, rc) << std::endl; + } else { + std::cout << memcached_strerror(nullptr, rc) << std::endl; + } } - exit(EXIT_SUCCESS); + exit(exit_code); } diff --git a/test/tests/bin/memdump.cpp b/test/tests/bin/memdump.cpp index e16f5e3e..48cfa990 100644 --- a/test/tests/bin/memdump.cpp +++ b/test/tests/bin/memdump.cpp @@ -12,19 +12,19 @@ TEST_CASE("bin/memdump") { SECTION("no servers provided") { string output; REQUIRE_FALSE(sh.run("memdump", output)); - REQUIRE(output == "No Servers provided\n"); + REQUIRE(output == "No servers provided.\n"); } SECTION("--help") { string output; REQUIRE(sh.run("memdump --help", output)); - REQUIRE_THAT(output, Contains("memdump")); - REQUIRE_THAT(output, Contains("v1")); - REQUIRE_THAT(output, Contains("help")); - REQUIRE_THAT(output, Contains("version")); - REQUIRE_THAT(output, Contains("option")); - REQUIRE_THAT(output, Contains("--")); - REQUIRE_THAT(output, Contains("=")); + REQUIRE_THAT(output, Contains("memdump v1")); + REQUIRE_THAT(output, Contains("Usage:")); + REQUIRE_THAT(output, Contains("Options:")); + REQUIRE_THAT(output, Contains("-h|--help")); + REQUIRE_THAT(output, Contains("-V|--version")); + REQUIRE_THAT(output, Contains("Environment:")); + REQUIRE_THAT(output, Contains("MEMCACHED_SERVERS")); } SECTION("with server") { diff --git a/test/tests/bin/memerror.cpp b/test/tests/bin/memerror.cpp index 64637894..a4f2cbaa 100644 --- a/test/tests/bin/memerror.cpp +++ b/test/tests/bin/memerror.cpp @@ -12,13 +12,14 @@ TEST_CASE("bin/memerror") { SECTION("--help") { string output; REQUIRE(sh.run("memerror --help", output)); - REQUIRE_THAT(output, Contains("memerror")); - REQUIRE_THAT(output, Contains("v1")); - REQUIRE_THAT(output, Contains("help")); - REQUIRE_THAT(output, Contains("version")); - REQUIRE_THAT(output, Contains("option")); - REQUIRE_THAT(output, Contains("--")); - REQUIRE_THAT(output, Contains("=")); + REQUIRE_THAT(output, Contains("memerror v1")); + REQUIRE_THAT(output, Contains("Usage:")); + REQUIRE_THAT(output, Contains("code [code ...]")); + REQUIRE_THAT(output, Contains("Options:")); + REQUIRE_THAT(output, Contains("-h|--help")); + REQUIRE_THAT(output, Contains("-V|--version")); + REQUIRE_THAT(output, Contains("Environment:")); + REQUIRE_THAT(output, Contains("MEMCACHED_SERVERS")); } SECTION("valid error codes") { diff --git a/test/tests/bin/memexist.cpp b/test/tests/bin/memexist.cpp index 994727d4..26bf60d7 100644 --- a/test/tests/bin/memexist.cpp +++ b/test/tests/bin/memexist.cpp @@ -12,19 +12,20 @@ TEST_CASE("bin/memexist") { SECTION("no servers provided") { string output; REQUIRE_FALSE(sh.run("memexist", output)); - REQUIRE(output == "No Servers provided\n"); + REQUIRE(output == "No servers provided.\n"); } SECTION("--help") { string output; REQUIRE(sh.run("memexist --help", output)); - REQUIRE_THAT(output, Contains("memexist")); - REQUIRE_THAT(output, Contains("v1")); - REQUIRE_THAT(output, Contains("help")); - REQUIRE_THAT(output, Contains("version")); - REQUIRE_THAT(output, Contains("option")); - REQUIRE_THAT(output, Contains("--")); - REQUIRE_THAT(output, Contains("=")); + REQUIRE_THAT(output, Contains("memexist v1")); + REQUIRE_THAT(output, Contains("Usage:")); + REQUIRE_THAT(output, Contains("key [key ...]")); + REQUIRE_THAT(output, Contains("Options:")); + REQUIRE_THAT(output, Contains("-h|--help")); + REQUIRE_THAT(output, Contains("-V|--version")); + REQUIRE_THAT(output, Contains("Environment:")); + REQUIRE_THAT(output, Contains("MEMCACHED_SERVERS")); } SECTION("with server") { -- 2.30.2