Skip to content

Commit 91dcb46

Browse files
committed
test with -j flag
1 parent 7598d90 commit 91dcb46

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

test/cli/other_test.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4907,13 +4907,23 @@ def test_redundant_file_reads(tmpdir, flags, expected):
49074907
assert proc.returncode == 0
49084908
assert stderr.splitlines()[-1].strip() == f'{expected} total'.encode('utf-8')
49094909

4910+
test_errorlogger_sourcecache_params = [
4911+
([]),
4912+
(["-j4", "--executor=process"]),
4913+
(["-j4", "--executor=thread"]),
4914+
]
4915+
49104916
@__strace_decorator
4911-
def test_errorlogger_sourcecache(tmpdir):
4917+
@pytest.mark.parametrize('extra_flags', test_errorlogger_sourcecache_params)
4918+
def test_errorlogger_sourcecache(tmpdir, extra_flags):
49124919
header_pathname = os.path.join(tmpdir, 'header.h')
49134920
file_1_pathname = os.path.join(tmpdir, 'file_1.c')
49144921
file_2_pathname = os.path.join(tmpdir, 'file_2.c')
49154922
file_3_pathname = os.path.join(tmpdir, 'file_3.c')
49164923
output_pathname = os.path.join(tmpdir, 'out.txt')
4924+
builddir_pathname = os.path.join(tmpdir, 'builddir')
4925+
4926+
os.mkdir(builddir_pathname)
49174927

49184928
# Project setup that results in error paths
49194929
# spanning multiple files (ctuuninitvar)
@@ -4978,10 +4988,11 @@ def test_errorlogger_sourcecache(tmpdir):
49784988
'-q',
49794989
'--enable=all',
49804990
f'--output-file={output_pathname}',
4991+
f'--cppcheck-build-dir={builddir_pathname}',
49814992
file_1_pathname,
49824993
file_2_pathname,
49834994
file_3_pathname,
4984-
]
4995+
] + extra_flags
49854996

49864997
proc = subprocess.Popen(args, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
49874998
_, strace_output = proc.communicate()
@@ -5013,7 +5024,6 @@ def test_errorlogger_sourcecache(tmpdir):
50135024
{file_3_pathname}:4:5: style: The function 'func_3' is never used. [unusedFunction]
50145025
int func_3(void)
50155026
^
5016-
nofile:0:0: information: Active checkers: 114/188 (use --checkers-report=<filename> to see details) [checkersReport]
50175027
50185028
"""
50195029

@@ -5030,5 +5040,21 @@ def test_errorlogger_sourcecache(tmpdir):
50305040
with open(output_pathname, 'r') as f:
50315041
output_content = f.read()
50325042

5043+
output_content = output_content.split('\n')
5044+
expected_cppcheck_output = expected_cppcheck_output.split('\n')
5045+
strace_output = strace_output.decode('utf-8').split('\n')
5046+
expected_strace_output = expected_strace_output.split('\n')
5047+
5048+
# Order may be different with -j
5049+
output_content.sort()
5050+
expected_cppcheck_output.sort()
5051+
strace_output.sort()
5052+
expected_strace_output.sort()
5053+
5054+
# With -j, the number of active checkers is different, and strace prints info about child processes
5055+
filter_func = lambda line: 'Active checkers' not in line and 'strace: Process' not in line
5056+
output_content = list(filter(filter_func, output_content))
5057+
strace_output = list(filter(filter_func, strace_output))
5058+
50335059
assert output_content == expected_cppcheck_output
5034-
assert strace_output.decode('utf-8') == expected_strace_output
5060+
assert strace_output == expected_strace_output

0 commit comments

Comments
 (0)