Skip to content

Commit

Permalink
added environment variable TEST_CPPCHECK_INJECT_J to inject -j in…
Browse files Browse the repository at this point in the history
…to the cppcheck invocation of Python tests
  • Loading branch information
firewave committed Mar 1, 2024
1 parent bb6fe1f commit ee59751
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 157 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
run: |
cd test/cli
python3 -m pytest -Werror --strict-markers -vv
TEST_CPPCHECK_INJECT_J="2" python3 -m pytest -Werror --strict-markers -vv
cd ../../..
ln -s cppcheck 'cpp check'
cd 'cpp check/test/cli'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,6 @@ jobs:
copy .\bin\cppcheck-core.dll .\cppcheck-core.dll || exit /b !errorlevel!
cd test/cli || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv || exit /b !errorlevel!
set TEST_CPPCHECK_INJECT_J=2
python -m pytest -Werror --strict-markers -vv || exit /b !errorlevel!
set TEST_CPPCHECK_INJECT_J=
1 change: 1 addition & 0 deletions .github/workflows/asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" TEST_CPPCHECK_INJECT_J="2" python3 -m pytest -Werror --strict-markers -vv
- name: Generate dependencies
if: false
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ jobs:
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" TEST_CPPCHECK_INJECT_J="2" python3 -m pytest -Werror --strict-markers -vv
1 change: 1 addition & 0 deletions .github/workflows/ubsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ jobs:
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" TEST_CPPCHECK_INJECT_J="2" python3 -m pytest -Werror --strict-markers -vv
10 changes: 1 addition & 9 deletions test/cli/helloworld_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,8 @@ def test_checkers_report():
assert 'Yes CheckAutoVariables::assignFunctionArg' in data


def __test_missing_include_system(use_j):
def test_missing_include_system(): # #11283
args = ['--enable=missingInclude', '--suppress=zerodiv', '--template=simple', 'helloworld']
if use_j:
args.insert(0, '-j2')

_, _, stderr = cppcheck(args)
assert stderr.replace('\\', '/') == 'helloworld/main.c:1:0: information: Include file: <stdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n'

def test_missing_include_system():
__test_missing_include_system(False)

def test_missing_include_system_j(): #11283
__test_missing_include_system(True)
116 changes: 15 additions & 101 deletions test/cli/inline-suppress_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,25 @@ def __create_unused_function_compile_commands(tmpdir):
return compile_commands


def __test1(use_j):
def test1():
args = [
'-q',
'--template=simple',
'--inline-suppr',
'proj-inline-suppress'
]
if use_j:
args.append('-j2')
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
assert stderr == ''
assert stdout == ''
assert ret == 0, stdout


def test1():
__test1(False)


def test1_j():
__test1(True)


