Skip to content

Commit d95a4d5

Browse files
committed
lookup_test.py: added more tests
1 parent 6634bf5 commit d95a4d5

1 file changed

Lines changed: 181 additions & 0 deletions

File tree

test/cli/lookup_test.py

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,28 @@ def test_lib_lookup_relative_noext_notfound(tmpdir):
213213
]
214214

215215

216+
# TODO: this can never be found - bail out early?
217+
def test_lib_lookup_relative_noext_trailing_notfound(tmpdir):
218+
test_file = os.path.join(tmpdir, 'test.c')
219+
with open(test_file, 'wt'):
220+
pass
221+
222+
exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=library', '--library=config/gnu/', test_file])
223+
exepath = os.path.dirname(exe)
224+
if sys.platform == 'win32':
225+
exepath = exepath.replace('\\', '/')
226+
assert exitcode == 1, stdout if stdout else stderr
227+
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
228+
assert lines == [
229+
# TODO: do not append extension
230+
"looking for library 'config/gnu/.cfg'",
231+
"looking for library '{}/config/gnu/.cfg'".format(exepath),
232+
"looking for library '{}/cfg/config/gnu/.cfg'".format(exepath),
233+
"library not found: 'config/gnu/'",
234+
"cppcheck: Failed to load library configuration file 'config/gnu/'. File not found"
235+
]
236+
237+
216238
def test_lib_lookup_absolute(tmpdir):
217239
test_file = os.path.join(tmpdir, 'test.c')
218240
with open(test_file, 'wt'):
@@ -258,6 +280,48 @@ def test_lib_lookup_absolute_notfound(tmpdir):
258280
]
259281

260282

283+
def test_lib_lookup_absolute_noext_notfound(tmpdir):
284+
test_file = os.path.join(tmpdir, 'test.c')
285+
with open(test_file, 'wt'):
286+
pass
287+
288+
cfg_file = os.path.join(tmpdir, 'test')
289+
290+
exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=library', '--library={}'.format(cfg_file), test_file])
291+
exepath = os.path.dirname(exe)
292+
if sys.platform == 'win32':
293+
exepath = exepath.replace('\\', '/')
294+
assert exitcode == 1, stdout
295+
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
296+
assert lines == [
297+
"looking for library '{}'".format(cfg_file),
298+
"library not found: '{}'".format(cfg_file),
299+
"cppcheck: Failed to load library configuration file '{}'. File not found".format(cfg_file)
300+
]
301+
302+
303+
# TODO: this can never be found - bail out early?
304+
def test_lib_lookup_absolute_noext_trailing_notfound(tmpdir):
305+
test_file = os.path.join(tmpdir, 'test.c')
306+
with open(test_file, 'wt'):
307+
pass
308+
309+
cfg_file = os.path.join(tmpdir, 'test')
310+
cfg_file_trail = cfg_file + os.path.sep
311+
312+
exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=library', '--library={}'.format(cfg_file_trail), test_file])
313+
exepath = os.path.dirname(exe)
314+
if sys.platform == 'win32':
315+
exepath = exepath.replace('\\', '/')
316+
assert exitcode == 1, stdout
317+
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
318+
assert lines == [
319+
"looking for library '{}'".format(cfg_file_trail),
320+
"library not found: '{}'".format(cfg_file_trail),
321+
"cppcheck: Failed to load library configuration file '{}'. File not found".format(cfg_file_trail)
322+
]
323+
324+
261325
def test_lib_lookup_nofile(tmpdir):
262326
test_file = os.path.join(tmpdir, 'test.c')
263327
with open(test_file, 'wt'):
@@ -552,6 +616,31 @@ def test_platform_lookup_relative_noext_notfound(tmpdir):
552616
]
553617

554618

619+
# TODO: this can never be found - bail out early?
620+
def test_platform_lookup_relative_noext_trailing_notfound(tmpdir):
621+
test_file = os.path.join(tmpdir, 'test.c')
622+
with open(test_file, 'wt'):
623+
pass
624+
625+
exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=platform/none/', test_file])
626+
cwd = os.getcwd()
627+
exepath = os.path.dirname(exe)
628+
if sys.platform == 'win32':
629+
cwd = cwd.replace('\\', '/')
630+
exepath = exepath.replace('\\', '/')
631+
assert exitcode == 1, stdout if stdout else stderr
632+
lines = stdout.splitlines()
633+
assert lines == [
634+
"looking for platform 'platform/none/'",
635+
# TODO: should not append extension
636+
"try to load platform file '{}/platform/none/.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none/.xml".format(cwd, cwd),
637+
"try to load platform file '{}/platforms/platform/none/.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none/.xml".format(cwd, cwd),
638+
"try to load platform file '{}/platform/none/.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none/.xml".format(exepath, exepath),
639+
"try to load platform file '{}/platforms/platform/none/.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none/.xml".format(exepath, exepath),
640+
"cppcheck: error: unrecognized platform: 'platform/none/'."
641+
]
642+
643+
555644
def test_platform_lookup_absolute(tmpdir):
556645
test_file = os.path.join(tmpdir, 'test.c')
557646
with open(test_file, 'wt'):
@@ -590,6 +679,42 @@ def test_platform_lookup_absolute_notfound(tmpdir):
590679
]
591680

