add travis-build to check source-code format
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
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