From 8782a5f5e41218c64ec9ae5c6932e452978ebae9 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 29 Aug 2019 11:38:21 +0200 Subject: [PATCH] lua.cfg: Add Lua C API library configuration with tests (#2119) --- .travis.yml | 2 +- cfg/lua.cfg | 156 +++++++++++++++++++++++++++++++++++++++++++ test/cfg/lua.c | 31 +++++++++ test/cfg/runtests.sh | 27 ++++++++ tools/donate-cpu.py | 1 + 5 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 cfg/lua.cfg create mode 100644 test/cfg/lua.c diff --git a/.travis.yml b/.travis.yml index 192517b6a..51fd90d77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ env: before_install: # install needed deps - travis_retry sudo apt-get update -qq - - travis_retry sudo apt-get install -qq python-pygments qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet python3-dev + - travis_retry sudo apt-get install -qq python-pygments qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet python3-dev liblua5.3-dev - travis_retry python2 -m pip install --user pytest==4.6.4 - travis_retry python2 -m pip install --user pylint - travis_retry python2 -m pip install --user unittest2 diff --git a/cfg/lua.cfg b/cfg/lua.cfg new file mode 100644 index 000000000..2ecdef683 --- /dev/null +++ b/cfg/lua.cfg @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + true + + + + + + false + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + false + + + + + + + false + + + + + + + + false + + + + + 1: + + + + + false + + + + + + false + + + + + + + + + false + + + + + + + + + false + + + + + + + + + + + + false + + + + + + + + + + + false + + + + + + + + + + + + false + + + + + + + + + + + true + + + + + + + + + + diff --git a/test/cfg/lua.c b/test/cfg/lua.c new file mode 100644 index 000000000..6f254cc12 --- /dev/null +++ b/test/cfg/lua.c @@ -0,0 +1,31 @@ + +// Test library configuration for lua.cfg +// +// Usage: +// $ cppcheck --check-library --library=lua --enable=information --error-exitcode=1 --inline-suppr --suppress=missingIncludeSystem test/cfg/lua.c +// => +// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0 +// + +#include +#include + +void validCode(lua_State *L) +{ + int a = lua_gettop(L); + printf("%d", a); + lua_pushnil(L); + lua_pop(L, 1); +} + +void ignoredReturnValue(lua_State *L) +{ + // cppcheck-suppress ignoredReturnValue + lua_tonumber(L, 1); + // cppcheck-suppress ignoredReturnValue + lua_tostring(L, 1); + // cppcheck-suppress ignoredReturnValue + lua_isboolean(L, 1); + // cppcheck-suppress ignoredReturnValue + lua_isnil(L, 1); +} diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index a98911e75..f6b337e61 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -199,6 +199,33 @@ else fi ${CPPCHECK} ${CPPCHECK_OPT} --library=python ${DIR}python.c +# lua.c +set +e +pkg-config --version +PKGCONFIG_RETURNCODE=$? +set -e +if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then + echo "pkg-config needed to retrieve Lua configuration is not available, skipping syntax check." +else + set +e + LUACONFIG=$(pkg-config --cflags lua-5.3) + LUACONFIG_RETURNCODE=$? + set -e + if [ $LUACONFIG_RETURNCODE -eq 0 ]; then + set +e + echo -e "#include " | ${CC} ${CC_OPT} ${LUACONFIG} -x c - + LUACONFIG_RETURNCODE=$? + set -e + if [ $LUACONFIG_RETURNCODE -ne 0 ]; then + echo "Lua not completely present or not working, skipping syntax check with ${CC}." + else + echo "Lua found and working, checking syntax with ${CC} now." + ${CC} ${CC_OPT} ${LUACONFIG} ${DIR}lua.c + fi + fi +fi +${CPPCHECK} ${CPPCHECK_OPT} --library=lua ${DIR}lua.c + # Check the syntax of the defines in the configuration files set +e xmlstarlet --version diff --git a/tools/donate-cpu.py b/tools/donate-cpu.py index 7b4ddea43..49fa5bb34 100644 --- a/tools/donate-cpu.py +++ b/tools/donate-cpu.py @@ -273,6 +273,7 @@ def scan_package(work_path, cppcheck_path, jobs): 'googletest': [''], 'gtk': ['', '', ''], 'libcerror': [''], + # 'lua': ['', '"lua.h"'], <= enable after release of version 1.89 'microsoft_sal': [''], 'motif': ['', '"prtypes.h"'],