Skip to content

Commit

Permalink
Fix #13299: misra.py: use language attribute instead of file extensio…
Browse files Browse the repository at this point in the history
…n to determine language (danmar#7075)
  • Loading branch information
swasti16 authored Dec 6, 2024
1 parent 57d4d61 commit 0dfb670
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions addons/cppcheckdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,7 @@ def __init__(self, filename):
"""
:param filename: Path to Cppcheck dump file
"""
self.language = None
self.filename = filename
self.rawTokens = []
self.platform = None
Expand All @@ -1234,6 +1235,8 @@ def __init__(self, filename):
for event, node in ElementTree.iterparse(self.filename, events=('start', 'end')):
if platform_done and rawtokens_done and suppressions_done:
break
if node.tag == 'dumps':
self.language = node.get('language')
if node.tag == 'platform' and event == 'start':
self.platform = Platform(node)
platform_done = True
Expand Down
2 changes: 1 addition & 1 deletion addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -4525,7 +4525,7 @@ def fillVerifyExpected(verify_expected, tok):
else:
self.printStatus('Checking ' + dumpfile + '...')

self.is_cpp = data.files and data.files[0].endswith('.cpp')
self.is_cpp = data.language == 'cpp'

for cfgNumber, cfg in enumerate(data.iterconfigurations()):
if not self.settings.quiet:
Expand Down
13 changes: 12 additions & 1 deletion addons/test/misra_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import pytest
import re
import sys
import os

from .util import dump_create, dump_remove, convert_json_output


TEST_SOURCE_FILES = ['./addons/test/misra/misra-test.c']
TEST_SOURCE_FILES = [os.path.join('addons','test','misra','misra-test.c')]


def remove_misra_config(s:str):
Expand Down Expand Up @@ -169,3 +170,13 @@ def test_read_ctu_info_line(checker):
assert checker.read_ctu_info_line('{"summary":"123"}') is None
assert checker.read_ctu_info_line('{"data":123}') is None
assert checker.read_ctu_info_line('{"summary":"123","data":123}') is not None

def test_platform(checker):
test_file = os.path.join('addons','test','misra','misra-test.c')
dump_create(test_file, "--language=c++")
checker.parseDump(test_file + ".dump")
assert checker.is_cpp is True

dump_create(test_file, "--language=c")
checker.parseDump(test_file + ".dump")
assert checker.is_cpp is False

0 comments on commit 0dfb670

Please sign in to comment.