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

index 400c47efcbed5b38d3af20803f0dba74018c7949..24d3869fa15ce84bd2f08385f48e0982fbe23b91 100644 (file)
@@ -29,7 +29,7 @@ int main(int argc, char *argv[]) {
     opt.add(def);
   }
 
-  opt.add("expiration", 'e', no_argument, "Expiration time in seconds or unix timestamp.");
+  opt.add("expire", 'e', required_argument, "Expiration time in seconds or unix timestamp.");
 
   char **argp = nullptr;
   if (!opt.parse(argc, argv, &argp)) {
index 35da7dc97614206c0263f560980709376415df83..c142b8dca5a5789a7532f8df3c7e4a75700781f4 100644 (file)
@@ -12,19 +12,20 @@ TEST_CASE("bin/memtouch") {
   SECTION("no servers provided") {
     string output;
     REQUIRE_FALSE(sh.run("memtouch", output));
-    REQUIRE(output == "No Servers provided\n");
+    REQUIRE(output == "No servers provided.\n");
   }
 
   SECTION("--help") {
     string output;
     REQUIRE(sh.run("memtouch --help", output));
-    REQUIRE_THAT(output, Contains("memtouch"));
-    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("memtouch 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") {
@@ -57,7 +58,10 @@ TEST_CASE("bin/memtouch") {
     SECTION("expires") {
       REQUIRE_SUCCESS(memcached_set(*memc, S("memtouch"), S("memtouch"), 60, 0));
       REQUIRE_SUCCESS(memcached_exist(*memc, S("memtouch")));
-      REQUIRE(sh.run(comm + "--expire=" + to_string(time(nullptr) - 2) + " memtouch"));
+      string output;
+      bool ok = sh.run(comm + " -v --expire=" + to_string(time(nullptr) - 2) + " memtouch", output);
+      REQUIRE(output == "");
+      REQUIRE(ok);
       REQUIRE_RC(MEMCACHED_NOTFOUND, memcached_exist(*memc, S("memtouch")));
     }
   }