Skip to content

Commit

Permalink
#12254: remove component test, add unit test, fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Dec 12, 2023
1 parent 20f3099 commit e11b2d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ void CmdLineParser::printHelp() const
mLogger.printRaw(oss.str());
}

bool CmdLineParser::isCppcheckPremium() const{
bool CmdLineParser::isCppcheckPremium() const {
if (mSettings.cppcheckCfgProductName.empty())
mSettings.loadCppcheckCfg();
return startsWith(mSettings.cppcheckCfgProductName, "Cppcheck Premium");
Expand Down
21 changes: 0 additions & 21 deletions test/cli/test-other.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,24 +826,3 @@ def test_file_duplicate_2(tmpdir):
]
assert stderr == ''


def test_cgf_with_relative_path(tmpdir):

test_file = os.path.join(tmpdir, 'test.c')
with open(test_file, 'wt'):
pass

test_cfg = os.path.join(tmpdir, '../../cppcheck.cfg')
with open(test_cfg, 'wt') as f:
f.write("""
{
"addons": [],
"productName": "Cppcheck Premium 1.2.3.4",
"about": "Cppcheck Premium 1.2.3.4"
}
""")

args = [test_file]

_, _, stderr = cppcheck(args)
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));
// 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

0 comments on commit e11b2d2

Please sign in to comment.