From cbff3fcdce5b0377a62fbe74f32e476efbf7ca9c Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Mon, 10 Aug 2015 13:05:37 -0400 Subject: TESTS: Add trailing whitespace test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Slebodnik Reviewed-by: Lukáš Slebodník Reviewed-by: Pavel Reichl --- src/tests/whitespace_test | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 src/tests/whitespace_test (limited to 'src') diff --git a/src/tests/whitespace_test b/src/tests/whitespace_test new file mode 100755 index 00000000..ea2aecf6 --- /dev/null +++ b/src/tests/whitespace_test @@ -0,0 +1,32 @@ +#!/bin/bash + +set -e -u -o pipefail + +# An AWK regex matching tracked file paths to be excluded from the search. +# Example: '.*\.po|README' +PATH_EXCLUDE_REGEX='.*\.po|.*\.patch|.*\.diff|\/debian\/.*' + +export GIT_DIR="$ABS_TOP_SRCDIR/.git" +export GIT_WORK_TREE="$ABS_TOP_SRCDIR" + +if [ ! -d "$GIT_DIR" ]; then + echo "Git repository is required for this test!" 1>&2 + exit 77 +fi + +git grep -n -I '\s\+$' -- "$(git rev-parse --show-toplevel)" | + awk -- " + BEGIN { + found = 0 + } + ! /^($PATH_EXCLUDE_REGEX):/ { + if (!found) { + print \"Trailing whitespace found:\" + found = 1 + } + print + } + END { + exit found + } + " -- cgit