Skip to content

Commit 0d5d3bc

Browse files
committed
travis: add indentation check after running tests
1 parent 7e3dc30 commit 0d5d3bc

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

ci/travis/linux/after_script.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cat '/tmp/ctest-important.log'
1+
[ -r /tmp/ctest-important.log ] && cat /tmp/ctest-important.log

ci/travis/linux/before_install.sh

+4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ sudo apt-get install --force-yes --no-install-recommends --no-install-suggests \
5656
xfonts-base \
5757
xfonts-scalable \
5858
xvfb \
59+
python-pip \
60+
flip \
5961
postgresql-9.1-postgis-2.1/precise # from ubuntugis-unstable, not pgdg
6062

63+
sudo -H pip install autopep8 # TODO when switching to trusty or above: replace python-pip with python-autopep8
64+
6165
#update clang
6266
sudo apt-get install --force-yes llvm-3.7 llvm-3.7-dev clang-3.7 libstdc++-4.9-dev
6367
export CXX="clang++-3.7"

ci/travis/linux/install.sh

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cmake -DWITH_SERVER=ON \
1010
-DENABLE_PGTEST=ON \
1111
-DWITH_QWTPOLAR=OFF \
1212
-DWITH_APIDOC=ON \
13+
-DWITH_ASTYLE=ON \
1314
-DWITH_PYSPATIALITE=ON \
1415
-DGRASS_PREFIX7=/usr/lib/grass70 \
1516
-DGRASS_INCLUDE_DIR7=/usr/lib/grass70/include ..

scripts/verify-indentation.sh

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
cd $(git rev-parse --show-toplevel)
4+
5+
export PATH=$PATH:$PWD/scripts
6+
7+
if [ -z "$TRAVIS_COMMIT_RANGE" ]; then
8+
echo "No commit range given"
9+
exit 0
10+
fi
11+
12+
TRAVIS_COMMIT_RANGE=${TRAVIS_COMMIT_RANGE/.../..}
13+
14+
if ! type -p astyle.sh >/dev/null; then
15+
echo astyle.sh not found
16+
exit 1
17+
fi
18+
19+
set -e
20+
21+
ASTYLEDIFF=/tmp/astyle.diff
22+
>$ASTYLEDIFF
23+
24+
echo "Checking indentation in $TRAVIS_COMMIT_RANGE"
25+
echo "Checking indentation in $TRAVIS_COMMIT_RANGE" >>/tmp/ctest-important.log
26+
git log $TRAVIS_COMMIT_RANGE >>/tmp/ctest-important.log 2>&1
27+
git diff --name-only $TRAVIS_COMMIT_RANGE >>/tmp/ctest-important.log 2>&1
28+
29+
git diff --name-only $TRAVIS_COMMIT_RANGE | while read f
30+
do
31+
echo "Checking $f" >>/tmp/ctest-important.log
32+
case "$f" in
33+
src/core/gps/qextserialport/*|src/plugins/dxf2shp_converter/dxflib/src/*|src/plugins/globe/osgEarthQt/*|src/plugins/globe/osgEarthUtil/*)
34+
echo $f skipped
35+
continue
36+
;;
37+
38+
*.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip|*.py)
39+
;;
40+
41+
*)
42+
continue
43+
;;
44+
esac
45+
46+
m=$f.prepare
47+
cp "$f" "$m"
48+
astyle.sh "$f"
49+
if diff -u "$m" "$f" >>$ASTYLEDIFF; then
50+
rm $m
51+
else
52+
echo "File $f needs indentation"
53+
fi
54+
done
55+
56+
if [ -s "$ASTYLEDIFF" ]; then
57+
echo
58+
echo "Required indentation updates:"
59+
cat "$ASTYLEDIFF"
60+
61+
cat <<EOF
62+
63+
Tips to prevent and resolve:
64+
* Enable WITH_ASTYLE in your cmake configuration
65+
* Use scripts/astyle.sh file to fix the now badly indented files
66+
* Consider using scripts/prepare-commit.sh as pre-commit hook to avoid this
67+
in the future (ln -s scripts/prepare-commit.sh .git/hooks/pre-commit) or
68+
run it manually before each commit.
69+
EOF
70+
71+
exit 1
72+
fi

tests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ IF (ENABLE_TESTS)
22
ADD_SUBDIRECTORY(src)
33
ADD_SUBDIRECTORY(bench)
44
ENDIF (ENABLE_TESTS)
5+
6+
IF(WITH_ASTYLE)
7+
ADD_TEST(qgis_indentation ${CMAKE_SOURCE_DIR}/scripts/verify-indentation.sh)
8+
ENDIF(WITH_ASTYLE)

0 commit comments

Comments
 (0)