@@ -3847,3 +3847,101 @@ def test_unmatched_file(tmp_path): # #14248 / #14249
38473847 f'{ lib_file } :-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]'
38483848 ]
38493849 assert ret == 0 , stdout
3850+
3851+
3852+ def test_simplecpp_warning (tmp_path ):
3853+ test_file = tmp_path / 'test.c'
3854+ with open (test_file , "w" ) as f :
3855+ f .write (
3856+ """
3857+ #define warning "warn msg"
3858+ """ )
3859+
3860+ args = [
3861+ '-q' ,
3862+ '--template=simple' ,
3863+ str (test_file )
3864+ ]
3865+
3866+ exitcode , stdout , stderr = cppcheck (args )
3867+ assert exitcode == 0 , stdout
3868+ assert stdout .splitlines () == []
3869+ assert stderr .splitlines () == []
3870+
3871+
3872+ def test_simplecpp_unhandled_char (tmp_path ):
3873+ test_file = tmp_path / 'test.c'
3874+ with open (test_file , "w" ) as f :
3875+ f .write (
3876+ """
3877+ int 你=0;
3878+ """ )
3879+
3880+ args = [
3881+ '-q' ,
3882+ '--template=simple' ,
3883+ str (test_file )
3884+ ]
3885+
3886+ exitcode , stdout , stderr = cppcheck (args )
3887+ assert exitcode == 0 , stdout
3888+ assert stdout .splitlines () == []
3889+ assert stderr .splitlines () == [
3890+ # TODO: lacks column information
3891+ # TODO: should report another ID
3892+ '{}:2:0: error: The code contains unhandled character(s) (character code=228). Neither unicode nor extended ascii is supported. [preprocessorErrorDirective]' .format (test_file )
3893+ ]
3894+
3895+
3896+ def test_simplecpp_include_nested_too_deeply (tmp_path ):
3897+ test_file = tmp_path / 'test.c'
3898+ with open (test_file , "w" ) as f :
3899+ f .write ('#include "test.h"' )
3900+
3901+ test_h = tmp_path / 'test.h'
3902+ with open (test_h , "w" ) as f :
3903+ f .write ('#include "test_0.h"' )
3904+
3905+ for i in range (400 ):
3906+ test_h = tmp_path / f'test_{ i } .h'
3907+ with open (test_h , "w" ) as f :
3908+ f .write ('#include "test_{}.h"' .format (i + 1 ))
3909+
3910+ args = [
3911+ '-q' ,
3912+ '--template=simple' ,
3913+ str (test_file )
3914+ ]
3915+
3916+ exitcode , stdout , stderr = cppcheck (args )
3917+ assert exitcode == 0 , stdout
3918+ assert stdout .splitlines () == []
3919+ test_h = tmp_path / 'test_398.h'
3920+ assert stderr .splitlines () == [
3921+ # TODO: should only report the error once
3922+ # TODO: should report another ID
3923+ '{}:1:0: error: #include nested too deeply [preprocessorErrorDirective]' .format (test_h ),
3924+ '{}:1:2: error: #include nested too deeply [preprocessorErrorDirective]' .format (test_h )
3925+ ]
3926+
3927+
3928+ def test_simplecpp_syntax_error (tmp_path ):
3929+ test_file = tmp_path / 'test.c'
3930+ with open (test_file , "w" ) as f :
3931+ f .write ('#include ""' )
3932+
3933+ args = [
3934+ '-q' ,
3935+ '--template=simple' ,
3936+ str (test_file )
3937+ ]
3938+
3939+ exitcode , stdout , stderr = cppcheck (args )
3940+ assert exitcode == 0 , stdout
3941+ assert stdout .splitlines () == []
3942+ assert stderr .splitlines () == [
3943+ # TODO: should only report the error once
3944+ # TODO: should report another ID
3945+ '{}:1:0: error: No header in #include [preprocessorErrorDirective]' .format (test_file ),
3946+ '{}:1:2: error: No header in #include [preprocessorErrorDirective]' .format (test_file )
3947+ ]
0 commit comments