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).
This commit is contained in:
Sebastian 2019-01-07 14:40:21 +01:00 committed by amai2012
parent 07da4b4d37
commit 7a59949cb4
2 changed files with 40 additions and 8 deletions

View File

@ -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 <QObject>
#include <QString>
#include <QtPlugin>
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();
};

View File

@ -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 <QString>" | ${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