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 (#6061)
  • Loading branch information
firewave committed Mar 8, 2024
1 parent 43e4fac commit 5804ef7
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 166 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,14 @@ jobs:
cd 'cpp check/test/cli'
python3 -m pytest -Werror --strict-markers -vv
# do not use pushd in this step since we go below the working directory
- name: Run test/cli (-j2)
run: |
cd test/cli
python3 -m pytest -Werror --strict-markers -vv
env:
TEST_CPPCHECK_INJECT_J: 2

- name: Run cfg tests
if: matrix.os != 'ubuntu-22.04'
run: |
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,28 @@ jobs:
if: matrix.config == 'release'
run: .\bin\testrunner.exe || exit /b !errorlevel!

- name: Run test/cli
- name: Prepare test/cli
if: matrix.config == 'release'
run: |
:: since FILESDIR is not set copy the binary to the root so the addons are found
:: copy .\build\bin\Release\cppcheck.exe .\cppcheck.exe || exit /b !errorlevel!
copy .\bin\cppcheck.exe .\cppcheck.exe || exit /b !errorlevel!
copy .\bin\cppcheck-core.dll .\cppcheck-core.dll || exit /b !errorlevel!
- name: Run test/cli
if: matrix.config == 'release'
run: |
cd test/cli || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv || exit /b !errorlevel!
- name: Run test/cli (-j2)
if: matrix.config == 'release'
run: |
cd test/cli || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv || exit /b !errorlevel!
env:
TEST_CPPCHECK_INJECT_J: 2

- name: Test addons
if: matrix.config == 'release'
run: |
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ jobs:
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
- name: Run test/cli (-j2)
run: |
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
env:
TEST_CPPCHECK_INJECT_J: 2

- name: Generate dependencies
if: false
run: |
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/tsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ jobs:
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
- name: Run test/cli (-j2)
run: |
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
env:
TEST_CPPCHECK_INJECT_J: 2

- name: Generate dependencies
if: false
run: |
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ubsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ jobs:
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
- name: Run test/cli (-j2)
run: |
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
env:
TEST_CPPCHECK_INJECT_J: 2

- name: Generate dependencies
run: |
# make sure auto-generated GUI files exist
Expand Down
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)
Loading

0 comments on commit 5804ef7

Please sign in to comment.