Commit 98b31d788b827763f7ec97db5a9db4e4dd9f0deb

Authored by Henry Fredrick Schreiner
Committed by Henry Schreiner
1 parent b2e471ac

Adding tests and deprecation messages

CMakeLists.txt
@@ -31,7 +31,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) @@ -31,7 +31,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
31 if(MSVC) 31 if(MSVC)
32 add_definitions("/W4") 32 add_definitions("/W4")
33 else() 33 else()
34 - add_definitions(-Wall -Wextra -pedantic -Wno-deprecated-declarations) 34 + add_definitions(-Wall -Wextra -pedantic)
35 endif() 35 endif()
36 36
37 if(CMAKE_VERSION VERSION_GREATER 3.6) 37 if(CMAKE_VERSION VERSION_GREATER 3.6)
include/CLI/App.hpp
@@ -1039,6 +1039,18 @@ class App { @@ -1039,6 +1039,18 @@ class App {
1039 return formatter_->make_help(this, prev, mode); 1039 return formatter_->make_help(this, prev, mode);
1040 } 1040 }
1041 1041
  1042 + /// Provided for backwards compatibility \deprecated
  1043 + CLI11_DEPRECATED("Please use footer instead")
  1044 + App *set_footer(std::string msg) { return footer(msg); }
  1045 +
  1046 + /// Provided for backwards compatibility \deprecated
  1047 + CLI11_DEPRECATED("Please use name instead")
  1048 + App *set_name(std::string msg) { return name(msg); }
  1049 +
  1050 + /// Provided for backwards compatibility \deprecated
  1051 + CLI11_DEPRECATED("Please use callback instead")
  1052 + App *set_callback(std::function<void()> fn) { return callback(fn); }
  1053 +
1042 ///@} 1054 ///@}
1043 /// @name Getters 1055 /// @name Getters
1044 ///@{ 1056 ///@{
include/CLI/Macros.hpp
@@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
30 #endif 30 #endif
31 #endif 31 #endif
32 32
33 -#if defined(PYBIND11_CPP14) 33 +#if defined(CLI11_CPP14)
34 #define CLI11_DEPRECATED(reason) [[deprecated(reason)]] 34 #define CLI11_DEPRECATED(reason) [[deprecated(reason)]]
35 #elif defined(_MSC_VER) 35 #elif defined(_MSC_VER)
36 #define CLI11_DEPRECATED(reason) __declspec(deprecated(reason)) 36 #define CLI11_DEPRECATED(reason) __declspec(deprecated(reason))
include/CLI/Option.hpp
@@ -665,6 +665,10 @@ class Option : public OptionBase&lt;Option&gt; { @@ -665,6 +665,10 @@ class Option : public OptionBase&lt;Option&gt; {
665 return this; 665 return this;
666 } 666 }
667 667
  668 + /// Provided for backward compatibility \deprecated
  669 + CLI11_DEPRECATED("Please use type_name instead")
  670 + Option *set_type_name(std::string typeval) { return type_name(typeval); }
  671 +
668 /// Set a custom option size 672 /// Set a custom option size
669 Option *type_size(int type_size) { 673 Option *type_size(int type_size) {
670 type_size_ = type_size; 674 type_size_ = type_size;
tests/CMakeLists.txt
@@ -30,6 +30,7 @@ set(CLI11_TESTS @@ -30,6 +30,7 @@ set(CLI11_TESTS
30 FormatterTest 30 FormatterTest
31 NewParseTest 31 NewParseTest
32 OptionalTest 32 OptionalTest
  33 + DeprecatedTest
33 ) 34 )
34 35
35 set(CLI11_MULTIONLY_TESTS 36 set(CLI11_MULTIONLY_TESTS
@@ -66,6 +67,13 @@ foreach(T ${CLI11_MULTIONLY_TESTS}) @@ -66,6 +67,13 @@ foreach(T ${CLI11_MULTIONLY_TESTS})
66 67
67 endforeach() 68 endforeach()
68 69
  70 +# Add -Wno-deprecated-declarations to DeprecatedTest
  71 +if(NOT MSVC)
  72 + target_compile_options(DeprecatedTest PRIVATE -Wno-deprecated-declarations)
  73 + if(TARGET DeprecatedTest_Single)
  74 + target_compile_options(DeprecatedTest_Single PRIVATE -Wno-deprecated-declarations)
  75 + endif()
  76 +endif()
69 77
70 # Link test (build error if inlines missing) 78 # Link test (build error if inlines missing)
71 add_library(link_test_1 link_test_1.cpp) 79 add_library(link_test_1 link_test_1.cpp)
tests/DeprecatedTest.cpp 0 → 100644
  1 +#ifdef CLI11_SINGLE_FILE
  2 +#include "CLI11.hpp"
  3 +#else
  4 +#include "CLI/CLI.hpp"
  5 +#endif
  6 +
  7 +#include "gtest/gtest.h"
  8 +
  9 +TEST(Deprecated, SetFooter) {
  10 + CLI::App app{"My prog"};
  11 +
  12 + app.set_footer("My Footer");
  13 + EXPECT_EQ("My Footer", app.get_footer());
  14 +}
  15 +
  16 +TEST(Deprecated, SetName) {
  17 + CLI::App app{"My prog"};
  18 +
  19 + app.set_name("My Name");
  20 + EXPECT_EQ("My Name", app.get_name());
  21 +}
  22 +
  23 +TEST(Deprecated, SetCallback) {
  24 + CLI::App app{"My prog"};
  25 +
  26 + bool val;
  27 + app.set_callback([&val]() { val = true; });
  28 +
  29 + std::vector<std::string> something;
  30 + app.parse(something);
  31 +
  32 + EXPECT_TRUE(val);
  33 +}
  34 +
  35 +TEST(Deprecated, SetTypeName) {
  36 + CLI::App app{"My prog"};
  37 +
  38 + std::string val;
  39 + auto opt = app.add_option("--val", val);
  40 + opt->set_type_name("THAT");
  41 +
  42 + EXPECT_EQ(opt->get_type_name(), "THAT");
  43 +}
tests/HelpTest.cpp
@@ -561,6 +561,14 @@ TEST(THelp, CustomDoubleOption) { @@ -561,6 +561,14 @@ TEST(THelp, CustomDoubleOption) {
561 EXPECT_THAT(app.help(), Not(HasSubstr("x 2"))); 561 EXPECT_THAT(app.help(), Not(HasSubstr("x 2")));
562 } 562 }
563 563
  564 +TEST(THelp, CheckEmptyTypeName) {
  565 + CLI::App app;
  566 +
  567 + auto opt = app.add_flag("-f,--flag");
  568 + std::string name = opt->get_type_name();
  569 + EXPECT_TRUE(name.empty());
  570 +}
  571 +
564 TEST(THelp, AccessDescription) { 572 TEST(THelp, AccessDescription) {
565 CLI::App app{"My description goes here"}; 573 CLI::App app{"My description goes here"};
566 574