Skip to content

Commit 29a266f

Browse files
committed
refs #14599 - test/cli/other_test.py: improved --showtime tests
1 parent 7d80f64 commit 29a266f

1 file changed

Lines changed: 73 additions & 19 deletions

File tree

test/cli/other_test.py

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -954,33 +954,87 @@ def test_unused_function_include(tmpdir):
954954
__test_unused_function_include(tmpdir, [])
955955

956956

957-
# TODO: test with all other types
958-
def test_showtime_top5_file(tmpdir):
959-
test_file = os.path.join(tmpdir, 'test.cpp')
957+
# TODO: test with multiple files
958+
def __test_showtime(tmp_path, showtime, exp_len, exp_last, extra_args=None):
959+
test_file = tmp_path / 'test.cpp'
960960
with open(test_file, 'wt') as f:
961-
f.write("""
962-
int main(int argc)
963-
{
964-
}
965-
""")
961+
f.write(
962+
"""
963+
void f()
964+
{
965+
(void)(*((int*)0)); // cppcheck-suppress nullPointer
966+
}
967+
""")
968+
969+
args = [
970+
f'--showtime={showtime}',
971+
'--quiet',
972+
'--inline-suppr',
973+
str(test_file)
974+
]
966975

967-
args = ['--showtime=top5_file', '--quiet', test_file]
976+
if extra_args:
977+
args += extra_args
968978

969979
exitcode, stdout, stderr = cppcheck(args)
970-
assert exitcode == 0 # TODO: needs to be 1
980+
assert exitcode == 0
971981
lines = stdout.splitlines()
972-
assert len(lines) == 7
973-
assert lines[0] == ''
974-
for i in range(1, 5):
975-
if lines[i].startswith('valueFlowLifetime'):
976-
assert lines[i].endswith(' - 2 result(s))')
977-
elif lines[i].startswith('valueFlowEnumValue'):
978-
assert lines[i].endswith(' - 2 result(s))')
979-
else:
980-
assert lines[i].endswith(' result(s))')
982+
assert len(lines) == exp_len
983+
idx_last = exp_len-1
984+
if idx_last:
985+
assert lines[0] == ''
986+
for i in range(1, idx_last):
987+
assert 'avg.' in lines[i]
988+
assert lines[idx_last].startswith(exp_last)
981989
assert stderr == ''
982990

983991

992+
def test_showtime_top5_file(tmp_path):
993+
__test_showtime(tmp_path, 'top5_file', 7, 'Check time: ')
994+
995+
996+
# TODO: remove extra args when --executor=process works works
997+
def test_showtime_top5_summary(tmp_path):
998+
__test_showtime(tmp_path, 'top5_summary', 7, 'Overall time: ', ['-j1'])
999+
1000+
1001+
# TODO: remove when --executor=process works works
1002+
def test_showtime_top5_summary_j_thread(tmp_path):
1003+
__test_showtime(tmp_path, 'top5_summary', 7, 'Overall time: ', ['-j2', '--executor=thread'])
1004+
1005+
1006+
# TODO: remove override when fixed
1007+
@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
1008+
@pytest.mark.xfail(strict=True) # TODO: need to transfer the timer results to parent process - see #4452
1009+
def test_showtime_top5_summary_j_process(tmp_path):
1010+
__test_showtime(tmp_path, 'top5_summary', 7, 'Overall time: ', ['-j2', '--executor=process'])
1011+
1012+
1013+
def test_showtime_file(tmp_path):
1014+
__test_showtime(tmp_path, 'file', 79, 'Check time: ')
1015+
1016+
1017+
# TODO: remove extra args when --executor=process works works
1018+
def test_showtime_summary(tmp_path):
1019+
__test_showtime(tmp_path, 'summary', 79, 'Overall time: ', ['-j1'])
1020+
1021+
1022+
# TODO: remove when --executor=process works works
1023+
def test_showtime_summary_j_thread(tmp_path):
1024+
__test_showtime(tmp_path, 'summary', 79, 'Overall time: ', ['-j2', '--executor=thread'])
1025+
1026+
1027+
# TODO: remove override when fixed
1028+
@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
1029+
@pytest.mark.xfail(strict=True) # TODO: need to transfer the timer results to parent process - see #4452
1030+
def test_showtime_summary_j_process(tmp_path):
1031+
__test_showtime(tmp_path, 'summary', 79, 'Overall time: ', ['-j2', '--executor=process'])
1032+
1033+
1034+
def test_showtime_file_total(tmp_path):
1035+
__test_showtime(tmp_path, 'file-total', 1, 'Check time: ')
1036+
1037+
9841038
def test_missing_addon(tmpdir):
9851039
args = ['--addon=misra3', '--addon=misra', '--addon=misra2', 'file.c']
9861040

0 commit comments

Comments
 (0)