whitespace_test revision 900778b5afd0143005cfd40cc67ad5086481f7ee
0N/A#!/bin/bash
0N/A
0N/Aset -e -u -o pipefail
0N/A
0N/A# An AWK regex matching tracked file paths to be excluded from the search.
0N/A# Example: '.*\.po|README'
0N/APATH_EXCLUDE_REGEX='.*\.po|.*\.patch|.*\.diff|\/debian\/.*'
0N/A
0N/Aexport GIT_DIR="$ABS_TOP_SRCDIR/.git"
0N/Aexport GIT_WORK_TREE="$ABS_TOP_SRCDIR"
0N/A
0N/Aif [ ! -d "$GIT_DIR" ]; then
0N/A echo "Git repository is required for this test!" 1>&2
0N/A exit 77
0N/Afi
0N/A
0N/A{
0N/A # Look for lines with trailing whitespace in all files tracked by Git
0N/A git grep -n -I '\s\+$' -- "$(git rev-parse --show-toplevel)" ||
0N/A # Don't fail if no such lines were found anywhere
0N/A [[ $? == 1 ]]
0N/A} |
0N/A awk -- "
0N/A BEGIN {
0N/A found = 0
0N/A }
0N/A ! /^($PATH_EXCLUDE_REGEX):/ {
0N/A if (!found) {
0N/A print \"Trailing whitespace found:\"
0N/A found = 1
0N/A }
0N/A print
0N/A }
0N/A END {
0N/A exit found
0N/A }
0N/A "
0N/A
0N/Adeclare found_file=false
0N/Awhile read file; do
0N/A [[ $file == "src/config/testconfigs/noparse.api.conf" ]] && continue
0N/A [[ $file =~ ^src/tests/cmocka/p11_nssdb/.*db ]] && continue
0N/A test `tail -c 1 $ABS_TOP_SRCDIR/$file` && \
0N/A echo "Missing new line at the eof: $file" && \
0N/A found_file=true
338N/Adone < <(git ls-files)
0N/A
0N/Aif $found_file; then
0N/A exit 1
0N/Afi
0N/A