Skip to content

Commit 608336f

Browse files
committed
CheckersReport: added workaround for "always active" checkers with UNUSEDFUNCTION_ONLY hack
1 parent 197df0d commit 608336f

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

lib/checkersreport.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ void CheckersReport::countCheckers()
143143
++mAllCheckersCount;
144144
}
145145
if (mSettings.premiumArgs.find("misra-c-") != std::string::npos || mSettings.addons.count("misra")) {
146+
const bool doUnusedFunctionOnly = Settings::unusedFunctionOnly();
146147
for (const checkers::MisraInfo& info: checkers::misraC2012Rules) {
147148
const std::string rule = std::to_string(info.a) + "." + std::to_string(info.b);
148-
const bool active = isMisraRuleActive(mActiveCheckers, rule);
149+
// this will return some rules as always active even if they are not in the active checkers.
150+
// this leads to a difference in the shown count and in the checkers stored in the builddir
151+
// TODO: fix this?
152+
const bool active = !doUnusedFunctionOnly && isMisraRuleActive(mActiveCheckers, rule);
149153
if (active)
150154
++mActiveCheckersCount;
151155
++mAllCheckersCount;

test/cli/other_test.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4045,14 +4045,11 @@ def test_active_unusedfunction_only_builddir(tmp_path):
40454045

40464046

40474047
def test_active_unusedfunction_only_misra(tmp_path):
4048-
# TODO: should only report a single active check
4049-
__test_active_checkers(tmp_path, 7, 1166, use_unusedfunction_only=True, use_misra=True)
4048+
__test_active_checkers(tmp_path, 1, 1166, use_unusedfunction_only=True, use_misra=True)
40504049

40514050

4052-
@pytest.mark.xfail(strict=True) # TODO: active count and checkers.txt differ
40534051
def test_active_unusedfunction_only_misra_builddir(tmp_path):
4054-
# TODO: should only report a single active check
40554052
checkers_exp = [
40564053
'CheckUnusedFunctions::check'
40574054
]
4058-
__test_active_checkers(tmp_path, 7, 1166, use_unusedfunction_only=True, use_misra=True, checkers_exp=checkers_exp)
4055+
__test_active_checkers(tmp_path, 1, 1166, use_unusedfunction_only=True, use_misra=True, checkers_exp=checkers_exp)

0 commit comments

Comments
 (0)