Skip to content

Commit

Permalink
Adding tests, moved deprecated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Feb 18, 2019
1 parent b9ef32d commit bbdf90c
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 51 deletions.
45 changes: 30 additions & 15 deletions include/CLI/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ class App {
}
#endif

/// Add set of options (No default, temp reference, such as an inline set)
/// Add set of options (No default, temp reference, such as an inline set) DEPRECATED
template <typename T>
Option *add_set(std::string option_name,
T &member, ///< The selected member of the set
Expand All @@ -656,7 +656,7 @@ class App {
return opt;
}

/// Add set of options (No default, set can be changed afterwords - do not destroy the set)
/// Add set of options (No default, set can be changed afterwords - do not destroy the set) DEPRECATED
template <typename T>
Option *add_mutable_set(std::string option_name,
T &member, ///< The selected member of the set
Expand All @@ -668,7 +668,7 @@ class App {
return opt;
}

/// Add set of options (with default, static set, such as an inline set)
/// Add set of options (with default, static set, such as an inline set) DEPRECATED
template <typename T>
Option *add_set(std::string option_name,
T &member, ///< The selected member of the set
Expand All @@ -681,7 +681,7 @@ class App {
return opt;
}

/// Add set of options (with default, set can be changed afterwards - do not destroy the set)
/// Add set of options (with default, set can be changed afterwards - do not destroy the set) DEPRECATED
template <typename T>
Option *add_mutable_set(std::string option_name,
T &member, ///< The selected member of the set
Expand All @@ -694,7 +694,8 @@ class App {
return opt;
}

/// Add set of options, string only, ignore case (no default, static set)
/// Add set of options, string only, ignore case (no default, static set) DEPRECATED
CLI11_DEPRECATED("Use ->check(CLI::IsMember(..., CLI::ignore_case)) instead")
Option *add_set_ignore_case(std::string option_name,
std::string &member, ///< The selected member of the set
std::set<std::string> options, ///< The set of possibilities
Expand All @@ -706,7 +707,8 @@ class App {
}

/// Add set of options, string only, ignore case (no default, set can be changed afterwards - do not destroy the
/// set)
/// set) DEPRECATED
CLI11_DEPRECATED("Use ->check(CLI::IsMember(..., CLI::ignore_case)) with a (shared) pointer instead")
Option *add_mutable_set_ignore_case(std::string option_name,
std::string &member, ///< The selected member of the set
const std::set<std::string> &options, ///< The set of possibilities
Expand All @@ -717,7 +719,8 @@ class App {
return opt;
}

/// Add set of options, string only, ignore case (default, static set)
/// Add set of options, string only, ignore case (default, static set) DEPRECATED
CLI11_DEPRECATED("Use ->check(CLI::IsMember(..., CLI::ignore_case)) instead")
Option *add_set_ignore_case(std::string option_name,
std::string &member, ///< The selected member of the set
std::set<std::string> options, ///< The set of possibilities
Expand All @@ -730,6 +733,8 @@ class App {
}

/// Add set of options, string only, ignore case (default, set can be changed afterwards - do not destroy the set)
/// DEPRECATED
CLI11_DEPRECATED("Use ->check(CLI::IsMember(...)) with a (shared) pointer instead")
Option *add_mutable_set_ignore_case(std::string option_name,
std::string &member, ///< The selected member of the set
const std::set<std::string> &options, ///< The set of possibilities
Expand All @@ -741,7 +746,8 @@ class App {
return opt;
}

/// Add set of options, string only, ignore underscore (no default, static set)
/// Add set of options, string only, ignore underscore (no default, static set) DEPRECATED
CLI11_DEPRECATED("Use ->check(CLI::IsMember(..., CLI::ignore_underscore)) instead")
Option *add_set_ignore_underscore(std::string option_name,
std::string &member, ///< The selected member of the set
std::set<std::string> options, ///< The set of possibilities
Expand All @@ -753,7 +759,8 @@ class App {
}

/// Add set of options, string only, ignore underscore (no default, set can be changed afterwards - do not destroy
/// the set)
/// the set) DEPRECATED
CLI11_DEPRECATED("Use ->check(CLI::IsMember(..., CLI::ignore_underscore)) with a (shared) pointer instead")
Option *add_mutable_set_ignore_underscore(std::string option_name,
std::string &member, ///< The selected member of the set
const std::set<std::string> &options, ///< The set of possibilities
Expand All @@ -764,7 +771,8 @@ class App {
return opt;
}

/// Add set of options, string only, ignore underscore (default, static set)
/// Add set of options, string only, ignore underscore (default, static set) DEPRECATED
CLI11_DEPRECATED("Use ->check(CLI::IsMember(..., CLI::ignore_underscore)) instead")
Option *add_set_ignore_underscore(std::string option_name,
std::string &member, ///< The selected member of the set
std::set<std::string> options, ///< The set of possibilities
Expand All @@ -777,7 +785,8 @@ class App {
}

/// Add set of options, string only, ignore underscore (default, set can be changed afterwards - do not destroy the
/// set)
/// set) DEPRECATED
CLI11_DEPRECATED("Use ->check(CLI::IsMember(..., CLI::ignore_underscore)) with a (shared) pointer instead")
Option *add_mutable_set_ignore_underscore(std::string option_name,
std::string &member, ///< The selected member of the set
const std::set<std::string> &options, ///< The set of possibilities
Expand All @@ -789,7 +798,8 @@ class App {
return opt;
}

/// Add set of options, string only, ignore underscore and case (no default, static set)
/// Add set of options, string only, ignore underscore and case (no default, static set) DEPRECATED
CLI11_DEPRECATED("Use ->check(CLI::IsMember(..., CLI::ignore_case, CLI::ignore_underscore)) instead")
Option *add_set_ignore_case_underscore(std::string option_name,
std::string &member, ///< The selected member of the set
std::set<std::string> options, ///< The set of possibilities
Expand All @@ -801,7 +811,9 @@ class App {
}

/// Add set of options, string only, ignore underscore and case (no default, set can be changed afterwards - do not
/// destroy the set)
/// destroy the set) DEPRECATED
CLI11_DEPRECATED(
"Use ->check(CLI::IsMember(..., CLI::ignore_case, CLI::ignore_underscore)) with a (shared) pointer instead")
Option *add_mutable_set_ignore_case_underscore(std::string option_name,
std::string &member, ///< The selected member of the set
const std::set<std::string> &options, ///< The set of possibilities
Expand All @@ -812,7 +824,8 @@ class App {
return opt;
}

/// Add set of options, string only, ignore underscore and case (default, static set)
/// Add set of options, string only, ignore underscore and case (default, static set) DEPRECATED
CLI11_DEPRECATED("Use ->check(CLI::IsMember(..., CLI::ignore_case, CLI::ignore_underscore)) instead")
Option *add_set_ignore_case_underscore(std::string option_name,
std::string &member, ///< The selected member of the set
std::set<std::string> options, ///< The set of possibilities
Expand All @@ -825,7 +838,9 @@ class App {
}

/// Add set of options, string only, ignore underscore and case (default, set can be changed afterwards - do not
/// destroy the set)
/// destroy the set) DEPRECATED
CLI11_DEPRECATED(
"Use ->check(CLI::IsMember(..., CLI::ignore_case, CLI::ignore_underscore)) with a (shared) pointer instead")
Option *add_mutable_set_ignore_case_underscore(std::string option_name,
std::string &member, ///< The selected member of the set
const std::set<std::string> &options, ///< The set of possibilities
Expand Down
60 changes: 53 additions & 7 deletions tests/DeprecatedTest.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
#ifdef CLI11_SINGLE_FILE
#include "CLI11.hpp"
#else
#include "CLI/CLI.hpp"
#endif

#include "gtest/gtest.h"
#include "app_helper.hpp"

TEST(Deprecated, Emtpy) {
// No deprecated features at this time.
EXPECT_TRUE(true);
}

// Classic sets

TEST_F(TApp, ClassicSetWithDefaults) {
int someint = 2;
app.add_set("-a", someint, {1, 2, 3, 4}, "", true);

args = {"-a1", "-a2"};

EXPECT_THROW(run(), CLI::ArgumentMismatch);
}

TEST_F(TApp, ClassicSetWithDefaultsConversion) {
int someint = 2;
app.add_set("-a", someint, {1, 2, 3, 4}, "", true);

args = {"-a", "hi"};

EXPECT_THROW(run(), CLI::ValidationError);
}

TEST_F(TApp, ClassicSetWithDefaultsIC) {
std::string someint = "ho";
app.add_set_ignore_case("-a", someint, {"Hi", "Ho"}, "", true);

args = {"-aHi", "-aHo"};

EXPECT_THROW(run(), CLI::ArgumentMismatch);
}

TEST_F(TApp, ClassicInSet) {

std::string choice;
app.add_set("-q,--quick", choice, {"one", "two", "three"});

args = {"--quick", "two"};

run();
EXPECT_EQ("two", choice);

args = {"--quick", "four"};
EXPECT_THROW(run(), CLI::ValidationError);
}

TEST_F(TApp, ClassicInSetWithDefault) {

std::string choice = "one";
app.add_set("-q,--quick", choice, {"one", "two", "three"}, "", true);

run();
EXPECT_EQ("one", choice);
}
12 changes: 6 additions & 6 deletions tests/HelpTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ TEST(THelp, IntDefaults) {

int one{1}, two{2};
app.add_option("--one", one, "Help for one", true);
app.add_set("--set", two, {2, 3, 4}, "Help for set", true);
app.add_option("--set", two, "Help for set", true)->check(CLI::IsMember({2, 3, 4}));

std::string help = app.help();

Expand All @@ -295,7 +295,7 @@ TEST(THelp, SetLower) {
CLI::App app{"My prog"};

std::string def{"One"};
app.add_set_ignore_case("--set", def, {"oNe", "twO", "THREE"}, "Help for set", true);
app.add_option("--set", def, "Help for set", true)->check(CLI::IsMember({"oNe", "twO", "THREE"}));

std::string help = app.help();

Expand Down Expand Up @@ -795,7 +795,7 @@ TEST(THelp, ChangingSet) {

std::set<int> vals{1, 2, 3};
int val;
app.add_mutable_set("--val", val, vals);
app.add_option("--val", val)->check(CLI::IsMember(&vals));

std::string help = app.help();

Expand All @@ -816,7 +816,7 @@ TEST(THelp, ChangingSetDefaulted) {

std::set<int> vals{1, 2, 3};
int val = 2;
app.add_mutable_set("--val", val, vals, "", true);
app.add_option("--val", val, "", true)->check(CLI::IsMember(&vals));

std::string help = app.help();

Expand All @@ -836,7 +836,7 @@ TEST(THelp, ChangingCaselessSet) {

std::set<std::string> vals{"1", "2", "3"};
std::string val;
app.add_mutable_set_ignore_case("--val", val, vals);
app.add_option("--val", val)->check(CLI::IsMember(&vals, CLI::ignore_case));

std::string help = app.help();

Expand All @@ -857,7 +857,7 @@ TEST(THelp, ChangingCaselessSetDefaulted) {

std::set<std::string> vals{"1", "2", "3"};
std::string val = "2";
app.add_mutable_set_ignore_case("--val", val, vals, "", true);
app.add_option("--val", val, "", true)->check(CLI::IsMember(&vals, CLI::ignore_case));

std::string help = app.help();

Expand Down
2 changes: 1 addition & 1 deletion tests/IniTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ TEST_F(TApp, IniOutputFlag) {
TEST_F(TApp, IniOutputSet) {

int v;
app.add_set("--simple", v, {1, 2, 3});
app.add_option("--simple", v)->check(CLI::IsMember({1, 2, 3}));

args = {"--simple=2"};

Expand Down
Loading

0 comments on commit bbdf90c

Please sign in to comment.