Commit 179daef1233d4c464a1f649c0b8a8db1761574af

Steffen Jaeckel 2019-04-06T17:37:33

add travis-build to check source-code format

diff --git a/.travis.yml b/.travis.yml
index 743d621..8461004 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -57,6 +57,14 @@ matrix:
     # We have only one program and the variable $BUILDOPTIONS
     # has only the options to that program: testme.sh
 
+    # Check source code format
+    - env: BUILDOPTIONS='--format'
+      addons:
+        apt:
+          packages:
+            - astyle
+      sudo: required
+
     # GCC for the 32-bit architecture (no valgrind yet)
     - env: BUILDOPTIONS='--with-cc=gcc --with-m32'
       addons:
diff --git a/testme.sh b/testme.sh
index b340df1..40ecb74 100755
--- a/testme.sh
+++ b/testme.sh
@@ -72,6 +72,10 @@ _help()
   echo "    --all                   Choose all architectures and gcc and clang"
   echo "                            as compilers but does not run valgrind."
   echo
+  echo "    --format                Runs the various source-code formatters"
+  echo "                            and generators and checks if the sources"
+  echo "                            are clean."
+  echo
   echo "    -h"
   echo "    --help                  This message"
   echo
@@ -168,6 +172,7 @@ MTEST_RAND=""
 VALGRIND_OPTS=" --leak-check=full --show-leak-kinds=all --error-exitcode=1 "
 #VALGRIND_OPTS=""
 VALGRIND_BIN=""
+CHECK_FORMAT=""
 
 alive_pid=0
 
@@ -225,6 +230,9 @@ do
     --mtest-real-rand)
       MTEST_RAND="-DLTM_MTEST_REAL_RAND"
     ;;
+    --format)
+      CHECK_FORMAT="1"
+    ;;
     --all)
       COMPILERS="gcc clang"
       ARCHFLAGS="-m64 -m32 -mx32"
@@ -243,6 +251,21 @@ do
   shift
 done
 
+function _check_git() {
+  git update-index --refresh >/dev/null || true
+  git diff-index --quiet HEAD -- . || ( echo "FAILURE: $*" && exit 1 )
+}
+
+if [[ "$CHECK_FORMAT" == "1" ]]
+then
+  make astyle
+  _check_git "make astyle"
+  make new_file
+  _check_git "make format"
+  perl helper.pl -a
+  exit $?
+fi
+
 [[ "$VALGRIND_BIN" == "" ]] && VALGRIND_OPTS=""
 
 # default to CC environment variable if no compiler is defined but some other options