@@ -3847,3 +3847,100 @@ 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: should report another ID
3891+ '{}:2:5: error: The code contains unhandled character(s) (character code=228). Neither unicode nor extended ascii is supported. [syntaxError]' .format (test_file )
3892+ ]
3893+
3894+
3895+ def test_simplecpp_include_nested_too_deeply (tmp_path ):
3896+ test_file = tmp_path / 'test.c'
3897+ with open (test_file , "w" ) as f :
3898+ f .write ('#include "test.h"' )
3899+
3900+ test_h = tmp_path / 'test.h'
3901+ with open (test_h , "w" ) as f :
3902+ f .write ('#include "test_0.h"' )
3903+
3904+ for i in range (400 ):
3905+ test_h = tmp_path / f'test_{ i } .h'
3906+ with open (test_h , "w" ) as f :
3907+ f .write ('#include "test_{}.h"' .format (i + 1 ))
3908+
3909+ args = [
3910+ '-q' ,
3911+ '--template=simple' ,
3912+ str (test_file )
3913+ ]
3914+
3915+ exitcode , stdout , stderr = cppcheck (args )
3916+ assert exitcode == 0 , stdout
3917+ assert stdout .splitlines () == []
3918+ test_h = tmp_path / 'test_398.h'
3919+ assert stderr .splitlines () == [
3920+ # TODO: should only report the error once
3921+ # TODO: should report another ID
3922+ '{}:1:0: error: #include nested too deeply [preprocessorErrorDirective]' .format (test_h ),
3923+ '{}:1:2: error: #include nested too deeply [preprocessorErrorDirective]' .format (test_h )
3924+ ]
3925+
3926+
3927+ def test_simplecpp_syntax_error (tmp_path ):
3928+ test_file = tmp_path / 'test.c'
3929+ with open (test_file , "w" ) as f :
3930+ f .write ('#include ""' )
3931+
3932+ args = [
3933+ '-q' ,
3934+ '--template=simple' ,
3935+ str (test_file )
3936+ ]
3937+
3938+ exitcode , stdout , stderr = cppcheck (args )
3939+ assert exitcode == 0 , stdout
3940+ assert stdout .splitlines () == []
3941+ assert stderr .splitlines () == [
3942+ # TODO: should only report the error once
3943+ # TODO: should report another ID
3944+ '{}:1:0: error: No header in #include [preprocessorErrorDirective]' .format (test_file ),
3945+ '{}:1:2: error: No header in #include [preprocessorErrorDirective]' .format (test_file )
3946+ ]
0 commit comments