Skip to content
Merged
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
55 changes: 41 additions & 14 deletions test/cli/lookup_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import sys
import pytest
import shutil

from testutils import cppcheck_ex, cppcheck
from testutils import cppcheck_ex, cppcheck, __lookup_cppcheck_exe

def __remove_std_lookup_log(l : list, exepath):
l.remove("looking for library 'std.cfg'")
Expand Down Expand Up @@ -63,9 +64,7 @@ def test_lib_lookup_notfound(tmpdir):
assert lines == [
# TODO: specify which folder is actually used for lookup here
"looking for library 'none.cfg'",
# TODO: lookup of '{exepath}/none' missing - could conflict with the platform lookup though
"looking for library '{}/none.cfg'".format(exepath),
# TODO: lookup of '{exepath}/cfg/none' missing
"looking for library '{}/cfg/none.cfg'".format(exepath),
"library not found: 'none'",
"cppcheck: Failed to load library configuration file 'none'. File not found"
Expand Down Expand Up @@ -260,7 +259,7 @@ def test_platform_lookup_builtin(tmpdir):
]


@pytest.mark.skip # TODO: perform additional lookups when run via symlink in CI
@pytest.mark.skip # TODO: performs additional lookups when run via symlink in CI
def test_platform_lookup(tmpdir):
test_file = os.path.join(tmpdir, 'test.c')
with open(test_file, 'wt'):
Expand All @@ -281,7 +280,7 @@ def test_platform_lookup(tmpdir):
]


@pytest.mark.skip # TODO: perform additional lookups when run via symlink in CI
@pytest.mark.skip # TODO: performs additional lookups when run via symlink in CI
def test_platform_lookup_ext(tmpdir):
test_file = os.path.join(tmpdir, 'test.c')
with open(test_file, 'wt'):
Expand Down Expand Up @@ -440,7 +439,7 @@ def test_platform_lookup_absolute_notfound(tmpdir):
]


@pytest.mark.skip # TODO: perform additional lookups when run via symlink in CI
@pytest.mark.skip # TODO: performs additional lookups when run via symlink in CI
def test_platform_lookup_nofile(tmpdir):
test_file = os.path.join(tmpdir, 'test.c')
with open(test_file, 'wt'):
Expand Down Expand Up @@ -650,7 +649,7 @@ def test_addon_lookup_nofile(tmpdir):
exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=misra', test_file])
exepath = os.path.dirname(exe)
exepath_sep = exepath + os.path.sep
assert exitcode == 0, stdout if stdout else stderr # TODO. should fail when addon is not found
assert exitcode == 0, stdout if stdout else stderr
lines = stdout.splitlines()
assert lines == [
"looking for addon 'misra.py'",
Expand Down Expand Up @@ -679,25 +678,29 @@ def test_addon_lookup_invalid(tmpdir):
]


@pytest.mark.skip # TODO
def test_config_lookup(tmpdir):
cppcheck_exe = __lookup_cppcheck_exe()
bin_dir = os.path.dirname(cppcheck_exe)
tmp_cppcheck_exe = shutil.copy2(cppcheck_exe, tmpdir)
if sys.platform == 'win32':
shutil.copy2(os.path.join(bin_dir, 'cppcheck-core.dll'), tmpdir)
shutil.copytree(os.path.join(bin_dir, 'cfg'), os.path.join(tmpdir, 'cfg'))

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

# TODO: needs to be in exepath so this is found
config_file = os.path.join(tmpdir, 'cppcheck.cfg')
with open(config_file, 'wt'):
pass
with open(config_file, 'wt') as f:
f.write('{}')

exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=config', '--addon=misra', test_file], cwd=tmpdir)
exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=config', test_file], cwd=tmpdir, cppcheck_exe=tmp_cppcheck_exe)
exepath = os.path.dirname(exe)
exepath_sep = exepath + os.path.sep
assert exitcode == 0, stdout if stdout else stderr
lines = stdout.splitlines()
assert lines == [
"looking for '{}cppcheck.cfg'".format(exepath_sep),
'no configuration found',
'Checking {} ...'.format(test_file)
]

Expand All @@ -718,6 +721,30 @@ def test_config_lookup_notfound(tmpdir):
'Checking {} ...'.format(test_file)
]

# TODO: test handling of invalid configuration
def test_config_invalid(tmpdir):
cppcheck_exe = __lookup_cppcheck_exe()
bin_dir = os.path.dirname(cppcheck_exe)
tmp_cppcheck_exe = shutil.copy2(cppcheck_exe, tmpdir)
if sys.platform == 'win32':
shutil.copy2(os.path.join(bin_dir, 'cppcheck-core.dll'), tmpdir)
shutil.copytree(os.path.join(bin_dir, 'cfg'), os.path.join(tmpdir, 'cfg'))

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

config_file = os.path.join(tmpdir, 'cppcheck.cfg')
with open(config_file, 'wt'):
pass

exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=config', test_file], cwd=tmpdir, cppcheck_exe=tmp_cppcheck_exe)
exepath = os.path.dirname(exe)
exepath_sep = exepath + os.path.sep
assert exitcode == 1, stdout if stdout else stderr
lines = stdout.splitlines()
assert lines == [
"looking for '{}cppcheck.cfg'".format(exepath_sep),
'cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 1 near: '
]

# TODO: test with FILESDIR
Loading