@@ -157,7 +157,7 @@ def test_project_empty_fields(tmpdir):
157157 </paths>
158158 <exclude/>
159159 <exclude>
160- <paths />
160+ <path />
161161 </exclude>
162162 <function-contracts/>
163163 <variable-contracts/>
@@ -531,4 +531,109 @@ def test_project_file_ignore(tmpdir):
531531 'cppcheck: Maybe all paths were ignored?'
532532 ]
533533
534+ assert_cppcheck (args , ec_exp = 1 , err_exp = [], out_exp = out_lines )
535+
536+
537+ def test_project_file_ignore_2 (tmpdir ):
538+ test_file = os .path .join (tmpdir , 'test.cpp' )
539+ with open (test_file , 'wt' ) as f :
540+ pass
541+
542+ project_file = os .path .join (tmpdir , 'test.cppcheck' )
543+ with open (project_file , 'wt' ) as f :
544+ f .write (
545+ """<?xml version="1.0" encoding="UTF-8"?>
546+ <project>
547+ <paths>
548+ <dir name="{}"/>
549+ </paths>
550+ <exclude>
551+ <path name="test.cpp"/>
552+ </exclude>
553+ </project>""" .format (test_file ))
554+
555+ args = ['--project={}' .format (project_file )]
556+ out_lines = [
557+ 'cppcheck: error: could not find or open any of the paths given.' ,
558+ 'cppcheck: Maybe all paths were ignored?'
559+ ]
560+
561+ assert_cppcheck (args , ec_exp = 1 , err_exp = [], out_exp = out_lines )
562+
563+
564+ def test_project_file_ignore_3 (tmpdir ):
565+ test_file = os .path .join (tmpdir , 'test.cpp' )
566+ with open (test_file , 'wt' ) as f :
567+ pass
568+
569+ project_file = os .path .join (tmpdir , 'test.cppcheck' )
570+ with open (project_file , 'wt' ) as f :
571+ f .write (
572+ """<?xml version="1.0" encoding="UTF-8"?>
573+ <project>
574+ <paths>
575+ <dir name="{}"/>
576+ </paths>
577+ <ignore>
578+ <path name="test.cpp"/>
579+ </ignore>
580+ </project>""" .format (test_file ))
581+
582+ args = ['--project={}' .format (project_file )]
583+ out_lines = [
584+ 'cppcheck: error: could not find or open any of the paths given.' ,
585+ 'cppcheck: Maybe all paths were ignored?'
586+ ]
587+
588+ assert_cppcheck (args , ec_exp = 1 , err_exp = [], out_exp = out_lines )
589+
590+
591+ @pytest .mark .xfail
592+ def test_json_file_ignore (tmpdir ):
593+ test_file = os .path .join (tmpdir , 'test.cpp' )
594+ with open (test_file , 'wt' ) as f :
595+ pass
596+
597+ compilation_db = [
598+ {"directory" : str (tmpdir ),
599+ "command" : "c++ -o bug1.o -c bug1.cpp" ,
600+ "file" : "test.cpp" ,
601+ "output" : "test.o" }
602+ ]
603+
604+ project_file = os .path .join (tmpdir , 'test.json' )
605+ with open (project_file , 'wt' ) as f :
606+ f .write (json .dumps (compilation_db ))
607+
608+ args = ['-itest.cpp' , '--project={}' .format (project_file )]
609+ out_lines = [
610+ 'cppcheck: error: no C or C++ source files found.' ,
611+ 'cppcheck: all paths were ignored'
612+ ]
613+
614+ assert_cppcheck (args , ec_exp = 1 , err_exp = [], out_exp = out_lines )
615+
616+
617+ def test_json_file_ignore_2 (tmpdir ):
618+ test_file = os .path .join (tmpdir , 'test.cpp' )
619+ with open (test_file , 'wt' ) as f :
620+ pass
621+
622+ compilation_db = [
623+ {"directory" : str (tmpdir ),
624+ "command" : "c++ -o bug1.o -c bug1.cpp" ,
625+ "file" : "test.cpp" ,
626+ "output" : "test.o" }
627+ ]
628+
629+ project_file = os .path .join (tmpdir , 'test.json' )
630+ with open (project_file , 'wt' ) as f :
631+ f .write (json .dumps (compilation_db ))
632+
633+ args = ['-i{}' .format (test_file ), '--project={}' .format (project_file )]
634+ out_lines = [
635+ 'cppcheck: error: no C or C++ source files found.' ,
636+ 'cppcheck: all paths were ignored'
637+ ]
638+
534639 assert_cppcheck (args , ec_exp = 1 , err_exp = [], out_exp = out_lines )
0 commit comments