mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 20:53:52 +00:00
Added more tests, some fixes
This commit is contained in:
parent
d070f32ed6
commit
1b2af21a2d
@ -289,7 +289,10 @@ lexical_cast(std::string input, T& output) {
|
||||
|
||||
// String and similar
|
||||
template<typename T>
|
||||
bool lexical_cast(std::string input, T& output) {
|
||||
typename std::enable_if<
|
||||
!std::is_floating_point<T>::value
|
||||
&& !std::is_integral<T>::value, bool>::type
|
||||
lexical_cast(std::string input, T& output) {
|
||||
logit("Direct lexical cast: " + input);
|
||||
output = input;
|
||||
return true;
|
||||
|
@ -36,9 +36,79 @@ struct TApp : public ::testing::Test {
|
||||
|
||||
};
|
||||
|
||||
TEST_F(TApp, AFewArgs) {
|
||||
TEST_F(TApp, OneFlagShort) {
|
||||
app.add_flag("c,count");
|
||||
args = {"-c"};
|
||||
run();
|
||||
EXPECT_EQ(1, app.count("c"));
|
||||
EXPECT_EQ(1, app.count("count"));
|
||||
}
|
||||
|
||||
TEST_F(TApp, OneFlagLong) {
|
||||
app.add_flag("c,count");
|
||||
args = {"--count"};
|
||||
run();
|
||||
EXPECT_EQ(1, app.count("c"));
|
||||
EXPECT_EQ(1, app.count("count"));
|
||||
}
|
||||
|
||||
TEST_F(TApp, OneFlagRef) {
|
||||
int ref;
|
||||
app.add_flag("c,count", ref);
|
||||
args = {"--count"};
|
||||
run();
|
||||
EXPECT_EQ(1, app.count("c"));
|
||||
EXPECT_EQ(1, app.count("count"));
|
||||
EXPECT_EQ(1, ref);
|
||||
}
|
||||
|
||||
TEST_F(TApp, OneString) {
|
||||
std::string str;
|
||||
app.add_option("s,string", str);
|
||||
args = {"--string", "mystring"};
|
||||
run();
|
||||
EXPECT_EQ(1, app.count("s"));
|
||||
EXPECT_EQ(1, app.count("string"));
|
||||
EXPECT_EQ(str, "mystring");
|
||||
}
|
||||
|
||||
|
||||
TEST_F(TApp, TogetherInt) {
|
||||
int i;
|
||||
app.add_option("i,int", i);
|
||||
args = {"-i4"};
|
||||
run();
|
||||
EXPECT_EQ(1, app.count("int"));
|
||||
EXPECT_EQ(1, app.count("i"));
|
||||
EXPECT_EQ(i, 4);
|
||||
}
|
||||
|
||||
TEST_F(TApp, SepInt) {
|
||||
int i;
|
||||
app.add_option("i,int", i);
|
||||
args = {"-i","4"};
|
||||
run();
|
||||
EXPECT_EQ(1, app.count("int"));
|
||||
EXPECT_EQ(1, app.count("i"));
|
||||
EXPECT_EQ(i, 4);
|
||||
}
|
||||
|
||||
TEST_F(TApp, OneStringAgain) {
|
||||
std::string str;
|
||||
app.add_option("s,string", str);
|
||||
args = {"--string", "mystring"};
|
||||
run();
|
||||
EXPECT_EQ(1, app.count("s"));
|
||||
EXPECT_EQ(1, app.count("string"));
|
||||
EXPECT_EQ(str, "mystring");
|
||||
}
|
||||
|
||||
|
||||
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(str, "previous");
|
||||
}
|
||||
|
@ -2,6 +2,15 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
|
||||
|
||||
add_subdirectory(googletest)
|
||||
|
||||
if (CMAKE_CONFIGURATION_TYPES)
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
|
||||
--force-new-ctest-process --output-on-failure
|
||||
--build-config "$<CONFIGURATION>")
|
||||
else()
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
|
||||
--force-new-ctest-process --output-on-failure)
|
||||
endif()
|
||||
|
||||
include_directories(${gtest_SOURCE_DIR}/include)
|
||||
|
||||
add_executable(CLITest CLITest.cpp ${headers})
|
||||
|
Loading…
x
Reference in New Issue
Block a user