592681

682+
def test_platform_lookup_absolute_noext_notfound(tmpdir):
683+
test_file = os.path.join(tmpdir, 'test.c')
684+
with open(test_file, 'wt'):
685+
pass
686+
687+
platform_file = os.path.join(tmpdir, 'test')
688+
689+
exitcode, stdout, stderr = cppcheck(['--debug-lookup=platform', '--platform={}'.format(platform_file), test_file])
690+
assert exitcode == 1, stdout if stdout else stderr
691+
lines = stdout.splitlines()
692+
assert lines == [
693+
"looking for platform '{}'".format(platform_file),
694+
"try to load platform file '{}' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}".format(platform_file, platform_file),
695+
"cppcheck: error: unrecognized platform: '{}'.".format(platform_file)
696+
]
697+
698+
699+
# TODO: this can never be found - bail out early?
700+
def test_platform_lookup_absolute_noext_trailing_notfound(tmpdir):
701+
test_file = os.path.join(tmpdir, 'test.c')
702+
with open(test_file, 'wt'):
703+
pass
704+
705+
platform_file = os.path.join(tmpdir, 'test')
706+
platform_file_trail = platform_file + os.path.sep
707+
708+
exitcode, stdout, stderr = cppcheck(['--debug-lookup=platform', '--platform={}'.format(platform_file_trail), test_file])
709+
assert exitcode == 1, stdout if stdout else stderr
710+
lines = stdout.splitlines()
711+
assert lines == [
712+
"looking for platform '{}'".format(platform_file_trail),
713+
"try to load platform file '{}' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}".format(platform_file_trail, platform_file_trail),
714+
"cppcheck: error: unrecognized platform: '{}'.".format(platform_file_trail)
715+
]
716+
717+
593718
@pytest.mark.skip # TODO: fails when not run from the root folder
594719
def test_platform_lookup_nofile(tmpdir):
595720
test_file = os.path.join(tmpdir, 'test.c')
@@ -777,6 +902,26 @@ def test_addon_lookup_relative_noext_notfound(tmpdir):
777902
]
778903

779904

905+
# TODO: this can never be found - bail out early?
906+
def test_addon_lookup_relative_noext_trailing_notfound(tmpdir):
907+
test_file = os.path.join(tmpdir, 'test.c')
908+
with open(test_file, 'wt'):
909+
pass
910+
911+
exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=addon/misra/', test_file])
912+
exepath = os.path.dirname(exe)
913+
exepath_sep = exepath + os.path.sep
914+
assert exitcode == 1, stdout
915+
lines = stdout.splitlines()
916+
assert lines == [
917+
# TODO: should not append extension
918+
"looking for addon 'addon/misra/.py'",
919+
"looking for addon '{}addon/misra/.py'".format(exepath_sep),
920+
"looking for addon '{}addons/addon/misra/.py'".format(exepath_sep), # TODO: mixed separators
921+
'Did not find addon addon/misra/.py'
922+
]
923+
924+
780925
def test_addon_lookup_absolute(tmpdir):
781926
test_file = os.path.join(tmpdir, 'test.c')
782927
with open(test_file, 'wt'):
@@ -811,6 +956,42 @@ def test_addon_lookup_absolute_notfound(tmpdir):
811956
]
812957

813958

959+
def test_addon_lookup_absolute_noext_notfound(tmpdir):
960+
test_file = os.path.join(tmpdir, 'test.c')
961+
with open(test_file, 'wt'):
962+
pass
963+
964+
addon_file = os.path.join(tmpdir, 'test')
965+
addon_file_py = os.path.join(tmpdir, 'test.py') # TODO: do not add extension
966+
967+
exitcode, stdout, stderr = cppcheck(['--debug-lookup=addon', '--addon={}'.format(addon_file), test_file])
968+
assert exitcode == 1, stdout if stdout else stderr
969+
lines = stdout.splitlines()
970+
assert lines == [
971+
"looking for addon '{}'".format(addon_file_py),
972+
'Did not find addon {}'.format(addon_file_py)
973+
]
974+
975+
976+
# TODO: this can never be found - bail out early?
977+
def test_addon_lookup_absolute_noext_trailing_notfound(tmpdir):
978+
test_file = os.path.join(tmpdir, 'test.c')
979+
with open(test_file, 'wt'):
980+
pass
981+
982+
addon_file = os.path.join(tmpdir, 'test')
983+
addon_file_trail = addon_file + os.path.sep
984+
addon_file_trail_py = addon_file_trail + '.py' # TODO: do not add extension
985+
986+
exitcode, stdout, stderr = cppcheck(['--debug-lookup=addon', '--addon={}'.format(addon_file_trail), test_file])
987+
assert exitcode == 1, stdout if stdout else stderr
988+
lines = stdout.splitlines()
989+
assert lines == [
990+
"looking for addon '{}'".format(addon_file_trail_py),
991+
'Did not find addon {}'.format(addon_file_trail_py)
992+
]
993+
994+
814995
def test_addon_lookup_nofile(tmpdir):
815996
test_file = os.path.join(tmpdir, 'test.c')
816997
with open(test_file, 'wt'):

0 commit comments

Comments
 (0)