@@ -4427,3 +4427,133 @@ def test_inline_block_suppr_builddir_twice(tmp_path):
44274427 assert exitcode == 0
44284428 assert stdout == ''
44294429 assert stderr == ''
4430+
4431+
4432+ def test_dui_include (tmp_path ):
4433+ test_file = tmp_path / 'test.c'
4434+ with open (test_file , "w" ) as f :
4435+ f .write ('void f() {}' )
4436+
4437+ inc_file = tmp_path / 'inc.h'
4438+ with open (inc_file , "w" ) as f :
4439+ f .write (
4440+ """
4441+ void f_i()
4442+ {
4443+ (void)(*((int*)0));
4444+ }
4445+ """ )
4446+
4447+ args = [
4448+ '-q' ,
4449+ '--template=simple' ,
4450+ f'--include={ inc_file } ' ,
4451+ str (test_file )
4452+ ]
4453+
4454+ exitcode , stdout , stderr = cppcheck (args )
4455+ assert exitcode == 0
4456+ assert stdout == ''
4457+ assert stderr .splitlines () == [
4458+ f'{ inc_file } :4:14: error: Null pointer dereference: (int*)0 [nullPointer]'
4459+ ]
4460+
4461+
4462+ def test_dui_include_missing (tmp_path ): # #14675
4463+ test_file = tmp_path / 'test.c'
4464+ with open (test_file , "w" ) as f :
4465+ f .write ('void f() {}' )
4466+
4467+ args = [
4468+ '-q' ,
4469+ '--template=simple' ,
4470+ '--include=missing.h' ,
4471+ str (test_file )
4472+ ]
4473+
4474+ exitcode , stdout , stderr = cppcheck (args )
4475+ assert exitcode == 0
4476+ assert stdout == ''
4477+ assert stderr .splitlines () == [
4478+ f"{ test_file } :0:0: error: Can not open include file 'missing.h' that is explicitly included. [missingIncludeExplicit]"
4479+ ]
4480+
4481+
4482+ def test_dui_include_relative (tmp_path ):
4483+ test_file = tmp_path / 'test.c'
4484+ with open (test_file , "w" ) as f :
4485+ f .write ('void f() {}' )
4486+
4487+ inc_file = tmp_path / 'inc.h'
4488+ with open (inc_file , "w" ) as f :
4489+ f .write (
4490+ """
4491+ void f_i()
4492+ {
4493+ (void)(*((int*)0));
4494+ }
4495+ """ )
4496+
4497+ args = [
4498+ '-q' ,
4499+ '--template=simple' ,
4500+ '--include=inc.h' ,
4501+ str (test_file )
4502+ ]
4503+
4504+ exitcode , stdout , stderr = cppcheck (args , cwd = tmp_path )
4505+ assert exitcode == 0
4506+ assert stdout == ''
4507+ assert stderr .splitlines () == [
4508+ 'inc.h:4:14: error: Null pointer dereference: (int*)0 [nullPointer]'
4509+ ]
4510+
4511+
4512+ def test_dui_include_relative_missing (tmp_path ):
4513+ test_file = tmp_path / 'test.c'
4514+ with open (test_file , "w" ) as f :
4515+ f .write ('void f() {}' )
4516+
4517+ inc_file = tmp_path / 'inc.h'
4518+ with open (inc_file , "w" ) as f :
4519+ f .write (
4520+ """
4521+ void f_i()
4522+ {
4523+ (void)(*((int*)0));
4524+ }
4525+ """ )
4526+
4527+ args = [
4528+ '-q' ,
4529+ '--template=simple' ,
4530+ '--include=inc.h' ,
4531+ str (test_file )
4532+ ]
4533+
4534+ exitcode , stdout , stderr = cppcheck (args ,)
4535+ assert exitcode == 0
4536+ assert stdout == ''
4537+ assert stderr .splitlines () == [
4538+ f"{ test_file } :0:0: error: Can not open include file 'inc.h' that is explicitly included. [missingIncludeExplicit]"
4539+ ]
4540+
4541+
4542+ def test_dui_include_absolute_missing (tmp_path ): # #14675
4543+ test_file = tmp_path / 'test.c'
4544+ with open (test_file , "w" ) as f :
4545+ f .write ('void f() {}' )
4546+
4547+ args = [
4548+ '-q' ,
4549+ '--template=simple' ,
4550+ '--include=/share/include/missing.h' ,
4551+ str (test_file )
4552+ ]
4553+
4554+ exitcode , stdout , stderr = cppcheck (args )
4555+ assert exitcode == 0
4556+ assert stdout == ''
4557+ assert stderr .splitlines () == [
4558+ f"{ test_file } :0:0: error: Can not open include file '/share/include/missing.h' that is explicitly included. [missingIncludeExplicit]"
4559+ ]
0 commit comments