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

Function test_analyzerinfo

test/cli/other_test.py:4342–4440  ·  view source on GitHub ↗
(tmp_path)

Source from the content-addressed store, hash-verified

4340
4341
4342def test_analyzerinfo(tmp_path):
4343 test_file = tmp_path / 'test.c'
4344 with open(test_file, "w") as f:
4345 f.write(
4346"""void f()
4347{
4348 (void)(*((int*)0));
4349}
4350""")
4351
4352 build_dir = tmp_path / 'b1'
4353 os.makedirs(build_dir)
4354
4355 test_a1_file = build_dir / 'test.a1'
4356
4357 args = [
4358 '-q',
4359 '--debug-analyzerinfo',
4360 '--template=simple',
4361 '--cppcheck-build-dir={}'.format(build_dir),
4362 '--enable=all',
4363 str(test_file)
4364 ]
4365
4366 stderr_exp = [
4367 '{}:3:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file),
4368 "{}:1:6: style: The function 'f' is never used. [unusedFunction]".format(test_file)
4369 ]
4370
4371 def run_and_assert_cppcheck(stdout_exp):
4372 exitcode, stdout, stderr = cppcheck(args)
4373 assert exitcode == 0, stdout
4374 assert stdout.splitlines() == stdout_exp
4375 assert stderr.splitlines() == stderr_exp
4376
4377 test_file_s = str(test_file).replace('\\', '/')
4378 test_a1_file_s = str(test_a1_file).replace('\\', '/')
4379
4380 # no cached results
4381 run_and_assert_cppcheck([
4382 "no cached result '{}' for '{}' found".format(test_a1_file_s, test_file_s)
4383 ])
4384
4385 # cached results
4386 run_and_assert_cppcheck([
4387 "skipping analysis - loaded 1 cached finding(s) from '{}' for '{}'".format(test_a1_file_s, test_file_s)
4388 ])
4389
4390 # modified file
4391 with open(test_file, 'a') as f:
4392 f.write('\n#define DEF')
4393
4394 run_and_assert_cppcheck([
4395 "discarding cached result from '{}' for '{}' - hash mismatch".format(test_a1_file_s, test_file_s)
4396 ])
4397
4398 # invalid XML
4399 with open(test_a1_file, 'a') as f:

Callers

nothing calls this directly

Calls 5

strFunction · 0.85
run_and_assert_cppcheckFunction · 0.85
formatMethod · 0.80
writeMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected