Skip to content

Commit f327920

Browse files
committed
test/cli/other_test.py: added tests for valueflow debug output
1 parent 83c9a57 commit f327920

File tree

1 file changed

+99
-1
lines changed

1 file changed

+99
-1
lines changed

Diff for: test/cli/other_test.py

+99-1
Original file line numberDiff line numberDiff line change
@@ -3035,4 +3035,102 @@ def test_debug_template(tmp_path):
30353035
assert stdout.find('### Symbol database ###') == -1
30363036
assert stdout.find('##AST') == -1
30373037
assert stdout.find('### Template Simplifier pass ') != -1
3038-
assert stderr.splitlines() == []
3038+
assert stderr.splitlines() == []
3039+
3040+
3041+
def test_debug_valueflow(tmp_path):
3042+
test_file = tmp_path / 'test.c'
3043+
with open(test_file, "w") as f:
3044+
f.write(
3045+
"""int f()
3046+
{
3047+
double d = 1.0 / 0.5;
3048+
return d;
3049+
}
3050+
""")
3051+
3052+
args = [
3053+
'-q',
3054+
'--debug', # TODO: limit to valueflow output
3055+
str(test_file)
3056+
]
3057+
3058+
exitcode, stdout, stderr = cppcheck(args)
3059+
assert exitcode == 0, stdout
3060+
3061+
# check sections in output
3062+
assert stdout.find('##file ') != -1
3063+
assert stdout.find('##Value flow') != -1
3064+
assert stdout.find('### Symbol database ###') == -1
3065+
assert stdout.find('##AST') == -1
3066+
assert stdout.find('### Template Simplifier pass ') == -1
3067+
assert stderr.splitlines() == []
3068+
3069+
# check precision in output - #13607
3070+
valueflow = stdout[stdout.find('##Value flow'):]
3071+
assert valueflow.splitlines() == [
3072+
'##Value flow',
3073+
'File {}'.format(str(test_file).replace('\\', '/')),
3074+
'Line 3',
3075+
' = always 2',
3076+
' 1.0 always 1',
3077+
' / always 2',
3078+
' 0.5 always 0.5',
3079+
'Line 4',
3080+
' d always {symbolic=(1.0/0.5),2}'
3081+
]
3082+
3083+
3084+
def test_debug_valueflow_xml(tmp_path): # #13606
3085+
test_file = tmp_path / 'test.c'
3086+
with open(test_file, "w") as f:
3087+
f.write(
3088+
"""double f()
3089+
{
3090+
double d = 0.0000001;
3091+
return d;
3092+
}
3093+
""")
3094+
3095+
args = [
3096+
'-q',
3097+
'--debug', # TODO: limit to valueflow output
3098+
'--xml',
3099+
str(test_file)
3100+
]
3101+
3102+
exitcode, stdout, stderr = cppcheck(args)
3103+
assert exitcode == 0, stdout
3104+
3105+
assert stderr
3106+
assert ElementTree.fromstring(stderr) is not None
3107+
3108+
# check sections in output
3109+
assert stdout.find('##file ') != -1 # also exists in CDATA
3110+
assert stdout.find('##Value flow') == -1
3111+
assert stdout.find('### Symbol database ###') == -1
3112+
assert stdout.find('##AST') == -1
3113+
assert stdout.find('### Template Simplifier pass ') == -1
3114+
3115+
# check XML nodes in output
3116+
debug_xml = ElementTree.fromstring(stdout)
3117+
assert debug_xml is not None
3118+
assert debug_xml.tag == 'debug'
3119+
file_elem = debug_xml.findall('file')
3120+
assert len(file_elem) == 1
3121+
valueflow_elem = debug_xml.findall('valueflow')
3122+
assert len(valueflow_elem) == 1
3123+
scopes_elem = debug_xml.findall('scopes')
3124+
assert len(scopes_elem) == 1
3125+
ast_elem = debug_xml.findall('ast')
3126+
assert len(ast_elem) == 0
3127+
3128+
# check precision in output - #13606
3129+
value_elem = valueflow_elem[0].findall('values/value')
3130+
assert len(value_elem) == 3
3131+
assert 'floatvalue' in value_elem[0].attrib
3132+
assert value_elem[0].attrib['floatvalue'] == '0.000000'
3133+
assert 'floatvalue' in value_elem[1].attrib
3134+
assert value_elem[1].attrib['floatvalue'] == '0.000000'
3135+
assert 'floatvalue' in value_elem[2].attrib
3136+
assert value_elem[2].attrib['floatvalue'] == '0.000000'

0 commit comments

Comments
 (0)