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