2
2
import sys
3
3
import pytest
4
4
import shutil
5
+ import json
5
6
6
7
from testutils import cppcheck_ex , cppcheck , __lookup_cppcheck_exe
7
8
@@ -12,6 +13,48 @@ def __remove_std_lookup_log(l : list, exepath):
12
13
return l
13
14
14
15
16
+ def __create_gui_project (tmpdir ):
17
+ file_name = 'test.c'
18
+ test_file = os .path .join (tmpdir , file_name )
19
+ with open (test_file , 'wt' ):
20
+ pass
21
+
22
+ project_file = os .path .join (tmpdir , 'project.cppcheck' )
23
+ with open (project_file , 'wt' ) as f :
24
+ f .write (
25
+ """<?xml version="1.0" encoding="UTF-8"?>
26
+ <project version="1">
27
+ <paths>
28
+ <dir name="{}"/>
29
+ </paths>
30
+ </project>""" .format (test_file )
31
+ )
32
+
33
+ return project_file , test_file
34
+
35
+
36
+ def __create_compdb (tmpdir ):
37
+ file_name = 'test.c'
38
+ test_file = os .path .join (tmpdir , file_name )
39
+ with open (test_file , 'wt' ):
40
+ pass
41
+
42
+ compilation_db = [
43
+ {
44
+ "directory" : str (tmpdir ),
45
+ "command" : "c++ -o {}.o -c {}" .format (os .path .basename (file_name ), file_name ),
46
+ "file" : file_name ,
47
+ "output" : "{}.o" .format (os .path .basename (file_name ))
48
+ }
49
+ ]
50
+
51
+ compile_commands = os .path .join (tmpdir , 'compile_commands.json' )
52
+ with open (compile_commands , 'wt' ) as f :
53
+ f .write (json .dumps (compilation_db ))
54
+
55
+ return compile_commands , test_file
56
+
57
+
15
58
def test_lib_lookup (tmpdir ):
16
59
test_file = os .path .join (tmpdir , 'test.c' )
17
60
with open (test_file , 'wt' ):
@@ -71,6 +114,46 @@ def test_lib_lookup_notfound(tmpdir):
71
114
]
72
115
73
116
117
+ def test_lib_lookup_notfound_project (tmpdir ): # #13938
118
+ project_file , _ = __create_gui_project (tmpdir )
119
+
120
+ exitcode , stdout , _ , exe = cppcheck_ex (['--debug-lookup=library' , '--library=none' , '--project={}' .format (project_file )])
121
+ exepath = os .path .dirname (exe )
122
+ if sys .platform == 'win32' :
123
+ exepath = exepath .replace ('\\ ' , '/' )
124
+ assert exitcode == 1 , stdout
125
+ lines = __remove_std_lookup_log (stdout .splitlines (), exepath )
126
+ assert lines == [
127
+ # TODO: needs to look relative to the project first
128
+ # TODO: specify which folder is actually used for lookup here
129
+ "looking for library 'none.cfg'" ,
130
+ "looking for library '{}/none.cfg'" .format (exepath ),
131
+ "looking for library '{}/cfg/none.cfg'" .format (exepath ),
132
+ "library not found: 'none'" ,
133
+ "cppcheck: Failed to load library configuration file 'none'. File not found"
134
+ ]
135
+
136
+
137
+ def test_lib_lookup_notfound_compdb (tmpdir ): # #13938
138
+ compdb_file , _ = __create_compdb (tmpdir )
139
+
140
+ exitcode , stdout , _ , exe = cppcheck_ex (['--debug-lookup=library' , '--library=none' , '--project={}' .format (compdb_file )])
141
+ exepath = os .path .dirname (exe )
142
+ if sys .platform == 'win32' :
143
+ exepath = exepath .replace ('\\ ' , '/' )
144
+ assert exitcode == 1 , stdout
145
+ lines = __remove_std_lookup_log (stdout .splitlines (), exepath )
146
+ assert lines == [
147
+ # TODO: needs to look relative to the project first
148
+ # TODO: specify which folder is actually used for lookup here
149
+ "looking for library 'none.cfg'" ,
150
+ "looking for library '{}/none.cfg'" .format (exepath ),
151
+ "looking for library '{}/cfg/none.cfg'" .format (exepath ),
152
+ "library not found: 'none'" ,
153
+ "cppcheck: Failed to load library configuration file 'none'. File not found"
154
+ ]
155
+
156
+
74
157
def test_lib_lookup_ext_notfound (tmpdir ):
75
158
test_file = os .path .join (tmpdir , 'test.c' )
76
159
with open (test_file , 'wt' ):
@@ -273,7 +356,7 @@ def test_platform_lookup(tmpdir):
273
356
assert exitcode == 0 , stdout if stdout else stderr
274
357
lines = stdout .splitlines ()
275
358
assert lines == [
276
- "looking for platform 'avr8' in '{}'" .format (exepath_bin ), # TODO: this not not the path *of* the executable but the the path *to* the executable
359
+ "looking for platform 'avr8' relative to '{}'" .format (exepath_bin ),
277
360
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml" ,
278
361
"try to load platform file 'platforms/avr8.xml' ... Success" ,
279
362
'Checking {} ...' .format (test_file )
@@ -294,7 +377,7 @@ def test_platform_lookup_ext(tmpdir):
294
377
assert exitcode == 0 , stdout if stdout else stderr
295
378
lines = stdout .splitlines ()
296
379
assert lines == [
297
- "looking for platform 'avr8.xml' in '{}'" .format (exepath_bin ), # TODO: this not not the path *of* the executable but the the path *to* the executable
380
+ "looking for platform 'avr8.xml' relative to '{}'" .format (exepath_bin ),
298
381
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml" ,
299
382
"try to load platform file 'platforms/avr8.xml' ... Success" ,
300
383
'Checking {} ...' .format (test_file )
@@ -315,7 +398,51 @@ def test_platform_lookup_notfound(tmpdir):
315
398
assert exitcode == 1 , stdout
316
399
lines = stdout .splitlines ()
317
400
assert lines == [
318
- "looking for platform 'none' in '{}'" .format (exepath_bin ), # TODO: this is not the path *of* the executable but the the path *to* the executable
401
+ "looking for platform 'none' relative to '{}'" .format (exepath_bin ),
402
+ "try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml" ,
403
+ "try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml" ,
404
+ "try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml" .format (exepath , exepath ),
405
+ "try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml" .format (exepath , exepath ),
406
+ "cppcheck: error: unrecognized platform: 'none'."
407
+ ]
408
+
409
+
410
+ def test_platform_lookup_notfound_project (tmpdir ): # #13939
411
+ project_file , _ = __create_gui_project (tmpdir )
412
+
413
+ exitcode , stdout , _ , exe = cppcheck_ex (['--debug-lookup=platform' , '--platform=none' , '--project={}' .format (project_file )])
414
+ exepath = os .path .dirname (exe )
415
+ exepath_bin = os .path .join (exepath , 'cppcheck' )
416
+ if sys .platform == 'win32' :
417
+ exepath = exepath .replace ('\\ ' , '/' )
418
+ exepath_bin += '.exe'
419
+ assert exitcode == 1 , stdout
420
+ lines = stdout .splitlines ()
421
+ assert lines == [
422
+ # TODO: needs to look relative to project file first
423
+ "looking for platform 'none' relative to '{}'" .format (exepath_bin ),
424
+ "try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml" ,
425
+ "try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml" ,
426
+ "try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml" .format (exepath , exepath ),
427
+ "try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml" .format (exepath , exepath ),
428
+ "cppcheck: error: unrecognized platform: 'none'."
429
+ ]
430
+
431
+
432
+ def test_platform_lookup_notfound_compdb (tmpdir ): # #13939
433
+ compdb_file , _ = __create_compdb (tmpdir )
434
+
435
+ exitcode , stdout , _ , exe = cppcheck_ex (['--debug-lookup=platform' , '--platform=none' , '--project={}' .format (compdb_file )])
436
+ exepath = os .path .dirname (exe )
437
+ exepath_bin = os .path .join (exepath , 'cppcheck' )
438
+ if sys .platform == 'win32' :
439
+ exepath = exepath .replace ('\\ ' , '/' )
440
+ exepath_bin += '.exe'
441
+ assert exitcode == 1 , stdout
442
+ lines = stdout .splitlines ()
443
+ assert lines == [
444
+ # TODO: needs to look relative to project file first
445
+ "looking for platform 'none' relative to '{}'" .format (exepath_bin ),
319
446
"try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml" ,
320
447
"try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml" ,
321
448
"try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml" .format (exepath , exepath ),
@@ -338,7 +465,7 @@ def test_platform_lookup_ext_notfound(tmpdir):
338
465
assert exitcode == 1 , stdout if stdout else stderr
339
466
lines = stdout .splitlines ()
340
467
assert lines == [
341
- "looking for platform 'none.xml' in '{}'" .format (exepath_bin ), # TODO: this not not the path *of* the executable but the the path *to* the executable
468
+ "looking for platform 'none.xml' relative to '{}'" .format (exepath_bin ),
342
469
"try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml" ,
343
470
"try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml" ,
344
471
"try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml" .format (exepath , exepath ),
@@ -361,7 +488,7 @@ def test_platform_lookup_relative_notfound(tmpdir):
361
488
assert exitcode == 1 , stdout if stdout else stderr
362
489
lines = stdout .splitlines ()
363
490
assert lines == [
364
- "looking for platform 'platform/none.xml' in '{}'" .format (exepath_bin ), # TODO: this not not the path *of* the executable but the the path *to* the executable
491
+ "looking for platform 'platform/none.xml' relative to '{}'" .format (exepath_bin ),
365
492
"try to load platform file 'platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platform/none.xml" ,
366
493
"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" ,
367
494
"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 ),
@@ -384,7 +511,7 @@ def test_platform_lookup_relative_noext_notfound(tmpdir):
384
511
assert exitcode == 1 , stdout if stdout else stderr
385
512
lines = stdout .splitlines ()
386
513
assert lines == [
387
- "looking for platform 'platform/none' in '{}'" .format (exepath_bin ), # TODO: this not not the path *of* the executable but the the path *to* the executable
514
+ "looking for platform 'platform/none' relative to '{}'" .format (exepath_bin ),
388
515
"try to load platform file 'platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platform/none.xml" ,
389
516
"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" ,
390
517
"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 ),
@@ -412,7 +539,7 @@ def test_platform_lookup_absolute(tmpdir):
412
539
assert exitcode == 0 , stdout if stdout else stderr
413
540
lines = stdout .splitlines ()
414
541
assert lines == [
415
- "looking for platform '{}' in '{}'" .format (platform_file , exepath_bin ), # TODO: this not not the path *of* the executable but the the path *to* the executable
542
+ "looking for platform '{}' relative to '{}'" .format (platform_file , exepath_bin ),
416
543
"try to load platform file '{}' ... Success" .format (platform_file ),
417
544
'Checking {} ...' .format (test_file )
418
545
]
@@ -433,7 +560,7 @@ def test_platform_lookup_absolute_notfound(tmpdir):
433
560
assert exitcode == 1 , stdout if stdout else stderr
434
561
lines = stdout .splitlines ()
435
562
assert lines == [
436
- "looking for platform '{}' in '{}'" .format (platform_file , exepath_bin ), # TODO: this not not the path *of* the executable but the the path *to* the executable
563
+ "looking for platform '{}' relative to '{}'" .format (platform_file , exepath_bin ),
437
564
"try to load platform file '{}' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}" .format (platform_file , platform_file ),
438
565
"cppcheck: error: unrecognized platform: '{}'." .format (platform_file )
439
566
]
@@ -457,7 +584,7 @@ def test_platform_lookup_nofile(tmpdir):
457
584
assert exitcode == 0 , stdout if stdout else stderr
458
585
lines = stdout .splitlines ()
459
586
assert lines == [
460
- "looking for platform 'avr8' in '{}'" .format (exepath_bin ), # TODO: this not not the path *of* the executable but the the path *to* the executable
587
+ "looking for platform 'avr8' relative to '{}'" .format (exepath_bin ),
461
588
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml" ,
462
589
"try to load platform file 'platforms/avr8.xml' ... Success" ,
463
590
'Checking {} ...' .format (test_file )
@@ -481,7 +608,7 @@ def test_platform_lookup_invalid(tmpdir):
481
608
assert exitcode == 1 , stdout if stdout else stderr
482
609
lines = stdout .splitlines ()
483
610
assert lines == [
484
- "looking for platform 'avr8' in '{}'" .format (exepath_bin ), # TODO: this not not the path *of* the executable but the the path *to* the executable
611
+ "looking for platform 'avr8' relative to '{}'" .format (exepath_bin ),
485
612
"try to load platform file 'avr8.xml' ... Error=XML_ERROR_PARSING_TEXT ErrorID=8 (0x8) Line number=1" ,
486
613
"cppcheck: error: unrecognized platform: 'avr8'."
487
614
]
@@ -541,6 +668,41 @@ def test_addon_lookup_notfound(tmpdir):
541
668
]
542
669
543
670
671
+ @pytest .mark .xfail (strict = True ) # TODO: no addon lookup is being performed at all
672
+ def test_addon_lookup_notfound_project (tmpdir ): # #13940 / #13941
673
+ project_file , _ = __create_gui_project (tmpdir )
674
+
675
+ exitcode , stdout , _ , exe = cppcheck_ex (['--debug-lookup=addon' , '--addon=none' , '--project={}' .format (project_file )])
676
+ exepath = os .path .dirname (exe )
677
+ exepath_sep = exepath + os .path .sep
678
+ assert exitcode == 0 , stdout
679
+ lines = stdout .splitlines ()
680
+ assert lines == [
681
+ # TODO: needs to look relative to the project file first
682
+ "looking for addon 'none.py'" ,
683
+ "looking for addon '{}none.py'" .format (exepath_sep ),
684
+ "looking for addon '{}addons/none.py'" .format (exepath_sep ), # TODO: mixed separators
685
+ 'Did not find addon none.py'
686
+ ]
687
+
688
+
689
+ def test_addon_lookup_notfound_compdb (tmpdir ): # #13940
690
+ compdb_file , _ = __create_compdb (tmpdir )
691
+
692
+ exitcode , stdout , _ , exe = cppcheck_ex (['--debug-lookup=addon' , '--addon=none' , '--project={}' .format (compdb_file )])
693
+ exepath = os .path .dirname (exe )
694
+ exepath_sep = exepath + os .path .sep
695
+ assert exitcode == 1 , stdout
696
+ lines = stdout .splitlines ()
697
+ assert lines == [
698
+ # TODO: needs to look relative to the project file first
699
+ "looking for addon 'none.py'" ,
700
+ "looking for addon '{}none.py'" .format (exepath_sep ),
701
+ "looking for addon '{}addons/none.py'" .format (exepath_sep ), # TODO: mixed separators
702
+ 'Did not find addon none.py'
703
+ ]
704
+
705
+
544
706
def test_addon_lookup_ext_notfound (tmpdir ):
545
707
test_file = os .path .join (tmpdir , 'test.c' )
546
708
with open (test_file , 'wt' ):
@@ -715,6 +877,7 @@ def test_config_lookup_notfound(tmpdir):
715
877
'Checking {} ...' .format (test_file )
716
878
]
717
879
880
+
718
881
def test_config_invalid (tmpdir ):
719
882
cppcheck_exe = __lookup_cppcheck_exe ()
720
883
bin_dir = os .path .dirname (cppcheck_exe )
0 commit comments