def __test2(use_j):
def test2():
args = [
'-q',
'--template=simple',
'proj-inline-suppress'
]
if use_j:
args.append('-j2')
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
assert lines == [
Expand All @@ -66,15 +54,7 @@ def __test2(use_j):
assert ret == 0, stdout


def test2():
__test2(False)


def test2_j():
__test2(True)


def __test_unmatched_suppression(use_j):
def test_unmatched_suppression():
args = [
'-q',
'--template=simple',
Expand All @@ -84,8 +64,6 @@ def __test_unmatched_suppression(use_j):
'--error-exitcode=1',
'{}2.c'.format(__proj_inline_suppres_path)
]
if use_j:
args.append('-j2')
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
assert lines == [
Expand All @@ -95,15 +73,7 @@ def __test_unmatched_suppression(use_j):
assert ret == 1, stdout


def test_unmatched_suppression():
__test_unmatched_suppression(False)


def test_unmatched_suppression_j():
__test_unmatched_suppression(True)


def __test_unmatched_suppression_path_with_extra_stuff(use_j):
def test_unmatched_suppression_path_with_extra_stuff():
args = [
'-q',
'--template=simple',
Expand All @@ -113,8 +83,6 @@ def __test_unmatched_suppression_path_with_extra_stuff(use_j):
'--error-exitcode=1',
'{}2.c'.format(__proj_inline_suppres_path)
]
if use_j:
args.append('-j2')
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
assert lines == [
Expand All @@ -124,22 +92,12 @@ def __test_unmatched_suppression_path_with_extra_stuff(use_j):
assert ret == 1, stdout


def test_unmatched_suppression_path_with_extra_stuff():
__test_unmatched_suppression_path_with_extra_stuff(False)


def test_unmatched_suppression_path_with_extra_stuff_j():
__test_unmatched_suppression_path_with_extra_stuff(True)


def __test_backwards_compatibility(use_j):
def test_backwards_compatibility():
args = [
'-q',
'--template=simple',
'{}3.cpp'.format(__proj_inline_suppres_path)
]
if use_j:
args.append('-j2')
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
assert lines == [
Expand All @@ -154,23 +112,13 @@ def __test_backwards_compatibility(use_j):
'--inline-suppr',
'{}3.cpp'.format(__proj_inline_suppres_path)
]
if use_j:
args.append('-j2')
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
assert lines == []
assert stdout == ''
assert ret == 0, stdout


def test_backwards_compatibility():
__test_backwards_compatibility(False)


def test_backwards_compatibility_j():
__test_backwards_compatibility(True)


def __test_compile_commands_unused_function(tmpdir, use_j):
compdb_file = __create_unused_function_compile_commands(tmpdir)
args = [
Expand All @@ -182,6 +130,8 @@ def __test_compile_commands_unused_function(tmpdir, use_j):
]
if use_j:
args.append('-j2')
else:
args.append('-j1')
ret, stdout, stderr = cppcheck(args)
proj_path_sep = os.path.join(__script_dir, 'proj-inline-suppress-unusedFunction') + os.path.sep
lines = stderr.splitlines()
Expand Down Expand Up @@ -213,6 +163,8 @@ def __test_compile_commands_unused_function_suppression(tmpdir, use_j):
]
if use_j:
args.append('-j2')
else:
args.append('-j1')
ret, stdout, stderr = cppcheck(args)
lines = stderr.splitlines()
assert lines == []
Expand All @@ -229,7 +181,7 @@ def test_compile_commands_unused_function_suppression_j(tmpdir):
__test_compile_commands_unused_function_suppression(tmpdir, True)


def __test_unmatched_suppression_ifdef(use_j):
def test_unmatched_suppression_ifdef():
args = [
'-q',
'--template=simple',
Expand All @@ -239,24 +191,14 @@ def __test_unmatched_suppression_ifdef(use_j):
'-DNO_ZERO_DIV',
'trac5704/trac5704a.c'
]
if use_j:
args.append('-j2')
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
assert lines == []
assert stdout == ''
assert ret == 0, stdout


def test_unmatched_suppression_ifdef():
__test_unmatched_suppression_ifdef(False)


def test_unmatched_suppression_ifdef_j():
__test_unmatched_suppression_ifdef(True)


def __test_unmatched_suppression_ifdef_0(use_j):
def test_unmatched_suppression_ifdef_0():
args = [
'-q',
'--template=simple',
Expand All @@ -265,24 +207,14 @@ def __test_unmatched_suppression_ifdef_0(use_j):
'--inline-suppr',
'trac5704/trac5704b.c'
]
if use_j:
args.append('-j2')
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
assert lines == []
assert stdout == ''
assert ret == 0, stdout


def test_unmatched_suppression_ifdef_0():
__test_unmatched_suppression_ifdef_0(False)


def test_unmatched_suppression_ifdef_0_j():
__test_unmatched_suppression_ifdef_0(True)


def __test_build_dir(tmpdir, use_j):
def test_build_dir(tmpdir):
args = [
'-q',
'--template=simple',
Expand All @@ -291,8 +223,6 @@ def __test_build_dir(tmpdir, use_j):
'--inline-suppr',
'{}4.c'.format(__proj_inline_suppres_path)
]
if use_j:
args.append('-j2')

ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
Expand All @@ -307,14 +237,6 @@ def __test_build_dir(tmpdir, use_j):
assert ret == 0, stdout


def test_build_dir(tmpdir):
__test_build_dir(tmpdir, False)


def test_build_dir_j(tmpdir):
__test_build_dir(tmpdir, True)


def __test_build_dir_unused_template(tmpdir, use_j):
args = [
'-q',
Expand All @@ -326,6 +248,8 @@ def __test_build_dir_unused_template(tmpdir, use_j):
]
if use_j:
args.append('-j2')
else:
args.append('-j1')

ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
Expand All @@ -343,7 +267,7 @@ def test_build_dir_unused_template_j(tmpdir):
__test_build_dir_unused_template(tmpdir, True)


def __test_suppress_unmatched_inline_suppression(use_j): # 11172
def test_suppress_unmatched_inline_suppression(): # 11172
args = [
'-q',
'--template=simple',
Expand All @@ -353,18 +277,8 @@ def __test_suppress_unmatched_inline_suppression(use_j): # 11172
'--inline-suppr',
'{}2.c'.format(__proj_inline_suppres_path)
]
if use_j:
args.append('-j2')
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
assert lines == []
assert stdout == ''
assert ret == 0, stdout


def test_suppress_unmatched_inline_suppression():
__test_suppress_unmatched_inline_suppression(False)


def test_suppress_unmatched_inline_suppression_j():
__test_suppress_unmatched_inline_suppression(True)
4 changes: 2 additions & 2 deletions test/cli/more-projects_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def test_project_file_order(tmpdir):
</paths>
</project>""".format(test_file_c, test_file_d, test_file_b, test_file_a))

args = ['--project={}'.format(project_file)]
args = ['-j1', '--project={}'.format(project_file)]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0
Expand Down Expand Up @@ -494,7 +494,7 @@ def test_project_file_duplicate_2(tmpdir):
</paths>
</project>""".format(test_file_c, test_file_a, test_file_b, tmpdir, test_file_b, test_file_c, test_file_a, tmpdir))

args = ['--project={}'.format(project_file)]
args = ['-j1', '--project={}'.format(project_file)]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0
Expand Down
Loading

0 comments on commit ee59751

Please sign in to comment.