From e11b2d29789d9a290be0ae382505fc3fb95c1c7e Mon Sep 17 00:00:00 2001 From: Oleksandr Labetskyi Date: Tue, 12 Dec 2023 12:13:51 +0200 Subject: [PATCH] #12254: remove component test, add unit test, fix format --- cli/cmdlineparser.cpp | 2 +- test/cli/test-other.py | 21 --------------------- test/testcmdlineparser.cpp | 14 ++++++++++++++ 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 7c4af1b31d0..7f5156059a9 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -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"); diff --git a/test/cli/test-other.py b/test/cli/test-other.py index 8f66ca90f6b..101f4cb880d 100644 --- a/test/cli/test-other.py +++ b/test/cli/test-other.py @@ -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 == '' diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index c4b6ed38ff2..21f23ba9b35 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -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); @@ -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() {