Skip to content

Commit

Permalink
test1
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Dec 12, 2023
1 parent 30e8814 commit a1511d7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
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
39 changes: 38 additions & 1 deletion test/cli/test-other.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import os
import sys
import pytest
import time

from testutils import cppcheck, assert_cppcheck
from testutils import cppcheck, assert_cppcheck, lookup_cppcheck_exe


def __test_missing_include(tmpdir, use_j):
Expand Down Expand Up @@ -825,3 +826,39 @@ def test_file_duplicate_2(tmpdir):
'3/3 files checked 0% done'
]
assert stderr == ''


def test_premium_with_relative_path(tmpdir):


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

product_name = 'Cppcheck Premium ' + str(time.time())

test_cfg = lookup_cppcheck_exe()
if(test_cfg.endswith('.exe')) :
test_cfg = test_cfg[:-4]
test_cfg += '.cfg'
with open(test_cfg, 'wt') as f:
f.write("""
{
"addons": [],
"productName": "NAME",
"about": "Cppcheck Premium 1.2.3.4"
}
""".replace('NAME', product_name))

if os.path.isfile('cppcheck') :
os.chdir('test/cli')

args = ['--premium=misra-c++-2008', test_file]

exitcode, _, stderr = cppcheck(args)
assert exitcode == 0
assert stderr == ''

_, stdout, stderr = cppcheck(['--version'])
assert stdout == product_name + '\n'
assert stderr == ''
4 changes: 2 additions & 2 deletions test/cli/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_gui_project_file(project_file, root_path=None, import_project=None, p
f.close()


def __lookup_cppcheck_exe():
def lookup_cppcheck_exe():
# path the script is located in
script_path = os.path.dirname(os.path.realpath(__file__))

Expand All @@ -63,7 +63,7 @@ def __lookup_cppcheck_exe():

# Run Cppcheck with args
def cppcheck(args, env=None):
exe = __lookup_cppcheck_exe()
exe = lookup_cppcheck_exe()
assert exe is not None, 'no cppcheck binary found'

logging.info(exe + ' ' + ' '.join(args))
Expand Down

0 comments on commit a1511d7

Please sign in to comment.