@@ -3064,4 +3064,102 @@ def test_file_ignore_2(tmp_path): # #13570
30643064 'cppcheck: error: could not find or open any of the paths given.' ,
30653065 'cppcheck: Maybe all paths were ignored?'
30663066 ]
3067- assert stderr .splitlines () == []
3067+ assert stderr .splitlines () == []
3068+
3069+
3070+ def test_debug_valueflow (tmp_path ):
3071+ test_file = tmp_path / 'test.c'
3072+ with open (test_file , "w" ) as f :
3073+ f .write (
3074+ """int f()
3075+ {
3076+ double d = 1.0 / 0.5;
3077+ return d;
3078+ }
3079+ """ )
3080+
3081+ args = [
3082+ '-q' ,
3083+ '--debug' , # TODO: limit to valueflow output
3084+ str (test_file )
3085+ ]
3086+
3087+ exitcode , stdout , stderr = cppcheck (args )
3088+ assert exitcode == 0 , stdout
3089+
3090+ # check sections in output
3091+ assert stdout .find ('##file ' ) != - 1
3092+ assert stdout .find ('##Value flow' ) != - 1
3093+ assert stdout .find ('### Symbol database ###' ) == - 1
3094+ assert stdout .find ('##AST' ) == - 1
3095+ assert stdout .find ('### Template Simplifier pass ' ) == - 1
3096+ assert stderr .splitlines () == []
3097+
3098+ # check precision in output - #13607
3099+ valueflow = stdout [stdout .find ('##Value flow' ):]
3100+ assert valueflow .splitlines () == [
3101+ '##Value flow' ,
3102+ 'File {}' .format (str (test_file ).replace ('\\ ' , '/' )),
3103+ 'Line 3' ,
3104+ ' = always 2.0' ,
3105+ ' 1.0 always 1.0' ,
3106+ ' / always 2.0' ,
3107+ ' 0.5 always 0.5' ,
3108+ 'Line 4' ,
3109+ ' d always {symbolic=(1.0/0.5),2.0}'
3110+ ]
3111+
3112+
3113+ def test_debug_valueflow_xml (tmp_path ): # #13606
3114+ test_file = tmp_path / 'test.c'
3115+ with open (test_file , "w" ) as f :
3116+ f .write (
3117+ """double f()
3118+ {
3119+ double d = 0.0000001;
3120+ return d;
3121+ }
3122+ """ )
3123+
3124+ args = [
3125+ '-q' ,
3126+ '--debug' , # TODO: limit to valueflow output
3127+ '--xml' ,
3128+ str (test_file )
3129+ ]
3130+
3131+ exitcode , stdout , stderr = cppcheck (args )
3132+ assert exitcode == 0 , stdout
3133+
3134+ assert stderr
3135+ assert ElementTree .fromstring (stderr ) is not None
3136+
3137+ # check sections in output
3138+ assert stdout .find ('##file ' ) != - 1 # also exists in CDATA
3139+ assert stdout .find ('##Value flow' ) == - 1
3140+ assert stdout .find ('### Symbol database ###' ) == - 1
3141+ assert stdout .find ('##AST' ) == - 1
3142+ assert stdout .find ('### Template Simplifier pass ' ) == - 1
3143+
3144+ # check XML nodes in output
3145+ debug_xml = ElementTree .fromstring (stdout )
3146+ assert debug_xml is not None
3147+ assert debug_xml .tag == 'debug'
3148+ file_elem = debug_xml .findall ('file' )
3149+ assert len (file_elem ) == 1
3150+ valueflow_elem = debug_xml .findall ('valueflow' )
3151+ assert len (valueflow_elem ) == 1
3152+ scopes_elem = debug_xml .findall ('scopes' )
3153+ assert len (scopes_elem ) == 1
3154+ ast_elem = debug_xml .findall ('ast' )
3155+ assert len (ast_elem ) == 0
3156+
3157+ # check precision in output - #13606
3158+ value_elem = valueflow_elem [0 ].findall ('values/value' )
3159+ assert len (value_elem ) == 3
3160+ assert 'floatvalue' in value_elem [0 ].attrib
3161+ assert value_elem [0 ].attrib ['floatvalue' ] == '1e-07'
3162+ assert 'floatvalue' in value_elem [1 ].attrib
3163+ assert value_elem [1 ].attrib ['floatvalue' ] == '1e-07'
3164+ assert 'floatvalue' in value_elem [2 ].attrib
3165+ assert value_elem [2 ].attrib ['floatvalue' ] == '1e-07'
0 commit comments