[PATCH 1/5] Run cppcheck on the C source files.
David Shea
dshea at redhat.com
Fri Jan 31 15:23:22 UTC 2014
This test will perform static analysis on our C sources and catch some
potential problems. Enabled some extra warnings that seemed minimally
annoying; we can adjust it later if we feel like.
---
tests/Makefile.am | 2 ++
tests/cppcheck/runcppcheck.sh | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+)
create mode 100755 tests/cppcheck/runcppcheck.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d67bf13..81bf461 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -51,6 +51,7 @@ dist_check_SCRIPTS = glade/accelerators/check_accelerators.py \
pylint/markup.py \
pylint/runpylint.sh \
pylint/pylint-one.sh \
+ cppcheck/runcppcheck.sh \
testenv.sh \
gettext/gettext_warnings.sh \
gettext/gettext_potfiles.py \
@@ -60,6 +61,7 @@ dist_check_SCRIPTS = glade/accelerators/check_accelerators.py \
TESTS = nosetests.sh \
pylint/runpylint.sh \
+ cppcheck/runcppcheck.sh \
gettext/gettext_warnings.sh \
gettext/gettext_potfiles.py \
storage/run_storage_tests.py \
diff --git a/tests/cppcheck/runcppcheck.sh b/tests/cppcheck/runcppcheck.sh
new file mode 100755
index 0000000..7dc2f4d
--- /dev/null
+++ b/tests/cppcheck/runcppcheck.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# If $top_srcdir has not been set by automake, import the test environment
+if [ -z "$top_srcdir" ]; then
+ top_srcdir="$(dirname "$0")/../.."
+ . ${top_srcdir}/tests/testenv.sh
+fi
+
+if ! type cppcheck > /dev/null 2>&1 ; then
+ echo "cppcheck must be installed"
+ exit 99
+fi
+
+# If files were specified on the command line, use those. Otherwise, look
+# for all .c files
+if [ "$#" -gt 0 ]; then
+ filelist="$@"
+else
+ filelist="$(find "$top_srcdir" -name '*.c')"
+fi
+
+# Disable unusedFunction in widgets since everything will show up as unused
+# Specify the path twice so the path works relative to both the top of the
+# tree and from the tests/ directory.
+cppcheck_output="$(echo "$filelist" |
+ xargs cppcheck -q -v --error-exitcode=1 \
+ --template='{id}:{file}:{line}: {message}' \
+ --inline-suppr \
+ --enable=warning,unusedFunction \
+ --suppress=unusedFunction:*/widgets/src/* \
+ --suppress=unusedFunction:widgets/src/* \
+ 2>&1 )"
+
+if [ -n "$cppcheck_output" ]; then
+ echo "$cppcheck_output"
+ exit 1
+fi
--
1.8.5.3
More information about the anaconda-patches
mailing list