-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathOptionsTest.cpp
More file actions
33 lines (31 loc) · 1.09 KB
/
Copy pathOptionsTest.cpp
File metadata and controls
33 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "catch.hpp"
#include "Options.h"
#include <vector>
#include <string>
#include <boost/tokenizer.hpp>
#include <algorithm>
namespace {
Options opt(const std::string& str) {
std::vector<std::string> tokens;
boost::tokenizer<boost::char_separator<char>> tokenizer{str, boost::char_separator<char>{" "}};
tokens.insert(tokens.end(), tokenizer.begin(), tokenizer.end());
std::vector<const char*> cmdline{"doh"};
transform(tokens.begin(), tokens.end(), back_inserter(cmdline),
[](const auto& str) { return str.c_str(); });
return Options{static_cast<int>(cmdline.size()), cmdline.data()};
}
}
TEST_CASE("Options") {
SECTION("throws when given") {
SECTION("four positionals") { REQUIRE_THROWS(opt("0.0.0.0 1080 8000 fourth_wheel")); }
SECTION("zero threads") { REQUIRE_THROWS(opt("--threads 0")); }
}
SECTION("When given help") {
auto options = opt("--help");
SECTION("is_help is true") { REQUIRE(options.is_help()); }
}
SECTION("Help string isn't blank") {
auto options = opt("--help");
REQUIRE(options.get_help().size() > 0);
}
}