Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#12254: cppcheck.cfg can't be loaded from relative paths anymore #5753

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1629,10 +1629,10 @@ void CmdLineParser::printHelp() const
mLogger.printRaw(oss.str());
}

bool CmdLineParser::isCppcheckPremium() {
Settings settings;
settings.loadCppcheckCfg(); // TODO: how to handle errors?
return startsWith(settings.cppcheckCfgProductName, "Cppcheck Premium");
bool CmdLineParser::isCppcheckPremium() const {
if (mSettings.cppcheckCfgProductName.empty())
mSettings.loadCppcheckCfg();
return startsWith(mSettings.cppcheckCfgProductName, "Cppcheck Premium");
}

bool CmdLineParser::tryLoadLibrary(Library& destination, const std::string& basepath, const char* filename)
Expand Down
2 changes: 1 addition & 1 deletion cli/cmdlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class CmdLineParser {
void printHelp() const;

private:
static bool isCppcheckPremium();
bool isCppcheckPremium() const;

template<typename T>
bool parseNumberArg(const char* const arg, std::size_t offset, T& num, bool mustBePositive = false)
Expand Down
1 change: 1 addition & 0 deletions test/cli/test-other.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,3 +825,4 @@ def test_file_duplicate_2(tmpdir):
'3/3 files checked 0% done'
]
assert stderr == ''

14 changes: 14 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(helplongExclusive);
TEST_CASE(version);
TEST_CASE(versionWithCfg);
TEST_CASE(versionSwitchWithCfg);
TEST_CASE(versionExclusive);
TEST_CASE(versionWithInvalidCfg);
TEST_CASE(onefile);
Expand Down Expand Up @@ -421,6 +422,19 @@ class TestCmdlineParser : public TestFixture {
(void)logger->str(); //ASSERT_EQUALS("The Product\n", logger->str()); // TODO: include version?
}

void versionSwitchWithCfg() {
REDIRECT;
ScopedFile file(Path::join(Path::getPathFromFilename(Path::getCurrentExecutablePath("")), "cppcheck.cfg"),
"{\n"
"\"productName\": \"Cppcheck Premium 1.2.3.4\""
"}\n");
const char * const argv[] = {"cppcheck", "--premium=misra-c++-2008", "--version", "file.cpp"};
// --premium=misra-c++-2008 should be recognized from cfg
ASSERT_EQUALS(CmdLineParser::Result::Exit, parser->parseFromArgs(4, argv));
danmar marked this conversation as resolved.
Show resolved Hide resolved
// TODO: somehow the config is not loaded on some systems
ASSERT_EQUALS("Cppcheck Premium 1.2.3.4\n", logger->str());
}

// TODO: test --version with extraVersion

void versionExclusive() {
Expand Down
Loading