mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
* add Tests and ability to handle program file inclusion in the single string. add the ability to deal with a single string in the parse command and handle quoted string appropriately * Add extra test cases for full coverage, clear up escape quote sequencing and handling of extra spaces
76 lines
2.1 KiB
C++
76 lines
2.1 KiB
C++
#include "app_helper.hpp"
|
|
|
|
#include "gmock/gmock.h"
|
|
#include <cstdio>
|
|
#include <sstream>
|
|
|
|
TEST_F(TApp, ExistingExeCheck) {
|
|
|
|
TempFile tmpexe{"existingExe.out"};
|
|
|
|
std::string str, str2, str3;
|
|
app.add_option("-s,--string", str);
|
|
app.add_option("-t,--tstr", str2);
|
|
app.add_option("-m,--mstr", str3);
|
|
|
|
{
|
|
std::ofstream out{tmpexe};
|
|
out << "useless string doesn't matter" << std::endl;
|
|
}
|
|
|
|
app.parse(std::string("./") + std::string(tmpexe) +
|
|
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
|
true);
|
|
EXPECT_EQ(str, "this is my quoted string");
|
|
EXPECT_EQ(str2, "qstring 2");
|
|
EXPECT_EQ(str3, "\"quoted string\"");
|
|
}
|
|
|
|
TEST_F(TApp, ExistingExeCheckWithSpace) {
|
|
|
|
TempFile tmpexe{"Space File.out"};
|
|
|
|
std::string str, str2, str3;
|
|
app.add_option("-s,--string", str);
|
|
app.add_option("-t,--tstr", str2);
|
|
app.add_option("-m,--mstr", str3);
|
|
|
|
{
|
|
std::ofstream out{tmpexe};
|
|
out << "useless string doesn't matter" << std::endl;
|
|
}
|
|
|
|
app.parse(std::string("./") + std::string(tmpexe) +
|
|
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
|
true);
|
|
EXPECT_EQ(str, "this is my quoted string");
|
|
EXPECT_EQ(str2, "qstring 2");
|
|
EXPECT_EQ(str3, "\"quoted string\"");
|
|
|
|
EXPECT_EQ(app.get_name(), std::string("./") + std::string(tmpexe));
|
|
}
|
|
|
|
TEST_F(TApp, ExistingExeCheckWithLotsOfSpace) {
|
|
|
|
TempFile tmpexe{"this is a weird file.exe"};
|
|
|
|
std::string str, str2, str3;
|
|
app.add_option("-s,--string", str);
|
|
app.add_option("-t,--tstr", str2);
|
|
app.add_option("-m,--mstr", str3);
|
|
|
|
{
|
|
std::ofstream out{tmpexe};
|
|
out << "useless string doesn't matter" << std::endl;
|
|
}
|
|
|
|
app.parse(std::string("./") + std::string(tmpexe) +
|
|
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
|
true);
|
|
EXPECT_EQ(str, "this is my quoted string");
|
|
EXPECT_EQ(str2, "qstring 2");
|
|
EXPECT_EQ(str3, "\"quoted string\"");
|
|
|
|
EXPECT_EQ(app.get_name(), std::string("./") + std::string(tmpexe));
|
|
}
|