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

Function __test_showtime

test/cli/other_test.py:966–1020  ·  view source on GitHub ↗
(tmp_path, showtime, exp_res, exp_last, use_compdb=False, use_addons=False, use_clang_tidy=False, extra_args=None)

Source from the content-addressed store, hash-verified

964
965# TODO: test with multiple files
966def __test_showtime(tmp_path, showtime, exp_res, exp_last, use_compdb=False, use_addons=False, use_clang_tidy=False, extra_args=None):
967 test_file = tmp_path / 'test.cpp' # the use of C++ is intentional
968 with open(test_file, 'wt') as f:
969 f.write(
970"""
971void f()
972{
973 (void)(*((int*)0)); // cppcheck-suppress nullPointer
974}
975""")
976
977 args = [
978 f'--showtime={showtime}',
979 '--quiet',
980 '--inline-suppr'
981 ]
982
983 if use_addons:
984 args += ['--addon=misra', '--addon=misc']
985
986 if use_clang_tidy:
987 args += ['--clang-tidy']
988 args += ['--suppress=clang-tidy-misc-use-internal-linkage']
989 args += ['--suppress=clang-tidy-google-readability-casting']
990 args += ['--suppress=clang-tidy-modernize-avoid-c-style-cast']
991 args += ['--suppress=clang-tidy-hicpp-use-nullptr']
992 args += ['--suppress=clang-tidy-modernize-use-nullptr']
993
994 if use_compdb:
995 compdb_file = tmp_path / 'compile_commands.json'
996 create_compile_commands(compdb_file, [test_file])
997
998 args.append(f'--project={compdb_file}')
999 else:
1000 args.append(str(test_file))
1001
1002 if extra_args:
1003 args += extra_args
1004
1005 exitcode, stdout, stderr = cppcheck(args)
1006 assert exitcode == 0
1007 lines = stdout.splitlines()
1008 exp_len = exp_res
1009 if 'cppcheck internal API usage' in stdout:
1010 exp_len += 1
1011 if use_addons:
1012 exp_len += 1 # TODO: should have individual entries for each addon and whole program analysis
1013 # TODO: add entry for clang-tidy analysis
1014 exp_len += 1 # last line
1015 assert len(lines) == exp_len
1016 for i in range(1, exp_res):
1017 assert 'avg.' in lines[i]
1018 assert lines[exp_len-1].startswith(exp_last)
1019 assert not 'avg.' in lines[exp_len-1]
1020 assert stderr == ''
1021
1022
1023def __test_showtime_top5_file(tmp_path, use_compdb=False):

Callers 5

__test_showtime_fileFunction · 0.85
__test_showtime_summaryFunction · 0.85

Calls 4

create_compile_commandsFunction · 0.90
cppcheckFunction · 0.90
strFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected