bin: consolidate clients
[m6w6/libmemcached] / test / tests / bin / memerror.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/Shell.hpp"
3 #include "test/lib/Server.hpp"
4 #include "test/lib/Retry.hpp"
5 #include "test/lib/ReturnMatcher.hpp"
6
7 using Catch::Matchers::Contains;
8
9 TEST_CASE("bin/memerror") {
10 Shell sh{string{TESTING_ROOT "/../src/bin"}};
11
12 SECTION("--help") {
13 string output;
14 REQUIRE(sh.run("memerror --help", output));
15 REQUIRE_THAT(output, Contains("memerror v1"));
16 REQUIRE_THAT(output, Contains("Usage:"));
17 REQUIRE_THAT(output, Contains("code [code ...]"));
18 REQUIRE_THAT(output, Contains("Options:"));
19 REQUIRE_THAT(output, Contains("-h|--help"));
20 REQUIRE_THAT(output, Contains("-V|--version"));
21 REQUIRE_THAT(output, Contains("Environment:"));
22 REQUIRE_THAT(output, Contains("MEMCACHED_SERVERS"));
23 }
24
25 SECTION("valid error codes") {
26 for (underlying_type_t<memcached_return_t> rc = MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; ++rc) {
27 string output;
28 REQUIRE(sh.run("memerror " + to_string(rc), output));
29 CHECK(output == memcached_strerror(nullptr, static_cast<memcached_return_t>(rc)) + string{"\n"});
30 }
31 }
32
33 SECTION("unknown error code") {
34 string output;
35 REQUIRE_FALSE(sh.run("memerror " + to_string(MEMCACHED_MAXIMUM_RETURN), output));
36 REQUIRE_THAT(output, Contains("INVALID memcached_return_t"));
37 }
38 }