Commit 1b2af21a2db77b9ccf0b9432b38df6936b7068b1

Authored by Henry Fredrick Schreiner
1 parent d070f32e

Added more tests, some fixes

include/CLI.hpp
@@ -289,7 +289,10 @@ lexical_cast(std::string input, T& output) { @@ -289,7 +289,10 @@ lexical_cast(std::string input, T& output) {
289 289
290 // String and similar 290 // String and similar
291 template<typename T> 291 template<typename T>
292 -bool lexical_cast(std::string input, T& output) { 292 +typename std::enable_if<
  293 + !std::is_floating_point<T>::value
  294 + && !std::is_integral<T>::value, bool>::type
  295 +lexical_cast(std::string input, T& output) {
293 logit("Direct lexical cast: " + input); 296 logit("Direct lexical cast: " + input);
294 output = input; 297 output = input;
295 return true; 298 return true;
tests/CLItest.cpp
@@ -36,9 +36,79 @@ struct TApp : public ::testing::Test { @@ -36,9 +36,79 @@ struct TApp : public ::testing::Test {
36 36
37 }; 37 };
38 38
39 -TEST_F(TApp, AFewArgs) { 39 +TEST_F(TApp, OneFlagShort) {
40 app.add_flag("c,count"); 40 app.add_flag("c,count");
41 args = {"-c"}; 41 args = {"-c"};
42 run(); 42 run();
  43 + EXPECT_EQ(1, app.count("c"));
43 EXPECT_EQ(1, app.count("count")); 44 EXPECT_EQ(1, app.count("count"));
44 } 45 }
  46 +
  47 +TEST_F(TApp, OneFlagLong) {
  48 + app.add_flag("c,count");
  49 + args = {"--count"};
  50 + run();
  51 + EXPECT_EQ(1, app.count("c"));
  52 + EXPECT_EQ(1, app.count("count"));
  53 +}
  54 +
  55 +TEST_F(TApp, OneFlagRef) {
  56 + int ref;
  57 + app.add_flag("c,count", ref);
  58 + args = {"--count"};
  59 + run();
  60 + EXPECT_EQ(1, app.count("c"));
  61 + EXPECT_EQ(1, app.count("count"));
  62 + EXPECT_EQ(1, ref);
  63 +}
  64 +
  65 +TEST_F(TApp, OneString) {
  66 + std::string str;
  67 + app.add_option("s,string", str);
  68 + args = {"--string", "mystring"};
  69 + run();
  70 + EXPECT_EQ(1, app.count("s"));
  71 + EXPECT_EQ(1, app.count("string"));
  72 + EXPECT_EQ(str, "mystring");
  73 +}
  74 +
  75 +
  76 +TEST_F(TApp, TogetherInt) {
  77 + int i;
  78 + app.add_option("i,int", i);
  79 + args = {"-i4"};
  80 + run();
  81 + EXPECT_EQ(1, app.count("int"));
  82 + EXPECT_EQ(1, app.count("i"));
  83 + EXPECT_EQ(i, 4);
  84 +}
  85 +
  86 +TEST_F(TApp, SepInt) {
  87 + int i;
  88 + app.add_option("i,int", i);
  89 + args = {"-i","4"};
  90 + run();
  91 + EXPECT_EQ(1, app.count("int"));
  92 + EXPECT_EQ(1, app.count("i"));
  93 + EXPECT_EQ(i, 4);
  94 +}
  95 +
  96 +TEST_F(TApp, OneStringAgain) {
  97 + std::string str;
  98 + app.add_option("s,string", str);
  99 + args = {"--string", "mystring"};
  100 + run();
  101 + EXPECT_EQ(1, app.count("s"));
  102 + EXPECT_EQ(1, app.count("string"));
  103 + EXPECT_EQ(str, "mystring");
  104 +}
  105 +
  106 +
  107 +TEST_F(TApp, DefaultStringAgain) {
  108 + std::string str = "previous";
  109 + app.add_option("s,string", str);
  110 + run();
  111 + EXPECT_EQ(0, app.count("s"));
  112 + EXPECT_EQ(0, app.count("string"));
  113 + EXPECT_EQ(str, "previous");
  114 +}
tests/CMakeLists.txt
@@ -2,6 +2,15 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR) @@ -2,6 +2,15 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
2 2
3 add_subdirectory(googletest) 3 add_subdirectory(googletest)
4 4
  5 +if (CMAKE_CONFIGURATION_TYPES)
  6 + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
  7 + --force-new-ctest-process --output-on-failure
  8 + --build-config "$<CONFIGURATION>")
  9 +else()
  10 + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
  11 + --force-new-ctest-process --output-on-failure)
  12 +endif()
  13 +
5 include_directories(${gtest_SOURCE_DIR}/include) 14 include_directories(${gtest_SOURCE_DIR}/include)
6 15
7 add_executable(CLITest CLITest.cpp ${headers}) 16 add_executable(CLITest CLITest.cpp ${headers})