Skip to content

Commit 3ed8273

Browse files
dmcppcheckclaude
andcommitted
metrics_test: make test_duplicate_metrics work with injected build dir and clang
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3f4b73e commit 3ed8273

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎test/cli/metrics_test.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,27 @@ def test_duplicate_metrics(tmpdir):
8484
file.write('''
8585
import sys
8686
dumpfile = sys.argv[-1]
87-
value = 5 if 'c.c' in dumpfile else 3
87+
with open(dumpfile, 'rt') as f:
88+
value = 5 if 'str="c"' in f.read() else 3
8889
print('{"metric":{"fileName":"util.h","function":"clamp","id":"HISCalling","lineNumber":2,"value":1}}')
8990
print('{"metric":{"fileName":"util.h","function":"clamp","id":"HISStmt","lineNumber":2,"value":%d}}' % value)
9091
print('{"metric":{"fileName":"util.h","id":"HISStmtFile","value":3}}')
9192
''')
9293
source_files = []
9394
for name in ('a.c', 'b.c', 'c.c'):
9495
path = os.path.join(tmpdir, name)
95-
with open(path, 'w') as _:
96-
pass
96+
with open(path, 'w') as f:
97+
f.write(f'int {name[0]};\n')
9798
source_files.append(path)
9899

99100
args = [f'--addon={addon_path}', '--xml-version=3'] + source_files
100101
ret, _, stderr = cppcheck(args)
101102
assert ret == 0
102103

103104
metrics = [line.strip() for line in stderr.splitlines() if line.strip().startswith('<metric ')]
104-
assert metrics == [
105+
assert sorted(metrics) == sorted([
105106
'<metric fileName="util.h" function="clamp" id="HISCalling" lineNumber="2" value="3"/>',
106107
'<metric fileName="util.h" function="clamp" id="HISStmt" lineNumber="2" value="3"/>',
107108
'<metric fileName="util.h" id="HISStmtFile" value="3"/>',
108109
'<metric fileName="util.h" function="clamp" id="HISStmt" lineNumber="2" value="5"/>'
109-
]
110+
])

0 commit comments

Comments
 (0)