MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / __test_active_checkers

Function __test_active_checkers

test/cli/other_test.py:4275–4317  ·  view source on GitHub ↗
(tmp_path, active_cnt, total_cnt, use_misra=False, use_unusedfunction_only=False, checkers_exp=None)

Source from the content-addressed store, hash-verified

4273
4274
4275def __test_active_checkers(tmp_path, active_cnt, total_cnt, use_misra=False, use_unusedfunction_only=False, checkers_exp=None):
4276 test_file = tmp_path / 'test.c'
4277 with open(test_file, 'w') as f:
4278 f.write('int i;')
4279
4280 build_dir = None
4281 if checkers_exp is not None:
4282 build_dir = tmp_path / 'b1'
4283 os.makedirs(build_dir)
4284
4285 args = [
4286 '-q',
4287 '--enable=information',
4288 '-j1',
4289 str(test_file)
4290 ]
4291
4292 if use_misra:
4293 args += ['--addon=misra']
4294 if build_dir:
4295 args += ['--cppcheck-build-dir={}'.format(build_dir)]
4296 else:
4297 args += ['--no-cppcheck-build-dir']
4298
4299 env = {}
4300 if use_unusedfunction_only:
4301 env = {'UNUSEDFUNCTION_ONLY': '1'}
4302 args += ['--enable=unusedFunction']
4303 exitcode, stdout, stderr, _ = cppcheck_ex(args, remove_checkers_report=False, env=env)
4304 assert exitcode == 0, stdout
4305 assert stdout.splitlines() == []
4306 assert stderr.splitlines() == [
4307 f'nofile:0:0: information: Active checkers: {active_cnt}/{total_cnt} (use --checkers-report=<filename> to see details) [checkersReport]',
4308 '' # TODO: get rid of extra newline
4309 ]
4310
4311 if build_dir:
4312 checkers_file = build_dir / 'checkers.txt'
4313 with open(checkers_file, 'r') as f:
4314 checkers = f.read().splitlines()
4315
4316 assert checkers == checkers_exp
4317 assert len(checkers) == active_cnt
4318
4319
4320def test_active_unusedfunction_only(tmp_path):

Calls 5

cppcheck_exFunction · 0.90
strFunction · 0.85
formatMethod · 0.80
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected