Skip to content

Commit 3e0b256

Browse files
committed
lib+platform
1 parent 85e352c commit 3e0b256

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

test/cli/lookup_test.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,4 +927,54 @@ def test_config_invalid(tmpdir):
927927
'cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 1 near: '
928928
]
929929

930-
# TODO: test with FILESDIR
930+
# TODO: test with FILESDIR
931+
932+
@pytest.mark.parametrize("type,file", [("library", "gnu.cfg"), ("platform", "avr8.xml")])
933+
def test_lookup_path(tmpdir, type, file):
934+
test_file = os.path.join(tmpdir, 'test.c')
935+
with open(test_file, 'wt'):
936+
pass
937+
938+
cppcheck = 'cppcheck' # No path
939+
path = os.path.dirname(__lookup_cppcheck_exe())
940+
env = os.environ.copy()
941+
env['PATH'] = path
942+
exitcode, stdout, stderr, _ = cppcheck_ex(args=[f'--debug-lookup={type}', f'--{type}={file}', test_file], cppcheck_exe=cppcheck, cwd=str(tmpdir), env=env)
943+
assert exitcode == 0, stdout if stdout else stderr
944+
def format_path(p):
945+
return p.replace('\\', '/').replace('"', '\'')
946+
lines = format_path(stdout).splitlines()
947+
948+
# TODO make lookups consistent between library and platform and add --debug-lookup={type} option
949+
950+
if type == 'platform':
951+
def try_fail(f):
952+
f = format_path(f)
953+
return f"try to load {type} file '{f}' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={f}"
954+
def try_success(f):
955+
f = format_path(f)
956+
return f"try to load {type} file '{f}' ... Success"
957+
assert lines == [
958+
f"looking for {type} '{file}'",
959+
try_fail(os.path.join(tmpdir, file)),
960+
try_fail(os.path.join(tmpdir, 'platforms', file)),
961+
try_fail(os.path.join(path, file)),
962+
try_success(os.path.join(path, 'platforms', file)),
963+
f'Checking {format_path(test_file)} ...'
964+
]
965+
elif type == 'library':
966+
def try_fail(f):
967+
return f"looking for {type} '{format_path(f)}'"
968+
def try_success(f):
969+
return f"looking for {type} '{format_path(f)}'"
970+
assert lines == [
971+
f"looking for {type} 'std.cfg'",
972+
try_fail(os.path.join(path, 'std.cfg')),
973+
try_success(os.path.join(path, 'cfg', 'std.cfg')),
974+
f"looking for {type} '{file}'",
975+
try_fail(os.path.join(path, file)),
976+
try_success(os.path.join(path, 'cfg', file)),
977+
f'Checking {format_path(test_file)} ...'
978+
]
979+
else:
980+
assert False, type + " not tested properly"

0 commit comments

Comments
 (0)