Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1702,11 +1702,6 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a

void CmdLineParser::printHelp(bool premium) const
{
// TODO: fetch URL from config like product name?
const std::string manualUrl(premium ?
"https://files.cppchecksolutions.com/manual.pdf" :
"https://cppcheck.sourceforge.io/manual.pdf");

std::ostringstream oss;
// TODO: display product name
oss << "Cppcheck - A tool for static C/C++ code analysis\n"
Expand Down Expand Up @@ -2077,7 +2072,7 @@ void CmdLineParser::printHelp(bool premium) const
" cppcheck -I inc1/ -I inc2/ f.cpp\n"
"\n"
"For more information:\n"
" " << manualUrl << "\n"
" " << mSettings.manualUrl << "\n"
"\n"
"Many thanks to the 3rd party libraries we use:\n"
" * tinyxml2 -- loading project/library/ctu files.\n"
Expand Down
9 changes: 9 additions & 0 deletions lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress
settings.cppcheckCfgProductName = v.get<std::string>();
}
}
{
const auto it = utils::as_const(obj).find("manualUrl");
if (it != obj.cend()) {
const auto& v = it->second;
if (!v.is<std::string>())
return "'manualUrl' is not a string";
settings.manualUrl = v.get<std::string>();
}
}
{
const auto it = utils::as_const(obj).find("about");
if (it != obj.cend()) {
Expand Down
2 changes: 2 additions & 0 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ class CPPCHECKLIB WARN_UNUSED Settings {
int loadAverage{};
#endif

std::string manualUrl{"https://cppcheck.sourceforge.io/manual.pdf"};

/** --max-configs value */
int maxConfigsOption = 0; // "Not Assigned" value

Expand Down
1 change: 1 addition & 0 deletions test/cli/premium_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __copy_cppcheck_premium(tmpdir):
"addons": [],
"productName": "NAME",
"about": "NAME",
"manualUrl" : "https://files.cppchecksolutions.com/manual.pdf",
"safety": true
}
""".replace('NAME', __PRODUCT_NAME))
Expand Down
15 changes: 9 additions & 6 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,16 @@ class TestCmdlineParser : public TestFixture {
REDIRECT;
ScopedFile file(Path::join(Path::getPathFromFilename(Path::getCurrentExecutablePath("")), "cppcheck.cfg"),
"{\n"
"\"productName\": \"Cppcheck Premium\""
"\"productName\": \"Cppcheck Premium\","
"\"manualUrl\": \"https://docs.notcppcheck.com/manual.pdf\""
"}\n");
const char * const argv[] = {"cppcheck"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Exit, parseFromArgs(argv));
ASSERT_EQUALS(1, settings->settingsFiles.size());
ASSERT_EQUALS(file.path(), *settings->settingsFiles.cbegin());
const std::string log_str = logger->str();
ASSERT_MSG(startsWith(log_str, "Cppcheck - A tool for static C/C++ code analysis"), "header");
ASSERT_MSG(log_str.find("https://files.cppchecksolutions.com/manual.pdf") != std::string::npos, "help url");
ASSERT_MSG(log_str.find("https://docs.notcppcheck.com/manual.pdf") != std::string::npos, "help url");
}

void nooptionsWithInvalidCfg() {
Expand Down Expand Up @@ -589,15 +590,16 @@ class TestCmdlineParser : public TestFixture {
REDIRECT;
ScopedFile file(Path::join(Path::getPathFromFilename(Path::getCurrentExecutablePath("")), "cppcheck.cfg"),
"{\n"
"\"productName\": \"Cppcheck Premium\""
"\"productName\": \"Cppcheck Premium\","
"\"manualUrl\": \"https://docs.notcppcheck.com/manual.pdf\""
"}\n");
const char * const argv[] = {"cppcheck", "-h"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Exit, parseFromArgs(argv));
ASSERT_EQUALS(1, settings->settingsFiles.size());
ASSERT_EQUALS(file.path(), *settings->settingsFiles.cbegin());
const std::string log_str = logger->str();
ASSERT_MSG(startsWith(log_str, "Cppcheck - A tool for static C/C++ code analysis"), "header");
ASSERT_MSG(log_str.find("https://files.cppchecksolutions.com/manual.pdf") != std::string::npos, "help url");
ASSERT_MSG(log_str.find("https://docs.notcppcheck.com/manual.pdf") != std::string::npos, "help url");
}

void helplong() {
Expand All @@ -618,15 +620,16 @@ class TestCmdlineParser : public TestFixture {
REDIRECT;
ScopedFile file(Path::join(Path::getPathFromFilename(Path::getCurrentExecutablePath("")), "cppcheck.cfg"),
"{\n"
"\"productName\": \"Cppcheck Premium\""
"\"productName\": \"Cppcheck Premium\","
"\"manualUrl\": \"https://docs.notcppcheck.com/manual.pdf\""
"}\n");
const char * const argv[] = {"cppcheck", "--help"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Exit, parseFromArgs(argv));
ASSERT_EQUALS(1, settings->settingsFiles.size());
ASSERT_EQUALS(file.path(), *settings->settingsFiles.cbegin());
const std::string log_str = logger->str();
ASSERT_MSG(startsWith(log_str, "Cppcheck - A tool for static C/C++ code analysis"), "header");
ASSERT_MSG(log_str.find("https://files.cppchecksolutions.com/manual.pdf") != std::string::npos, "help url");
ASSERT_MSG(log_str.find("https://docs.notcppcheck.com/manual.pdf") != std::string::npos, "help url");
}

void version() {
Expand Down
15 changes: 15 additions & 0 deletions test/testsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ class TestSettings : public TestFixture {
R"({"suppressions": [1]}\n)");
ASSERT_EQUALS("'suppressions' array entry is not a string", Settings::loadCppcheckCfg(s, supprs));
}
{
Settings s;
Suppressions supprs;
ScopedFile file("cppcheck.cfg",
R"({"manualUrl": "https://docs.notcppcheck.com/manual.pdf"})");
ASSERT_EQUALS("", Settings::loadCppcheckCfg(s, supprs));
ASSERT_EQUALS("https://docs.notcppcheck.com/manual.pdf", s.manualUrl);
}
{
Settings s;
Suppressions supprs;
ScopedFile file("cppcheck.cfg",
R"({"manualUrl": 0}\n)");
ASSERT_EQUALS("'manualUrl' is not a string", Settings::loadCppcheckCfg(s, supprs));
}

// TODO: test with FILESDIR
}
Expand Down
Loading