@@ -11,7 +11,6 @@ def __remove_std_lookup_log(l : list, exepath):
1111 return l
1212
1313
14- # TODO: test with FILESDIR
1514def test_lib_lookup (tmpdir ):
1615 test_file = os .path .join (tmpdir , 'test.c' )
1716 with open (test_file , 'wt' ):
@@ -24,15 +23,32 @@ def test_lib_lookup(tmpdir):
2423 assert exitcode == 0 , stdout if stdout else stderr
2524 lines = __remove_std_lookup_log (stdout .splitlines (), exepath )
2625 assert lines == [
27- "looking for library 'gnu'" ,
2826 "looking for library 'gnu.cfg'" ,
2927 "looking for library '{}/gnu.cfg'" .format (exepath ),
3028 "looking for library '{}/cfg/gnu.cfg'" .format (exepath ),
3129 'Checking {} ...' .format (test_file )
3230 ]
3331
3432
35- # TODO: test with FILESDIR
33+ def test_lib_lookup_ext (tmpdir ):
34+ test_file = os .path .join (tmpdir , 'test.c' )
35+ with open (test_file , 'wt' ):
36+ pass
37+
38+ exitcode , stdout , stderr , exe = cppcheck_ex (['--debug-lookup=library' , '--library=gnu.cfg' , test_file ])
39+ exepath = os .path .dirname (exe )
40+ if sys .platform == 'win32' :
41+ exepath = exepath .replace ('\\ ' , '/' )
42+ assert exitcode == 0 , stdout if stdout else stderr
43+ lines = __remove_std_lookup_log (stdout .splitlines (), exepath )
44+ assert lines == [
45+ "looking for library 'gnu.cfg'" ,
46+ "looking for library '{}/gnu.cfg'" .format (exepath ),
47+ "looking for library '{}/cfg/gnu.cfg'" .format (exepath ),
48+ 'Checking {} ...' .format (test_file )
49+ ]
50+
51+
3652def test_lib_lookup_notfound (tmpdir ):
3753 test_file = os .path .join (tmpdir , 'test.c' )
3854 with open (test_file , 'wt' ):
@@ -46,7 +62,6 @@ def test_lib_lookup_notfound(tmpdir):
4662 lines = __remove_std_lookup_log (stdout .splitlines (), exepath )
4763 assert lines == [
4864 # TODO: specify which folder is actually used for lookup here
49- "looking for library 'none'" , # TODO: this could conflict with the platform lookup
5065 "looking for library 'none.cfg'" ,
5166 # TODO: lookup of '{exepath}/none' missing - could conflict with the platform lookup though
5267 "looking for library '{}/none.cfg'" .format (exepath ),
@@ -57,6 +72,66 @@ def test_lib_lookup_notfound(tmpdir):
5772 ]
5873
5974
75+ def test_lib_lookup_ext_notfound (tmpdir ):
76+ test_file = os .path .join (tmpdir , 'test.c' )
77+ with open (test_file , 'wt' ):
78+ pass
79+
80+ exitcode , stdout , stderr , exe = cppcheck_ex (['--debug-lookup=library' , '--library=none.cfg' , test_file ])
81+ exepath = os .path .dirname (exe )
82+ if sys .platform == 'win32' :
83+ exepath = exepath .replace ('\\ ' , '/' )
84+ assert exitcode == 1 , stdout if stdout else stderr
85+ lines = __remove_std_lookup_log (stdout .splitlines (), exepath )
86+ assert lines == [
87+ "looking for library 'none.cfg'" ,
88+ "looking for library '{}/none.cfg'" .format (exepath ),
89+ "looking for library '{}/cfg/none.cfg'" .format (exepath ),
90+ "library not found: 'none.cfg'" ,
91+ "cppcheck: Failed to load library configuration file 'none.cfg'. File not found"
92+ ]
93+
94+
95+ def test_lib_lookup_relative_notfound (tmpdir ):
96+ test_file = os .path .join (tmpdir , 'test.c' )
97+ with open (test_file , 'wt' ):
98+ pass
99+
100+ exitcode , stdout , stderr , exe = cppcheck_ex (['--debug-lookup=library' , '--library=config/gnu.xml' , test_file ])
101+ exepath = os .path .dirname (exe )
102+ if sys .platform == 'win32' :
103+ exepath = exepath .replace ('\\ ' , '/' )
104+ assert exitcode == 1 , stdout if stdout else stderr
105+ lines = __remove_std_lookup_log (stdout .splitlines (), exepath )
106+ assert lines == [
107+ "looking for library 'config/gnu.xml'" ,
108+ "looking for library '{}/config/gnu.xml'" .format (exepath ),
109+ "looking for library '{}/cfg/config/gnu.xml'" .format (exepath ),
110+ "library not found: 'config/gnu.xml'" ,
111+ "cppcheck: Failed to load library configuration file 'config/gnu.xml'. File not found"
112+ ]
113+
114+
115+ def test_lib_lookup_relative_noext_notfound (tmpdir ):
116+ test_file = os .path .join (tmpdir , 'test.c' )
117+ with open (test_file , 'wt' ):
118+ pass
119+
120+ exitcode , stdout , stderr , exe = cppcheck_ex (['--debug-lookup=library' , '--library=config/gnu' , test_file ])
121+ exepath = os .path .dirname (exe )
122+ if sys .platform == 'win32' :
123+ exepath = exepath .replace ('\\ ' , '/' )
124+ assert exitcode == 1 , stdout if stdout else stderr
125+ lines = __remove_std_lookup_log (stdout .splitlines (), exepath )
126+ assert lines == [
127+ "looking for library 'config/gnu.cfg'" ,
128+ "looking for library '{}/config/gnu.cfg'" .format (exepath ),
129+ "looking for library '{}/cfg/config/gnu.cfg'" .format (exepath ),
130+ "library not found: 'config/gnu'" ,
131+ "cppcheck: Failed to load library configuration file 'config/gnu'. File not found"
132+ ]
133+
134+
60135def test_lib_lookup_absolute (tmpdir ):
61136 test_file = os .path .join (tmpdir , 'test.c' )
62137 with open (test_file , 'wt' ):
@@ -120,7 +195,6 @@ def test_lib_lookup_nofile(tmpdir):
120195 assert exitcode == 0 , stdout if stdout else stderr
121196 lines = __remove_std_lookup_log (stdout .splitlines (), exepath )
122197 assert lines == [
123- "looking for library 'gtk'" ,
124198 "looking for library 'gtk.cfg'" ,
125199 "looking for library '{}/gtk.cfg'" .format (exepath ),
126200 "looking for library '{}/cfg/gtk.cfg'" .format (exepath ),
@@ -140,11 +214,9 @@ def test_lib_lookup_multi(tmpdir):
140214 assert exitcode == 0 , stdout if stdout else stderr
141215 lines = __remove_std_lookup_log (stdout .splitlines (), exepath )
142216 assert lines == [
143- "looking for library 'posix'" ,
144217 "looking for library 'posix.cfg'" ,
145218 "looking for library '{}/posix.cfg'" .format (exepath ),
146219 "looking for library '{}/cfg/posix.cfg'" .format (exepath ),
147- "looking for library 'gnu'" ,
148220 "looking for library 'gnu.cfg'" ,
149221 "looking for library '{}/gnu.cfg'" .format (exepath ),
150222 "looking for library '{}/cfg/gnu.cfg'" .format (exepath ),
@@ -167,7 +239,6 @@ def test_platform_lookup_builtin(tmpdir):
167239
168240
169241# TODO: behaves differently when using a CMake build
170- # TODO: test with FILESDIR
171242@pytest .mark .skip
172243def test_platform_lookup_external (tmpdir ):
173244 test_file = os .path .join (tmpdir , 'test.c' )
@@ -190,7 +261,6 @@ def test_platform_lookup_external(tmpdir):
190261 ]
191262
192263
193- # TODO: test with FILESDIR
194264def test_platform_lookup_external_notfound (tmpdir ):
195265 test_file = os .path .join (tmpdir , 'test.c' )
196266 with open (test_file , 'wt' ):
@@ -218,7 +288,6 @@ def test_platform_lookup_external_notfound(tmpdir):
218288 ]
219289
220290
221- # TODO: test with FILESDIR
222291def test_addon_lookup (tmpdir ):
223292 test_file = os .path .join (tmpdir , 'test.c' )
224293 with open (test_file , 'wt' ):
@@ -237,7 +306,6 @@ def test_addon_lookup(tmpdir):
237306 ]
238307
239308
240- # TODO: test with FILESDIR
241309def test_addon_lookup_ext (tmpdir ):
242310 test_file = os .path .join (tmpdir , 'test.c' )
243311 with open (test_file , 'wt' ):
@@ -256,7 +324,6 @@ def test_addon_lookup_ext(tmpdir):
256324 ]
257325
258326
259- # TODO: test with FILESDIR
260327def test_addon_lookup_notfound (tmpdir ):
261328 test_file = os .path .join (tmpdir , 'test.c' )
262329 with open (test_file , 'wt' ):
@@ -275,7 +342,6 @@ def test_addon_lookup_notfound(tmpdir):
275342 ]
276343
277344
278- # TODO: test with FILESDIR
279345def test_addon_lookup_ext_notfound (tmpdir ):
280346 test_file = os .path .join (tmpdir , 'test.c' )
281347 with open (test_file , 'wt' ):
@@ -294,7 +360,106 @@ def test_addon_lookup_ext_notfound(tmpdir):
294360 ]
295361
296362
297- # TODO: test with FILESDIR
363+ def test_addon_lookup_relative_notfound (tmpdir ):
364+ test_file = os .path .join (tmpdir , 'test.c' )
365+ with open (test_file , 'wt' ):
366+ pass
367+
368+ exitcode , stdout , _ , exe = cppcheck_ex (['--debug-lookup=addon' , '--addon=addon/misra.py' , test_file ])
369+ exepath = os .path .dirname (exe )
370+ exepath_sep = exepath + os .path .sep
371+ assert exitcode == 1 , stdout
372+ lines = stdout .splitlines ()
373+ assert lines == [
374+ "looking for addon 'addon/misra.py'" ,
375+ "looking for addon '{}addon/misra.py'" .format (exepath_sep ),
376+ "looking for addon '{}addons/addon/misra.py'" .format (exepath_sep ), # TODO: mixed separators
377+ 'Did not find addon addon/misra.py'
378+ ]
379+
380+
381+ def test_addon_lookup_relative_noext_notfound (tmpdir ):
382+ test_file = os .path .join (tmpdir , 'test.c' )
383+ with open (test_file , 'wt' ):
384+ pass
385+
386+ exitcode , stdout , _ , exe = cppcheck_ex (['--debug-lookup=addon' , '--addon=addon/misra' , test_file ])
387+ exepath = os .path .dirname (exe )
388+ exepath_sep = exepath + os .path .sep
389+ assert exitcode == 1 , stdout
390+ lines = stdout .splitlines ()
391+ assert lines == [
392+ "looking for addon 'addon/misra.py'" ,
393+ "looking for addon '{}addon/misra.py'" .format (exepath_sep ),
394+ "looking for addon '{}addons/addon/misra.py'" .format (exepath_sep ), # TODO: mixed separators
395+ 'Did not find addon addon/misra.py'
396+ ]
397+
398+
399+ def test_addon_lookup_absolute (tmpdir ):
400+ test_file = os .path .join (tmpdir , 'test.c' )
401+ with open (test_file , 'wt' ):
402+ pass
403+
404+ addon_file = os .path .join (tmpdir , 'test.py' )
405+ with open (addon_file , 'wt' ) as f :
406+ f .write ('''''' )
407+
408+ exitcode , stdout , stderr , exe = cppcheck_ex (['--debug-lookup=addon' , '--addon={}' .format (addon_file ), test_file ])
409+ exepath = os .path .dirname (exe )
410+ exepath_sep = exepath + os .path .sep
411+ assert exitcode == 0 , stdout if stdout else stderr
412+ lines = stdout .splitlines ()
413+ assert lines == [
414+ "looking for addon '{}'" .format (addon_file ),
415+ 'Checking {} ...' .format (test_file )
416+ ]
417+
418+
419+ def test_addon_lookup_absolute_notfound (tmpdir ):
420+ test_file = os .path .join (tmpdir , 'test.c' )
421+ with open (test_file , 'wt' ):
422+ pass
423+
424+ addon_file = os .path .join (tmpdir , 'test.py' )
425+
426+ exitcode , stdout , stderr , exe = cppcheck_ex (['--debug-lookup=addon' , '--addon={}' .format (addon_file ), test_file ])
427+ exepath = os .path .dirname (exe )
428+ exepath_sep = exepath + os .path .sep
429+ assert exitcode == 1 , stdout if stdout else stderr
430+ lines = stdout .splitlines ()
431+ assert lines == [
432+ "looking for addon '{}'" .format (addon_file ),
433+ "looking for addon '{}{}'" .format (exepath_sep , addon_file ), # TODO: should not perform this lookup
434+ "looking for addon '{}addons/{}'" .format (exepath_sep , addon_file ), # TODO: should not perform this lookup
435+ 'Did not find addon {}' .format (addon_file )
436+ ]
437+
438+
439+ def test_addon_lookup_nofile (tmpdir ):
440+ test_file = os .path .join (tmpdir , 'test.c' )
441+ with open (test_file , 'wt' ):
442+ pass
443+
444+ # make sure we do not produce an error when the attempted lookup path is a directory and not a file
445+ misra_dir = os .path .join (tmpdir , 'misra' )
446+ os .mkdir (misra_dir )
447+ misra_cfg_dir = os .path .join (tmpdir , 'misra.py' )
448+ os .mkdir (misra_cfg_dir )
449+
450+ exitcode , stdout , stderr , exe = cppcheck_ex (['--debug-lookup=addon' , '--addon=misra' , test_file ])
451+ exepath = os .path .dirname (exe )
452+ exepath_sep = exepath + os .path .sep
453+ assert exitcode == 0 , stdout if stdout else stderr # TODO. should fail when addon is not found
454+ lines = stdout .splitlines ()
455+ assert lines == [
456+ "looking for addon 'misra.py'" ,
457+ "looking for addon '{}misra.py'" .format (exepath_sep ),
458+ "looking for addon '{}addons/misra.py'" .format (exepath_sep ), # TODO: mixed separators
459+ 'Checking {} ...' .format (test_file )
460+ ]
461+
462+
298463@pytest .mark .skip
299464def test_config_lookup (tmpdir ):
300465 test_file = os .path .join (tmpdir , 'test.c' )
@@ -318,7 +483,6 @@ def test_config_lookup(tmpdir):
318483 ]
319484
320485
321- # TODO: test with FILESDIR
322486def test_config_lookup_notfound (tmpdir ):
323487 test_file = os .path .join (tmpdir , 'test.c' )
324488 with open (test_file , 'wt' ):
@@ -333,4 +497,7 @@ def test_config_lookup_notfound(tmpdir):
333497 "looking for '{}cppcheck.cfg'" .format (exepath_sep ),
334498 'no configuration found' ,
335499 'Checking {} ...' .format (test_file )
336- ]
500+ ]
501+
502+ # TODO: test with FILESDIR
503+ # TODO: test with extension already in place
0 commit comments