1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 20:23:55 +00:00

Adding tests and deprecation messages

This commit is contained in:
Henry Fredrick Schreiner 2018-06-18 13:10:22 +02:00 committed by Henry Schreiner
parent b2e471ac4d
commit 98b31d788b
7 changed files with 77 additions and 2 deletions

View File

@ -31,7 +31,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
if(MSVC)
add_definitions("/W4")
else()
add_definitions(-Wall -Wextra -pedantic -Wno-deprecated-declarations)
add_definitions(-Wall -Wextra -pedantic)
endif()
if(CMAKE_VERSION VERSION_GREATER 3.6)

View File

@ -1039,6 +1039,18 @@ class App {
return formatter_->make_help(this, prev, mode);
}
/// Provided for backwards compatibility \deprecated
CLI11_DEPRECATED("Please use footer instead")
App *set_footer(std::string msg) { return footer(msg); }
/// Provided for backwards compatibility \deprecated
CLI11_DEPRECATED("Please use name instead")
App *set_name(std::string msg) { return name(msg); }
/// Provided for backwards compatibility \deprecated
CLI11_DEPRECATED("Please use callback instead")
App *set_callback(std::function<void()> fn) { return callback(fn); }
///@}
/// @name Getters
///@{

View File

@ -30,7 +30,7 @@
#endif
#endif
#if defined(PYBIND11_CPP14)
#if defined(CLI11_CPP14)
#define CLI11_DEPRECATED(reason) [[deprecated(reason)]]
#elif defined(_MSC_VER)
#define CLI11_DEPRECATED(reason) __declspec(deprecated(reason))

View File

@ -665,6 +665,10 @@ class Option : public OptionBase<Option> {
return this;
}
/// Provided for backward compatibility \deprecated
CLI11_DEPRECATED("Please use type_name instead")
Option *set_type_name(std::string typeval) { return type_name(typeval); }
/// Set a custom option size
Option *type_size(int type_size) {
type_size_ = type_size;

View File

@ -30,6 +30,7 @@ set(CLI11_TESTS
FormatterTest
NewParseTest
OptionalTest
DeprecatedTest
)
set(CLI11_MULTIONLY_TESTS
@ -66,6 +67,13 @@ foreach(T ${CLI11_MULTIONLY_TESTS})
endforeach()
# Add -Wno-deprecated-declarations to DeprecatedTest
if(NOT MSVC)
target_compile_options(DeprecatedTest PRIVATE -Wno-deprecated-declarations)
if(TARGET DeprecatedTest_Single)
target_compile_options(DeprecatedTest_Single PRIVATE -Wno-deprecated-declarations)
endif()
endif()
# Link test (build error if inlines missing)
add_library(link_test_1 link_test_1.cpp)

43
tests/DeprecatedTest.cpp Normal file
View File

@ -0,0 +1,43 @@
#ifdef CLI11_SINGLE_FILE
#include "CLI11.hpp"
#else
#include "CLI/CLI.hpp"
#endif
#include "gtest/gtest.h"
TEST(Deprecated, SetFooter) {
CLI::App app{"My prog"};
app.set_footer("My Footer");
EXPECT_EQ("My Footer", app.get_footer());
}
TEST(Deprecated, SetName) {
CLI::App app{"My prog"};
app.set_name("My Name");
EXPECT_EQ("My Name", app.get_name());
}
TEST(Deprecated, SetCallback) {
CLI::App app{"My prog"};
bool val;
app.set_callback([&val]() { val = true; });
std::vector<std::string> something;
app.parse(something);
EXPECT_TRUE(val);
}
TEST(Deprecated, SetTypeName) {
CLI::App app{"My prog"};
std::string val;
auto opt = app.add_option("--val", val);
opt->set_type_name("THAT");
EXPECT_EQ(opt->get_type_name(), "THAT");
}

View File

@ -561,6 +561,14 @@ TEST(THelp, CustomDoubleOption) {
EXPECT_THAT(app.help(), Not(HasSubstr("x 2")));
}
TEST(THelp, CheckEmptyTypeName) {
CLI::App app;
auto opt = app.add_flag("-f,--flag");
std::string name = opt->get_type_name();
EXPECT_TRUE(name.empty());
}
TEST(THelp, AccessDescription) {
CLI::App app{"My description goes here"};