From 239d3b1c31cac102d5e2524f9d22ab483c7a61e8 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Sun, 23 Apr 2017 13:57:01 -0400 Subject: [PATCH] Fixes for compiler warnings with max warnings on Xcode --- include/CLI/App.hpp | 6 +-- include/CLI/Option.hpp | 2 +- include/CLI/StringTools.hpp | 4 +- include/CLI/Timer.hpp | 4 +- tests/AppTest.cpp | 88 ++++++++++++++++++------------------- tests/HelpTest.cpp | 2 +- 6 files changed, 53 insertions(+), 53 deletions(-) diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 4c3998b0..622b3f26 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -565,7 +565,7 @@ public: ///@{ /// Counts the number of times the given option was passed. - int count(std::string name) const { + size_t count(std::string name) const { for(const Option_p &opt : options_) { if(opt->check_name(name)) { return opt->count(); @@ -878,7 +878,7 @@ protected: for(const Option_p& opt : options_) { // Required if (opt->get_required() - && (opt->count() < opt->get_expected() || opt->count() == 0)) + && ((int) opt->count() < opt->get_expected() || opt->count() == 0)) throw RequiredError(opt->get_name()); // Requires for (const Option* opt_req : opt->requires_) @@ -1005,7 +1005,7 @@ protected: for(const Option_p& opt : options_) { // Eat options, one by one, until done if ( opt->get_positional() - && (opt->count() < opt->get_expected() + && ((int) opt->count() < opt->get_expected() || opt->get_expected() < 0) ) { diff --git a/include/CLI/Option.hpp b/include/CLI/Option.hpp index a1e53e56..0e03d7db 100644 --- a/include/CLI/Option.hpp +++ b/include/CLI/Option.hpp @@ -123,7 +123,7 @@ public: ///@{ /// Count the total number of times an option was passed - int count() const { + size_t count() const { return results_.size(); } diff --git a/include/CLI/StringTools.hpp b/include/CLI/StringTools.hpp index d5400635..52faf459 100644 --- a/include/CLI/StringTools.hpp +++ b/include/CLI/StringTools.hpp @@ -113,10 +113,10 @@ inline std::string trim_copy(const std::string &str, const std::string &filter) /// Print a two part "help" string inline void format_help(std::stringstream &out, std::string name, std::string description, size_t wid) { name = " " + name; - out << std::setw(wid) << std::left << name; + out << std::setw((int) wid) << std::left << name; if(description != "") { if(name.length()>=wid) - out << std::endl << std::setw(wid) << ""; + out << std::endl << std::setw((int) wid) << ""; out << description; } out << std::endl; diff --git a/include/CLI/Timer.hpp b/include/CLI/Timer.hpp index 89c4a844..158d3542 100644 --- a/include/CLI/Timer.hpp +++ b/include/CLI/Timer.hpp @@ -75,6 +75,7 @@ public: return make_time_str(time); } + // LCOV_EXCL_START std::string make_time_str(double time) const { auto print_it = [](double x, std::string unit){ char buffer[50]; @@ -82,7 +83,6 @@ public: return buffer + std::string(" ") + unit; }; - // LCOV_EXCL_START if(time < .000001) return print_it(time*1000000000, "ns"); else if(time < .001) @@ -91,8 +91,8 @@ public: return print_it(time*1000, "ms"); else return print_it(time, "s"); - // LCOV_EXCL_END } + // LCOV_EXCL_END /// This is the main function, it creates a string std::string to_string() const { diff --git a/tests/AppTest.cpp b/tests/AppTest.cpp index 399543f3..cbd0fece 100644 --- a/tests/AppTest.cpp +++ b/tests/AppTest.cpp @@ -6,8 +6,8 @@ TEST_F(TApp, OneFlagShort) { app.add_flag("-c,--count"); args = {"-c"}; run(); - EXPECT_EQ(1, app.count("-c")); - EXPECT_EQ(1, app.count("--count")); + EXPECT_EQ((size_t) 1, app.count("-c")); + EXPECT_EQ((size_t) 1, app.count("--count")); } TEST_F(TApp, CountNonExist) { @@ -21,8 +21,8 @@ TEST_F(TApp, OneFlagLong) { app.add_flag("-c,--count"); args = {"--count"}; run(); - EXPECT_EQ(1, app.count("-c")); - EXPECT_EQ(1, app.count("--count")); + EXPECT_EQ((size_t) 1, app.count("-c")); + EXPECT_EQ((size_t) 1, app.count("--count")); } TEST_F(TApp, DashedOptions) { @@ -32,10 +32,10 @@ TEST_F(TApp, DashedOptions) { args = {"-c", "--q", "--this", "--that"}; run(); - EXPECT_EQ(1, app.count("-c")); - EXPECT_EQ(1, app.count("--q")); - EXPECT_EQ(2, app.count("--this")); - EXPECT_EQ(2, app.count("--that")); + EXPECT_EQ((size_t) 1, app.count("-c")); + EXPECT_EQ((size_t) 1, app.count("--q")); + EXPECT_EQ((size_t) 2, app.count("--this")); + EXPECT_EQ((size_t) 2, app.count("--that")); } @@ -44,8 +44,8 @@ TEST_F(TApp, OneFlagRef) { app.add_flag("-c,--count", ref); args = {"--count"}; run(); - EXPECT_EQ(1, app.count("-c")); - EXPECT_EQ(1, app.count("--count")); + EXPECT_EQ((size_t) 1, app.count("-c")); + EXPECT_EQ((size_t) 1, app.count("--count")); EXPECT_EQ(1, ref); } @@ -54,8 +54,8 @@ TEST_F(TApp, OneString) { app.add_option("-s,--string", str); args = {"--string", "mystring"}; run(); - EXPECT_EQ(1, app.count("-s")); - EXPECT_EQ(1, app.count("--string")); + EXPECT_EQ((size_t) 1, app.count("-s")); + EXPECT_EQ((size_t) 1, app.count("--string")); EXPECT_EQ(str, "mystring"); } @@ -64,8 +64,8 @@ TEST_F(TApp, OneStringEqualVersion) { app.add_option("-s,--string", str); args = {"--string=mystring"}; run(); - EXPECT_EQ(1, app.count("-s")); - EXPECT_EQ(1, app.count("--string")); + EXPECT_EQ((size_t) 1, app.count("-s")); + EXPECT_EQ((size_t) 1, app.count("--string")); EXPECT_EQ(str, "mystring"); } @@ -75,8 +75,8 @@ TEST_F(TApp, TogetherInt) { app.add_option("-i,--int", i); args = {"-i4"}; run(); - EXPECT_EQ(1, app.count("--int")); - EXPECT_EQ(1, app.count("-i")); + EXPECT_EQ((size_t) 1, app.count("--int")); + EXPECT_EQ((size_t) 1, app.count("-i")); EXPECT_EQ(i, 4); } @@ -85,8 +85,8 @@ TEST_F(TApp, SepInt) { app.add_option("-i,--int", i); args = {"-i","4"}; run(); - EXPECT_EQ(1, app.count("--int")); - EXPECT_EQ(1, app.count("-i")); + EXPECT_EQ((size_t) 1, app.count("--int")); + EXPECT_EQ((size_t) 1, app.count("-i")); EXPECT_EQ(i, 4); } @@ -95,8 +95,8 @@ TEST_F(TApp, OneStringAgain) { app.add_option("-s,--string", str); args = {"--string", "mystring"}; run(); - EXPECT_EQ(1, app.count("-s")); - EXPECT_EQ(1, app.count("--string")); + EXPECT_EQ((size_t) 1, app.count("-s")); + EXPECT_EQ((size_t) 1, app.count("--string")); EXPECT_EQ(str, "mystring"); } @@ -105,8 +105,8 @@ TEST_F(TApp, DefaultStringAgain) { std::string str = "previous"; app.add_option("-s,--string", str); run(); - EXPECT_EQ(0, app.count("-s")); - EXPECT_EQ(0, app.count("--string")); + EXPECT_EQ((size_t) 0, app.count("-s")); + EXPECT_EQ((size_t) 0, app.count("--string")); EXPECT_EQ(str, "previous"); } @@ -134,9 +134,9 @@ TEST_F(TApp, LotsOfFlags) { args = {"-a","-b","-aA"}; run(); - EXPECT_EQ(2, app.count("-a")); - EXPECT_EQ(1, app.count("-b")); - EXPECT_EQ(1, app.count("-A")); + EXPECT_EQ((size_t) 2, app.count("-a")); + EXPECT_EQ((size_t) 1, app.count("-b")); + EXPECT_EQ((size_t) 1, app.count("-A")); } @@ -182,8 +182,8 @@ TEST_F(TApp, ShortOpts) { run(); - EXPECT_EQ(2, app.count("-z")); - EXPECT_EQ(1, app.count("-y")); + EXPECT_EQ((size_t) 2, app.count("-z")); + EXPECT_EQ((size_t) 1, app.count("-y")); EXPECT_EQ((unsigned long long) 2, funnyint); EXPECT_EQ("zyz", someopt); } @@ -200,8 +200,8 @@ TEST_F(TApp, DefaultOpts) { run(); - EXPECT_EQ(1, app.count("i")); - EXPECT_EQ(1, app.count("-s")); + EXPECT_EQ((size_t) 1, app.count("i")); + EXPECT_EQ((size_t) 1, app.count("-s")); EXPECT_EQ(2, i); EXPECT_EQ("9", s); } @@ -238,8 +238,8 @@ TEST_F(TApp, Positionals) { run(); - EXPECT_EQ(1, app.count("posit1")); - EXPECT_EQ(1, app.count("posit2")); + EXPECT_EQ((size_t) 1, app.count("posit1")); + EXPECT_EQ((size_t) 1, app.count("posit2")); EXPECT_EQ("thing1", posit1); EXPECT_EQ("thing2", posit2); } @@ -278,8 +278,8 @@ TEST_F(TApp, MixedPositionals) { run(); - EXPECT_EQ(1, app.count("posit2")); - EXPECT_EQ(1, app.count("--posit1")); + EXPECT_EQ((size_t) 1, app.count("posit2")); + EXPECT_EQ((size_t) 1, app.count("--posit1")); EXPECT_EQ(7, positional_int); EXPECT_EQ("thing2", positional_string); } @@ -311,19 +311,19 @@ TEST_F(TApp, Reset) { run(); - EXPECT_EQ(1, app.count("--simple")); - EXPECT_EQ(1, app.count("-d")); + EXPECT_EQ((size_t) 1, app.count("--simple")); + EXPECT_EQ((size_t) 1, app.count("-d")); EXPECT_DOUBLE_EQ(1.2, doub); app.reset(); - EXPECT_EQ(0, app.count("--simple")); - EXPECT_EQ(0, app.count("-d")); + EXPECT_EQ((size_t) 0, app.count("--simple")); + EXPECT_EQ((size_t) 0, app.count("-d")); run(); - EXPECT_EQ(1, app.count("--simple")); - EXPECT_EQ(1, app.count("-d")); + EXPECT_EQ((size_t) 1, app.count("--simple")); + EXPECT_EQ((size_t) 1, app.count("-d")); EXPECT_DOUBLE_EQ(1.2, doub); } @@ -470,7 +470,7 @@ TEST_F(TApp, VectorFixedString) { args = {"--string", "mystring", "mystring2", "mystring3"}; run(); - EXPECT_EQ(3, app.count("--string")); + EXPECT_EQ((size_t) 3, app.count("--string")); EXPECT_EQ(answer, strvec); } @@ -485,13 +485,13 @@ TEST_F(TApp, VectorUnlimString) { args = {"--string", "mystring", "mystring2", "mystring3"}; run(); - EXPECT_EQ(3, app.count("--string")); + EXPECT_EQ((size_t) 3, app.count("--string")); EXPECT_EQ(answer, strvec); app.reset(); args = {"-s", "mystring", "mystring2", "mystring3"}; run(); - EXPECT_EQ(3, app.count("--string")); + EXPECT_EQ((size_t) 3, app.count("--string")); EXPECT_EQ(answer, strvec); } @@ -505,7 +505,7 @@ TEST_F(TApp, VectorFancyOpts) { args = {"--string", "mystring", "mystring2", "mystring3"}; run(); - EXPECT_EQ(3, app.count("--string")); + EXPECT_EQ((size_t) 3, app.count("--string")); EXPECT_EQ(answer, strvec); app.reset(); @@ -696,7 +696,7 @@ TEST_F(TApp, Env) { run(); EXPECT_EQ(2, val); - EXPECT_EQ(1, vopt->count()); + EXPECT_EQ((size_t) 1, vopt->count()); app.reset(); vopt->required(); diff --git a/tests/HelpTest.cpp b/tests/HelpTest.cpp index 49b35359..a5f4bf3d 100644 --- a/tests/HelpTest.cpp +++ b/tests/HelpTest.cpp @@ -219,7 +219,7 @@ TEST(THelp, Subcom) { char y[] = "sub2"; std::vector args = {x,y}; - app.parse(args.size(), args.data()); + app.parse((int) args.size(), args.data()); help = app.help(); EXPECT_THAT(help, HasSubstr("Usage: ./myprogram sub2"));