@@ -372,6 +372,134 @@ def test_project_file_filter_3(tmpdir):
372372 assert_cppcheck (args , ec_exp = 0 , err_exp = [], out_exp = out_lines )
373373
374374
375+ def test_project_relpath_file_filter_abspath (tmpdir ):
376+ """
377+ relative paths in project file, absolute path in file filter
378+ """
379+ test_file_cpp = os .path .join (tmpdir , 'test.cpp' )
380+ with open (test_file_cpp , 'wt' ) as f :
381+ pass
382+ test_file_c = os .path .join (tmpdir , 'test.c' )
383+ with open (test_file_c , 'wt' ) as f :
384+ pass
385+
386+ project_file = os .path .join (tmpdir , 'test.cppcheck' )
387+ with open (project_file , 'wt' ) as f :
388+ f .write (
389+ """<?xml version="1.0" encoding="UTF-8"?>
390+ <project>
391+ <paths>
392+ <dir name="test.cpp"/>
393+ <dir name="test.c"/>
394+ </paths>
395+ </project>""" )
396+
397+ out_lines = [
398+ 'Checking test.c ...'
399+ ]
400+
401+ args = ['--file-filter={}' .format (test_file_c ), '--project=test.cppcheck' ]
402+ assert_cppcheck (args , ec_exp = 0 , err_exp = [], out_exp = out_lines , cwd = tmpdir )
403+
404+
405+ def test_project_abspath_file_filter_relpath (tmpdir ):
406+ """
407+ absolute paths in project file, relative path in file filter
408+ """
409+ test_file_cpp = os .path .join (tmpdir , 'test.cpp' )
410+ with open (test_file_cpp , 'wt' ) as f :
411+ pass
412+ test_file_c = os .path .join (tmpdir , 'test.c' )
413+ with open (test_file_c , 'wt' ) as f :
414+ pass
415+
416+ project_file = os .path .join (tmpdir , 'test.cppcheck' )
417+ with open (project_file , 'wt' ) as f :
418+ f .write (
419+ """<?xml version="1.0" encoding="UTF-8"?>
420+ <project>
421+ <paths>
422+ <dir name="{}"/>
423+ <dir name="{}"/>
424+ </paths>
425+ </project>""" .format (test_file_c , test_file_cpp ))
426+
427+ out_lines = [
428+ 'Checking {} ...' .format (test_file_c )
429+ ]
430+
431+ args = ['--file-filter=test.c' , '--project=test.cppcheck' ]
432+ assert_cppcheck (args , ec_exp = 0 , err_exp = [], out_exp = out_lines , cwd = tmpdir )
433+
434+
435+ def test_project_pathmatch_other_cwd (tmpdir ):
436+ """
437+ mixed relative and absolute paths in project file and on command line, executed in a different directory
438+ """
439+ test_root = tmpdir
440+ test_cwd = os .path .join (test_root , 'cwd' )
441+ test_dir_1 = os .path .join (test_root , 'a' )
442+ test_dir_2 = os .path .join (test_root , 'b' )
443+ test_dir_3 = os .path .join (test_cwd , 'b' )
444+
445+ os .mkdir (test_cwd )
446+ os .mkdir (test_dir_1 )
447+ os .mkdir (test_dir_2 )
448+ os .mkdir (test_dir_3 )
449+
450+ test_file_1 = os .path .join (test_dir_1 , 'a-abs.c' )
451+ with open (test_file_1 , 'wt' ) as f :
452+ pass
453+
454+ test_file_2 = os .path .join (test_dir_1 , 'a-rel.c' )
455+ with open (test_file_2 , 'wt' ) as f :
456+ pass
457+
458+ test_file_3 = os .path .join (test_dir_2 , 'b-abs.c' )
459+ with open (test_file_3 , 'wt' ) as f :
460+ pass
461+
462+ test_file_4 = os .path .join (test_dir_2 , 'b-rel.c' )
463+ with open (test_file_4 , 'wt' ) as f :
464+ pass
465+
466+ test_file_5 = os .path .join (test_dir_3 , 'b-abs.c' )
467+ with open (test_file_5 , 'wt' ) as f :
468+ pass
469+
470+ test_file_6 = os .path .join (test_dir_3 , 'b-rel.c' )
471+ with open (test_file_6 , 'wt' ) as f :
472+ pass
473+
474+ project_file = os .path .join (test_root , 'test.cppcheck' )
475+ with open (project_file , 'wt' ) as f :
476+ f .write (
477+ """<?xml version="1.0" encoding="UTF-8"?>
478+ <project>
479+ <exclude>
480+ <path name="./?/"/>
481+ </exclude>
482+ <paths>
483+ <dir name="{}"/>
484+ <dir name="a/a-rel.c"/>
485+ <dir name="{}"/>
486+ <dir name="b/b-rel.c"/>
487+ <dir name="{}"/>
488+ <dir name="cwd/b/b-rel.c"/>
489+ </paths>
490+ </project>""" .format (test_file_1 , test_file_3 , test_file_5 ))
491+
492+ out_lines = [
493+ 'Checking {} ...' .format (test_file_5 ),
494+ '1/2 files checked 0% done' ,
495+ 'Checking ../cwd/b/b-rel.c ...' ,
496+ '2/2 files checked 0% done'
497+ ]
498+
499+ args = ['--file-filter={}/*/?/**.c*' .format (test_root ), '--project=../test.cppcheck' ]
500+ assert_cppcheck (args , ec_exp = 0 , err_exp = [], out_exp = out_lines , cwd = test_cwd )
501+
502+
375503def test_project_file_filter_no_match (tmpdir ):
376504 test_file = os .path .join (tmpdir , 'test.cpp' )
377505 with open (test_file , 'wt' ) as f :
0 commit comments