bin: consolidate clients
authorMichael Wallner <mike@php.net>
Tue, 17 Nov 2020 19:44:32 +0000 (20:44 +0100)
committerMichael Wallner <mike@php.net>
Tue, 17 Nov 2020 19:44:32 +0000 (20:44 +0100)
src/bin/memerror.cc
test/tests/bin/memdump.cpp
test/tests/bin/memerror.cpp
test/tests/bin/memexist.cpp

index f78afed7328fa4b5f9a496f3f619430d6f339a7a..3948ff3e79d074db5d7c35941b13c2506a7f73a4 100644 (file)
@@ -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<memcached_return_t>(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);
 }
index e16f5e3e39dc6cd3668ff015dea9b5b23664c5d4..48cfa9906d6d9da805680f3c4aae95103d550e3c 100644 (file)
@@ -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") {
index 64637894e080e5ce71bbbf08fbb2e94749e043e3..a4f2cbaa2e8693ad0978cd449b08e70abbc31966 100644 (file)
@@ -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") {
index 994727d48e23ec74e2035cbebb20a24072dc9df9..26bf60d79d3088487eed1db05a955d5464646a16 100644 (file)
@@ -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") {