From b3a46e72dc29798bde8e2cde08f7907670efaa58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 1 May 2019 11:54:13 +0200 Subject: [PATCH] Fix and test syntaxError suppression --- .travis.yml | 6 ++---- lib/cppcheck.cpp | 12 +++--------- test/cli/proj-suppress-syntaxError/1.c | 10 ++++++++++ test/cli/proj-suppress-syntaxError/2.c | 1 + test/cli/proj-suppress-syntaxError/3.c | 2 ++ test/cli/test-suppress-syntaxError.py | 17 +++++++++++++++++ 6 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 test/cli/proj-suppress-syntaxError/1.c create mode 100644 test/cli/proj-suppress-syntaxError/2.c create mode 100644 test/cli/proj-suppress-syntaxError/3.c create mode 100644 test/cli/test-suppress-syntaxError.py diff --git a/.travis.yml b/.travis.yml index 24b779fd9..0d71512fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -219,11 +219,9 @@ script: # building gui generates some more files that cppcheck can check, so check the repo *after* building gui - cd ../ # self check - - touch /tmp/cppcheck.cppcheck - - ${CPPCHECK} --template=gcc -D__CPPCHECK__ -f --error-exitcode=1 --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml/ -Icli --enable=style,performance,portability,warning,internal --exception-handling --inline-suppr --suppressions-list=.travis_suppressions -itest/cli -itest/synthetic -itest/testsuites -iaddons -igui . -j 2 |& tee /tmp/cppcheck.cppcheck + - ${CPPCHECK} --template=gcc -D__CPPCHECK__ -f --error-exitcode=1 --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml/ -Icli --enable=style,performance,portability,warning,internal --exception-handling --inline-suppr --suppressions-list=.travis_suppressions -itest/cli -itest/synthetic -itest/testsuites -iaddons -igui . -j 2 # check gui with qt settings - - ${CPPCHECK} --template=gcc --library=qt --error-exitcode=1 -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml/ -Icli --enable=style,performance,portability,warning,internal --exception-handling -j 2 gui --suppressions-list=.travis_suppressions -igui/test |& tee --append /tmp/cppcheck.cppcheck - - sh -c "! grep '\]$' /tmp/cppcheck.cppcheck" + - ${CPPCHECK} --template=gcc --library=qt --error-exitcode=1 -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml/ -Icli --enable=style,performance,portability,warning,internal --exception-handling -j 2 gui --suppressions-list=.travis_suppressions -igui/test # check naming conventions - ${CPPCHECK} -i gui/test -j 2 --dump -q gui lib - find lib gui -maxdepth 1 -name "*.dump" | xargs -n 1 -P 4 python addons/naming.py --private-member-variable='m[A-Z].*' diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 6b5480b3e..1d8b3bc49 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -215,7 +215,6 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string CheckUnusedFunctions checkUnusedFunctions(nullptr, nullptr, nullptr); - bool internalErrorFound(false); try { Preprocessor preprocessor(mSettings, this); std::set configurations; @@ -538,11 +537,8 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string e.id, false); - if (errmsg._severity == Severity::error || mSettings.isEnabled(errmsg._severity)) { + if (errmsg._severity == Severity::error || mSettings.isEnabled(errmsg._severity)) reportErr(errmsg); - if (!mSuppressInternalErrorFound) - internalErrorFound = true; - } } } @@ -668,9 +664,6 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string } mErrorList.clear(); - if (internalErrorFound && (mExitCode==0)) { - mExitCode = 1; - } return mExitCode; } @@ -1122,8 +1115,9 @@ void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg) } } - if (!mSettings.nofail.isSuppressed(errorMessage) && (mUseGlobalSuppressions || !mSettings.nomsg.isSuppressed(errorMessage))) + if (!mSettings.nofail.isSuppressed(errorMessage) && !mSettings.nomsg.isSuppressed(errorMessage)) { mExitCode = 1; + } mErrorList.push_back(errmsg); diff --git a/test/cli/proj-suppress-syntaxError/1.c b/test/cli/proj-suppress-syntaxError/1.c new file mode 100644 index 000000000..ebc333b99 --- /dev/null +++ b/test/cli/proj-suppress-syntaxError/1.c @@ -0,0 +1,10 @@ + + +void validCode(int argInt) +{ + // if G_UNLIKELY is not defined this results in a syntax error + if G_UNLIKELY(argInt == 1) { + } else if (G_UNLIKELY(argInt == 2)) { + } +} + diff --git a/test/cli/proj-suppress-syntaxError/2.c b/test/cli/proj-suppress-syntaxError/2.c new file mode 100644 index 000000000..12a8770e5 --- /dev/null +++ b/test/cli/proj-suppress-syntaxError/2.c @@ -0,0 +1 @@ +void f1(); diff --git a/test/cli/proj-suppress-syntaxError/3.c b/test/cli/proj-suppress-syntaxError/3.c new file mode 100644 index 000000000..d8eabefa3 --- /dev/null +++ b/test/cli/proj-suppress-syntaxError/3.c @@ -0,0 +1,2 @@ + +void f2(); diff --git a/test/cli/test-suppress-syntaxError.py b/test/cli/test-suppress-syntaxError.py new file mode 100644 index 000000000..c5d6a68d6 --- /dev/null +++ b/test/cli/test-suppress-syntaxError.py @@ -0,0 +1,17 @@ + +# python -m pytest test-suppress-syntaxError.py + +import os +import re +from testutils import cppcheck + +def test_j2(): + ret, stdout, stderr = cppcheck('--error-exitcode=1 -j2 -q proj-suppress-syntaxError') + assert ret == 1 + 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 + assert len(stderr) == 0 +