1
1
import os
2
2
import sys
3
3
import pytest
4
+ import shutil
4
5
5
- from testutils import cppcheck_ex , cppcheck
6
+ from testutils import cppcheck_ex , cppcheck , __lookup_cppcheck_exe
6
7
7
8
def __remove_std_lookup_log (l : list , exepath ):
8
9
l .remove ("looking for library 'std.cfg'" )
@@ -63,9 +64,7 @@ def test_lib_lookup_notfound(tmpdir):
63
64
assert lines == [
64
65
# TODO: specify which folder is actually used for lookup here
65
66
"looking for library 'none.cfg'" ,
66
- # TODO: lookup of '{exepath}/none' missing - could conflict with the platform lookup though
67
67
"looking for library '{}/none.cfg'" .format (exepath ),
68
- # TODO: lookup of '{exepath}/cfg/none' missing
69
68
"looking for library '{}/cfg/none.cfg'" .format (exepath ),
70
69
"library not found: 'none'" ,
71
70
"cppcheck: Failed to load library configuration file 'none'. File not found"
@@ -260,7 +259,7 @@ def test_platform_lookup_builtin(tmpdir):
260
259
]
261
260
262
261
263
- @pytest .mark .skip # TODO: perform additional lookups when run via symlink in CI
262
+ @pytest .mark .skip # TODO: performs additional lookups when run via symlink in CI
264
263
def test_platform_lookup (tmpdir ):
265
264
test_file = os .path .join (tmpdir , 'test.c' )
266
265
with open (test_file , 'wt' ):
@@ -281,7 +280,7 @@ def test_platform_lookup(tmpdir):
281
280
]
282
281
283
282
284
- @pytest .mark .skip # TODO: perform additional lookups when run via symlink in CI
283
+ @pytest .mark .skip # TODO: performs additional lookups when run via symlink in CI
285
284
def test_platform_lookup_ext (tmpdir ):
286
285
test_file = os .path .join (tmpdir , 'test.c' )
287
286
with open (test_file , 'wt' ):
@@ -440,7 +439,7 @@ def test_platform_lookup_absolute_notfound(tmpdir):
440
439
]
441
440
442
441
443
- @pytest .mark .skip # TODO: perform additional lookups when run via symlink in CI
442
+ @pytest .mark .skip # TODO: performs additional lookups when run via symlink in CI
444
443
def test_platform_lookup_nofile (tmpdir ):
445
444
test_file = os .path .join (tmpdir , 'test.c' )
446
445
with open (test_file , 'wt' ):
@@ -648,7 +647,7 @@ def test_addon_lookup_nofile(tmpdir):
648
647
exitcode , stdout , stderr , exe = cppcheck_ex (['--debug-lookup=addon' , '--addon=misra' , test_file ])
649
648
exepath = os .path .dirname (exe )
650
649
exepath_sep = exepath + os .path .sep
651
- assert exitcode == 0 , stdout if stdout else stderr # TODO. should fail when addon is not found
650
+ assert exitcode == 0 , stdout if stdout else stderr
652
651
lines = stdout .splitlines ()
653
652
assert lines == [
654
653
"looking for addon 'misra.py'" ,
@@ -677,25 +676,29 @@ def test_addon_lookup_invalid(tmpdir):
677
676
]
678
677
679
678
680
- @pytest .mark .skip # TODO
681
679
def test_config_lookup (tmpdir ):
680
+ cppcheck_exe = __lookup_cppcheck_exe ()
681
+ bin_dir = os .path .dirname (cppcheck_exe )
682
+ tmp_cppcheck_exe = shutil .copy2 (cppcheck_exe , tmpdir )
683
+ if sys .platform == 'win32' :
684
+ shutil .copy2 (os .path .join (bin_dir , 'cppcheck-core.dll' ), tmpdir )
685
+ shutil .copytree (os .path .join (bin_dir , 'cfg' ), os .path .join (tmpdir , 'cfg' ))
686
+
682
687
test_file = os .path .join (tmpdir , 'test.c' )
683
688
with open (test_file , 'wt' ):
684
689
pass
685
690
686
- # TODO: needs to be in exepath so this is found
687
691
config_file = os .path .join (tmpdir , 'cppcheck.cfg' )
688
- with open (config_file , 'wt' ):
689
- pass
692
+ with open (config_file , 'wt' ) as f :
693
+ f . write ( '{}' )
690
694
691
- exitcode , stdout , stderr , exe = cppcheck_ex (['--debug-lookup=config' , '--addon=misra' , test_file ], cwd = tmpdir )
695
+ exitcode , stdout , stderr , exe = cppcheck_ex (['--debug-lookup=config' , test_file ], cwd = tmpdir , cppcheck_exe = tmp_cppcheck_exe )
692
696
exepath = os .path .dirname (exe )
693
697
exepath_sep = exepath + os .path .sep
694
698
assert exitcode == 0 , stdout if stdout else stderr
695
699
lines = stdout .splitlines ()
696
700
assert lines == [
697
701
"looking for '{}cppcheck.cfg'" .format (exepath_sep ),
698
- 'no configuration found' ,
699
702
'Checking {} ...' .format (test_file )
700
703
]
701
704
@@ -716,6 +719,30 @@ def test_config_lookup_notfound(tmpdir):
716
719
'Checking {} ...' .format (test_file )
717
720
]
718
721
719
- # TODO: test handling of invalid configuration
722
+ def test_config_invalid (tmpdir ):
723
+ cppcheck_exe = __lookup_cppcheck_exe ()
724
+ bin_dir = os .path .dirname (cppcheck_exe )
725
+ tmp_cppcheck_exe = shutil .copy2 (cppcheck_exe , tmpdir )
726
+ if sys .platform == 'win32' :
727
+ shutil .copy2 (os .path .join (bin_dir , 'cppcheck-core.dll' ), tmpdir )
728
+ shutil .copytree (os .path .join (bin_dir , 'cfg' ), os .path .join (tmpdir , 'cfg' ))
729
+
730
+ test_file = os .path .join (tmpdir , 'test.c' )
731
+ with open (test_file , 'wt' ):
732
+ pass
733
+
734
+ config_file = os .path .join (tmpdir , 'cppcheck.cfg' )
735
+ with open (config_file , 'wt' ):
736
+ pass
737
+
738
+ exitcode , stdout , stderr , exe = cppcheck_ex (['--debug-lookup=config' , test_file ], cwd = tmpdir , cppcheck_exe = tmp_cppcheck_exe )
739
+ exepath = os .path .dirname (exe )
740
+ exepath_sep = exepath + os .path .sep
741
+ assert exitcode == 1 , stdout if stdout else stderr
742
+ lines = stdout .splitlines ()
743
+ assert lines == [
744
+ "looking for '{}cppcheck.cfg'" .format (exepath_sep ),
745
+ 'cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 1 near: '
746
+ ]
720
747
721
748
# TODO: test with FILESDIR
0 commit comments