From 3cbd136d86867f293926ac3e0ebd7f2f2c57a07d Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 28 Feb 2024 13:44:18 +0100 Subject: [PATCH] added environment variable `TEST_CPPCHECK_INJECT_J` to inject `-j` into the cppcheck invocation of Python tests --- .github/workflows/CI-unixish.yml | 1 + .github/workflows/CI-windows.yml | 3 + .github/workflows/asan.yml | 1 + .github/workflows/tsan.yml | 1 + .github/workflows/ubsan.yml | 1 + test/cli/helloworld_test.py | 10 +-- test/cli/inline-suppress_test.py | 116 ++++---------------------- test/cli/more-projects_test.py | 4 +- test/cli/other_test.py | 52 +++++------- test/cli/qml_test.py | 2 +- test/cli/suppress-syntaxError_test.py | 24 +++--- test/cli/testutils.py | 10 +++ test/cli/unused_function_test.py | 16 ++-- 13 files changed, 82 insertions(+), 159 deletions(-) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 4f97bc18c193..b30a99331953 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -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' diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml index 7b84c67e1951..178f12995cb3 100644 --- a/.github/workflows/CI-windows.yml +++ b/.github/workflows/CI-windows.yml @@ -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= diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index 85a11263b57c..adae78903ebc 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -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 diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml index f79442c62c50..05e6408f580c 100644 --- a/.github/workflows/tsan.yml +++ b/.github/workflows/tsan.yml @@ -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 diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml index 20efd0742f0a..6615de76d600 100644 --- a/.github/workflows/ubsan.yml +++ b/.github/workflows/ubsan.yml @@ -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 diff --git a/test/cli/helloworld_test.py b/test/cli/helloworld_test.py index cc68d0bad8cf..94f136024fec 100644 --- a/test/cli/helloworld_test.py +++ b/test/cli/helloworld_test.py @@ -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: 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) diff --git a/test/cli/inline-suppress_test.py b/test/cli/inline-suppress_test.py index 8a7d7ea2b883..144ba717749a 100644 --- a/test/cli/inline-suppress_test.py +++ b/test/cli/inline-suppress_test.py @@ -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 == [ @@ -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', @@ -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 == [ @@ -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', @@ -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 == [ @@ -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 == [ @@ -154,8 +112,6 @@ 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 == [] @@ -163,14 +119,6 @@ def __test_backwards_compatibility(use_j): 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 = [ @@ -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() @@ -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 == [] @@ -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', @@ -239,8 +191,6 @@ 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 == [] @@ -248,15 +198,7 @@ def __test_unmatched_suppression_ifdef(use_j): 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', @@ -265,8 +207,6 @@ 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 == [] @@ -274,15 +214,7 @@ def __test_unmatched_suppression_ifdef_0(use_j): 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', @@ -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() @@ -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', @@ -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() @@ -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', @@ -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) diff --git a/test/cli/more-projects_test.py b/test/cli/more-projects_test.py index bc3ec616a9a1..c26bce8ac955 100644 --- a/test/cli/more-projects_test.py +++ b/test/cli/more-projects_test.py @@ -420,7 +420,7 @@ def test_project_file_order(tmpdir): """.format(test_file_c, test_file_d, test_file_b, test_file_a)) - args = ['--project={}'.format(project_file)] + args = ['--project={}'.format(project_file), '-j1'] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -494,7 +494,7 @@ def test_project_file_duplicate_2(tmpdir): """.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 = ['--project={}'.format(project_file), '-j1'] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 18d1d0763a3e..acc5a0fc2f07 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -9,7 +9,7 @@ from testutils import cppcheck, assert_cppcheck -def __test_missing_include(tmpdir, use_j): +def test_missing_include(tmpdir): # #11283 test_file = os.path.join(tmpdir, 'test.c') with open(test_file, 'wt') as f: f.write(""" @@ -17,21 +17,11 @@ def __test_missing_include(tmpdir, use_j): """) args = ['--enable=missingInclude', '--template=simple', test_file] - if use_j: - args.insert(0, '-j2') _, _, stderr = cppcheck(args) assert stderr == '{}:2:0: information: Include file: "test.h" not found. [missingInclude]\n'.format(test_file) -def test_missing_include(tmpdir): - __test_missing_include(tmpdir, False) - - -def test_missing_include_j(tmpdir): #11283 - __test_missing_include(tmpdir, True) - - def __test_missing_include_check_config(tmpdir, use_j): test_file = os.path.join(tmpdir, 'test.c') with open(test_file, 'wt') as f: @@ -113,7 +103,7 @@ def test_progress(tmpdir): } """) - args = ['--report-progress=0', '--enable=all', '--inconclusive', test_file] + args = ['--report-progress=0', '--enable=all', '--inconclusive', '-j1', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -217,6 +207,7 @@ def test_internal_error(tmpdir): assert stderr == '{}:0:0: error: Bailing from out analysis: Checking file failed: converting \'1f\' to integer failed - not an integer [internalError]\n\n^\n'.format(test_file) +# TODO: test with -j2 def test_addon_misra(tmpdir): test_file = os.path.join(tmpdir, 'test.cpp') with open(test_file, 'wt') as f: @@ -224,7 +215,7 @@ def test_addon_misra(tmpdir): typedef int MISRA_5_6_VIOLATION; """) - args = ['--addon=misra', '--enable=all', test_file] + args = ['--addon=misra', '--enable=all', '--disable=unusedFunction', '-j1', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -247,7 +238,7 @@ def test_addon_y2038(tmpdir): } """) - args = ['--addon=y2038', '--enable=all', '--template=simple', test_file] + args = ['--addon=y2038', '--enable=all', '--disable=unusedFunction', '--template=simple', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -268,7 +259,7 @@ def test_addon_threadsafety(tmpdir): } """) - args = ['--addon=threadsafety', '--enable=all', '--template=simple', test_file] + args = ['--addon=threadsafety', '--enable=all', '--disable=unusedFunction', '--template=simple', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -298,7 +289,7 @@ def test_addon_naming(tmpdir): int Var; """) - args = ['--addon={}'.format(addon_file), '--enable=all', '--template=simple', test_file] + args = ['--addon={}'.format(addon_file), '--enable=all', '--disable=unusedFunction', '--template=simple', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -409,7 +400,7 @@ class _clz { namespace _invalid_namespace { } """%(test_include_file_basename)) - args = ['--addon='+addon_file, '--verbose', '--enable=all', test_file] + args = ['--addon='+addon_file, '--verbose', '--enable=all', '--disable=unusedFunction', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -491,6 +482,7 @@ class _clz { assert lines == expect +# TODO: test with -j2 def test_addon_namingng_config(tmpdir): addon_file = os.path.join(tmpdir, 'namingng.json') addon_config_file = os.path.join(tmpdir, 'namingng.config.json') @@ -540,7 +532,7 @@ def test_addon_namingng_config(tmpdir): # only create the file pass - args = ['--addon='+addon_file, '--verbose', '--enable=all', test_file] + args = ['--addon='+addon_file, '--verbose', '--enable=all', '-j1', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -590,7 +582,7 @@ def test_addon_findcasts(tmpdir): } """) - args = ['--addon=findcasts', '--enable=all', '--template=simple', test_file] + args = ['--addon=findcasts', '--enable=all', '--disable=unusedFunction', '--template=simple', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -611,7 +603,7 @@ def test_addon_misc(tmpdir): } """) - args = ['--addon=misc', '--enable=all', '--template=simple', test_file] + args = ['--addon=misc', '--enable=all', '--disable=unusedFunction', '--template=simple', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -656,7 +648,7 @@ def test_invalid_addon_py(tmpdir): typedef int MISRA_5_6_VIOLATION; """) - args = ['--addon={}'.format(addon_file), '--enable=all', test_file] + args = ['--addon={}'.format(addon_file), '--enable=all', '--disable=unusedFunction', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 # TODO: needs to be 1 @@ -667,6 +659,7 @@ def test_invalid_addon_py(tmpdir): assert stderr == "{}:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon 'addon1' - exitcode is 1 [internalError]\n\n^\n".format(test_file) +# TODO: test with -j2 def test_invalid_addon_py_verbose(tmpdir): addon_file = os.path.join(tmpdir, 'addon1.py') with open(addon_file, 'wt') as f: @@ -680,7 +673,7 @@ def test_invalid_addon_py_verbose(tmpdir): typedef int MISRA_5_6_VIOLATION; """) - args = ['--addon={}'.format(addon_file), '--enable=all', '--verbose', test_file] + args = ['--addon={}'.format(addon_file), '--enable=all', '--disable=unusedFunction', '--verbose', '-j1', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 # TODO: needs to be 1 @@ -727,7 +720,7 @@ def test_addon_result(tmpdir): typedef int MISRA_5_6_VIOLATION; """) - args = ['--addon={}'.format(addon_file), '--enable=all', test_file] + args = ['--addon={}'.format(addon_file), '--enable=all', '--disable=unusedFunction', test_file] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 # TODO: needs to be 1 @@ -738,6 +731,7 @@ def test_addon_result(tmpdir): assert stderr == 'test.cpp:1:1: style: msg [addon1-id]\n\n^\n' +# TODO: test with -j2 # #11483 def test_unused_function_include(tmpdir): test_cpp_file = os.path.join(tmpdir, 'test.cpp') @@ -757,13 +751,13 @@ class A { }; """) - args = ['--enable=unusedFunction', '--inline-suppr', '--template=simple', test_cpp_file] + args = ['--enable=unusedFunction', '--inline-suppr', '--template=simple', '-j1', test_cpp_file] _, _, stderr = cppcheck(args) assert stderr == "{}:4:0: style: The function 'f' is never used. [unusedFunction]\n".format(test_h_file) -# TODO: test with -j and all other types +# TODO: test with all other types def test_showtime_top5_file(tmpdir): test_file = os.path.join(tmpdir, 'test.cpp') with open(test_file, 'wt') as f: @@ -877,7 +871,7 @@ def test_file_order(tmpdir): with open(test_file_d, 'wt'): pass - args = [test_file_c, test_file_d, test_file_b, test_file_a] + args = [test_file_c, test_file_d, test_file_b, test_file_a, '-j1'] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -909,7 +903,7 @@ def test_markup(tmpdir): with open(test_file_4, 'wt') as f: pass - args = ['--library=qt', test_file_1, test_file_2, test_file_3, test_file_4] + args = ['--library=qt', test_file_1, test_file_2, test_file_3, test_file_4, '-j1'] out_lines = [ 'Checking {} ...'.format(test_file_2), '1/4 files checked 0% done', @@ -938,7 +932,7 @@ def test_markup_j(tmpdir): with open(test_file_4, 'wt') as f: pass - args = ['--library=qt', test_file_1, test_file_2, test_file_3, test_file_4] + args = ['--library=qt', '-j2', test_file_1, test_file_2, test_file_3, test_file_4] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 @@ -1068,7 +1062,7 @@ def test_file_duplicate_2(tmpdir): with open(test_file_c, 'wt'): pass - args = [test_file_c, test_file_a, test_file_b, str(tmpdir), test_file_b, test_file_c, test_file_a, str(tmpdir)] + args = [test_file_c, test_file_a, test_file_b, str(tmpdir), test_file_b, test_file_c, test_file_a, str(tmpdir), '-j1'] exitcode, stdout, stderr = cppcheck(args) assert exitcode == 0 diff --git a/test/cli/qml_test.py b/test/cli/qml_test.py index 81c22cf03b0a..485ab597c4e8 100644 --- a/test/cli/qml_test.py +++ b/test/cli/qml_test.py @@ -12,7 +12,7 @@ def test_unused_functions(): - ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--library=qt', '--enable=unusedFunction', __project_dir]) + ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--library=qt', '--enable=unusedFunction', '-j1', __project_dir]) # there are unused functions. But fillSampleData is not unused because that is referenced from main.qml assert stdout.splitlines() == [] assert stderr.splitlines() == [ diff --git a/test/cli/suppress-syntaxError_test.py b/test/cli/suppress-syntaxError_test.py index 3c77ba5b808d..bc3248c8afbe 100644 --- a/test/cli/suppress-syntaxError_test.py +++ b/test/cli/suppress-syntaxError_test.py @@ -1,27 +1,29 @@ # python -m pytest test-suppress-syntaxError.py +import pytest from testutils import cppcheck -def test_j2(): - ret, stdout, stderr = cppcheck(['--error-exitcode=1', '-j2', '-q', 'proj-suppress-syntaxError']) - assert ret == 1 +def test_j(): + ret, stdout, stderr = cppcheck(['-q', '--error-exitcode=1', '-j2', '-q', 'proj-suppress-syntaxError']) + assert ret == 1, stdout assert len(stderr) > 0 -def test_j2_suppress(): - ret, stdout, stderr = cppcheck(['--error-exitcode=1', '--suppress=*:proj-suppress-syntaxError/*', '-j2', '-q', 'proj-suppress-syntaxError']) - assert ret == 0 +def test_suppress_j(): + ret, stdout, stderr = cppcheck(['-q', '--error-exitcode=1', '--suppress=*:proj-suppress-syntaxError/*', '-j2', '-q', 'proj-suppress-syntaxError']) + assert ret == 0, stdout assert len(stderr) == 0 +# TODO: test with -j2 def test_safety_suppress_syntax_error_implicitly(tmpdir): - ret, stdout, stderr = cppcheck(['--safety', '--suppress=*', 'proj-suppress-syntaxError'], remove_checkers_report=False) - assert ret == 1 + ret, stdout, stderr = cppcheck(['-q', '--safety', '--suppress=*', 'proj-suppress-syntaxError', '-j1'], remove_checkers_report=False) + assert ret == 1, stdout assert '[syntaxError]' in stderr assert 'Active checkers: There was critical errors' in stderr +# TODO: test with -j2 def test_safety_suppress_syntax_error_explicitly(): - ret, stdout, stderr = cppcheck(['--safety', '--suppress=syntaxError', 'proj-suppress-syntaxError'], remove_checkers_report=False) - assert ret == 1 + ret, stdout, stderr = cppcheck(['-q', '--safety', '--suppress=syntaxError', 'proj-suppress-syntaxError', '-j1'], remove_checkers_report=False) + assert ret == 1, stdout assert '[syntaxError]' not in stderr assert 'Active checkers: There was critical errors' in stderr - diff --git a/test/cli/testutils.py b/test/cli/testutils.py index 22a646a224c2..48ac83d0a7cf 100644 --- a/test/cli/testutils.py +++ b/test/cli/testutils.py @@ -77,6 +77,16 @@ def cppcheck(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_exe exe = cppcheck_exe if cppcheck_exe else __lookup_cppcheck_exe() assert exe is not None, 'no cppcheck binary found' + if 'TEST_CPPCHECK_INJECT_J' in os.environ: + found_j = False + for arg in args: + if arg.startswith('-j'): + found_j = True + break + if not found_j: + arg_j = '-j' + str(os.environ['TEST_CPPCHECK_INJECT_J']) + args.append(arg_j) + logging.info(exe + ' ' + ' '.join(args)) p = subprocess.Popen([exe] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, cwd=cwd) try: diff --git a/test/cli/unused_function_test.py b/test/cli/unused_function_test.py index e161df4e06fb..4aa06ade4d03 100644 --- a/test/cli/unused_function_test.py +++ b/test/cli/unused_function_test.py @@ -31,7 +31,7 @@ def __create_compdb(tmpdir, projpath): def test_unused_functions(): - ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', __project_dir]) + ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', '-j1', __project_dir]) assert stdout.splitlines() == [] assert stderr.splitlines() == [ "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) @@ -53,7 +53,8 @@ def test_unused_functions_project(): '--template=simple', '--enable=unusedFunction', '--inline-suppr', - '--project={}'.format(os.path.join(__project_dir, 'unusedFunction.cppcheck'))]) + '--project={}'.format(os.path.join(__project_dir, 'unusedFunction.cppcheck')), + '-j1']) assert stdout.splitlines() == [] assert [ "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) @@ -81,7 +82,8 @@ def test_unused_functions_compdb(tmpdir): '--template=simple', '--enable=unusedFunction', '--inline-suppr', - '--project={}'.format(compdb_file) + '--project={}'.format(compdb_file), + '-j1' ]) assert stdout.splitlines() == [] assert stderr.splitlines() == [ @@ -109,7 +111,7 @@ def test_unused_functions_compdb_j(tmpdir): def test_unused_functions_builddir(tmpdir): build_dir = os.path.join(tmpdir, 'b1') os.mkdir(build_dir) - ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', '--cppcheck-build-dir={}'.format(build_dir), __project_dir]) + ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', '-j1', '--cppcheck-build-dir={}'.format(build_dir), __project_dir]) assert stdout.splitlines() == [] assert stderr.splitlines() == [ "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) @@ -140,7 +142,8 @@ def test_unused_functions_builddir_project(tmpdir): '--enable=unusedFunction', '--inline-suppr', '--project={}'.format(os.path.join(__project_dir, 'unusedFunction.cppcheck')), - '--cppcheck-build-dir={}'.format(build_dir)]) + '--cppcheck-build-dir={}'.format(build_dir), + '-j1']) assert stdout.splitlines() == [] assert stderr.splitlines() == [ "{}3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(__project_dir_sep) @@ -178,7 +181,8 @@ def test_unused_functions_builddir_compdb(tmpdir): '--enable=unusedFunction', '--inline-suppr', '--project={}'.format(compdb_file), - '--cppcheck-build-dir={}'.format(build_dir) + '--cppcheck-build-dir={}'.format(build_dir), + '-j1' ]) assert stdout.splitlines() == [] assert stderr.splitlines() == [