Skip to content

Commit cfe308c

Browse files
committed
misc: add a travis check for trailing whitepsace
1 parent 5881efd commit cfe308c

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

Diff for: .travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ before_install:
7171

7272
# shell-checks is quick and works, no display or compiles needed
7373

74-
script: time sh ./tests/shell-checks
74+
script:
75+
- time sh ./tests/shell-checks
76+
# Also check for trailing whitespace. Not doing in shell-checks because it depends on a clean tree (uses git diff):
77+
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then time sh ./tests/whitespace-check; fi
7578

7679
# OS X doesn't allow writing to /usr/bin, skip non-PREFIX make install test there
7780
install:

Diff for: tests/whitespace-check

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
set -x
4+
5+
# Invoked by travis to check for trailing whitespace
6+
# Only in travis since local tree may have other diffs applied:
7+
make cleanup
8+
9+
# Git diff doesn't show the trailing whitespace as of 2018/05/13.
10+
# Tried various color/diff settings with no luck.
11+
# The workaround is cat, but commands aren't standard on Linux/OS X
12+
git diff --exit-code > whitespace.diff
13+
ret="$?"
14+
15+
if [ "$ret" = 0 ]; then
16+
echo "No trailing whitespace found."
17+
exit 0
18+
else
19+
echo "There is trailing whitespace that needs to be fixed:"
20+
21+
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
22+
cat -A whitespace.diff
23+
elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
24+
# Currently unimpemented on OSX.
25+
# sed will need to be fixed as well:
26+
# sed --in-place 's,[ \t]\+$,,' $(find Makefile src tests -type f)
27+
# sed: illegal option -- -
28+
# usage: sed script [-Ealn] [-i extension] [file ...]
29+
# sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
30+
# make: *** [cleanup] Error 1
31+
# cat -etv whitespace.diff
32+
echo "Not fully implemented on osx yet"
33+
else
34+
echo "Unknown OS!"
35+
fi
36+
37+
exit 1
38+
fi

0 commit comments

Comments
 (0)