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