From 7a59949cb45c28de722f4418a2382b1e6ce0a54c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 7 Jan 2019 14:40:21 +0100 Subject: [PATCH] qt config test: Use pkg-config to retrieve Qt settings. (#1571) To be able to use real Qt-Code in "test/cfg/qt.cpp" and still do a syntax check the Qt settings are read out via pkg-config now if it is available. This way the test now can contain Qt macros and functions and the syntax check can still be used. Additionally the same options as for the other tests are used now for the Qt config tests. Installing the package "qtbase5-dev" should be enough to enable the syntax checks (already installed for travis tests). --- test/cfg/qt.cpp | 19 ++++++++++++++----- test/cfg/runtests.sh | 29 ++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index f1b0693db..dd98afb78 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -7,11 +7,10 @@ // No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0 // -class QString { -public: - int size(); - char &operator[](int pos); -}; +#include +#include +#include + void QString1(QString s) { @@ -27,3 +26,13 @@ int QString2() // cppcheck-suppress reademptycontainer return s.size(); } + +// Verify that Qt macros do not result in syntax errors, false positives or other issues. +class MacroTest1: public QObject { + Q_OBJECT + Q_PLUGIN_METADATA(IID "com.foo.bar" FILE "test.json") + +public: + explicit MacroTest1(QObject *parent = 0); + ~MacroTest1(); +}; diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index 08720f0d9..b4b6ba7f3 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -30,8 +30,31 @@ ${CC} ${CC_OPT} -D_GNU_SOURCE ${DIR}gnu.c ${CPPCHECK} ${CPPCHECK_OPT} --library=gnu ${DIR}gnu.c # qt.cpp -${CXX} ${CXX_OPT} ${DIR}qt.cpp -${CPPCHECK} --enable=style --enable=information --inconclusive --inline-suppr --error-exitcode=1 --library=qt ${DIR}qt.cpp +set +e +pkg-config --version +PKGCONFIG_RETURNCODE=$? +set -e +if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then + echo "pkg-config needed to retrieve Qt configuration is not available, skipping syntax check." +else + set +e + QTCONFIG=$(pkg-config --cflags Qt5Core) + QTCONFIG_RETURNCODE=$? + set -e + if [ $QTCONFIG_RETURNCODE -eq 0 ]; then + set +e + echo -e "#include " | ${CXX} ${CXX_OPT} ${QTCONFIG} -x c++ - + QTCHECK_RETURNCODE=$? + set -e + if [ $QTCHECK_RETURNCODE -ne 0 ]; then + echo "Qt not completely present or not working, skipping syntax check with ${CXX}." + else + echo "Qt found and working, checking syntax with ${CXX} now." + ${CXX} ${CXX_OPT} ${QTCONFIG} ${DIR}qt.cpp + fi + fi +fi +${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=qt ${DIR}qt.cpp # bsd.c ${CPPCHECK} ${CPPCHECK_OPT} --library=bsd ${DIR}bsd.c @@ -51,7 +74,7 @@ ${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win64 ${DIR}windows.cpp # wxwidgets.cpp set +e -WXCONFIG=`wx-config --cxxflags` +WXCONFIG=$(wx-config --cxxflags) WXCONFIG_RETURNCODE=$? set -e if [ $WXCONFIG_RETURNCODE -ne 0 ]; then