@@ -3847,3 +3847,105 @@ 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" , encoding = 'utf-8' ) as f :
3875+ f .write (
3876+ """
3877+ int 你=0;
3878+ """ )
3879+
3880+ args = [
3881+ '-q' ,
3882+ '--template=simple' ,
3883+ '--emit-duplicates' ,
3884+ str (test_file )
3885+ ]
3886+
3887+ exitcode , stdout , stderr = cppcheck (args )
3888+ assert exitcode == 0 , stdout
3889+ assert stdout .splitlines () == []
3890+ assert stderr .splitlines () == [
3891+ # TODO: should report another ID
3892+ '{}:2:5: error: The code contains unhandled character(s) (character code=228). Neither unicode nor extended ascii is supported. [syntaxError]' .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+ '--emit-duplicates' ,
3914+ str (test_file )
3915+ ]
3916+
3917+ exitcode , stdout , stderr = cppcheck (args )
3918+ assert exitcode == 0 , stdout
3919+ assert stdout .splitlines () == []
3920+ test_h = tmp_path / 'test_398.h'
3921+ assert stderr .splitlines () == [
3922+ # TODO: should only report the error once
3923+ # TODO: should report another ID
3924+ # TODO: lacks column information
3925+ '{}:1:0: error: #include nested too deeply [preprocessorErrorDirective]' .format (test_h ),
3926+ '{}:1:2: error: #include nested too deeply [preprocessorErrorDirective]' .format (test_h )
3927+ ]
3928+
3929+
3930+ def test_simplecpp_syntax_error (tmp_path ):
3931+ test_file = tmp_path / 'test.c'
3932+ with open (test_file , "w" ) as f :
3933+ f .write ('#include ""' )
3934+
3935+ args = [
3936+ '-q' ,
3937+ '--template=simple' ,
3938+ '--emit-duplicates' ,
3939+ str (test_file )
3940+ ]
3941+
3942+ exitcode , stdout , stderr = cppcheck (args )
3943+ assert exitcode == 0 , stdout
3944+ assert stdout .splitlines () == []
3945+ assert stderr .splitlines () == [
3946+ # TODO: should only report the error once
3947+ # TODO: should report another ID
3948+ # TODO: lacks column information
3949+ '{}:1:0: error: No header in #include [preprocessorErrorDirective]' .format (test_file ),
3950+ '{}:1:2: error: No header in #include [preprocessorErrorDirective]' .format (test_file )
3951+ ]
0 commit comments