From 7d876701b3d7ca8ee9ed9f5fabc62eec7ed2a274 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 14 Feb 2016 14:21:28 -0500 Subject: [PATCH] Add test case to match headers --- test.sh | 1 + test/test-headerfmt.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100755 test/test-headerfmt.sh diff --git a/test.sh b/test.sh index 1c5a0332..453db26b 100755 --- a/test.sh +++ b/test.sh @@ -14,6 +14,7 @@ diff <(tail -n +$start AUTHORS | sort) <(tail -n +$start AUTHORS) ./test/test-gofmt.sh ./test/test-yamlfmt.sh ./test/test-bashfmt.sh +./test/test-headerfmt.sh go test echo running go vet # since it doesn't output an ok message on pass go vet && echo PASS diff --git a/test/test-headerfmt.sh b/test/test-headerfmt.sh new file mode 100755 index 00000000..ccd64b2d --- /dev/null +++ b/test/test-headerfmt.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# check that headers are properly formatted +echo running test-headerfmt.sh +ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir! +FILE="${ROOT}/main.go" # file headers should match main.go +COUNT=0 +while IFS='' read -r line; do # find what header should look like + echo "$line" | grep -q '^//' || break + COUNT=`expr $COUNT + 1` +done < "$FILE" +cd "${ROOT}" + +find_files() { + git ls-files | grep '\.go$' +} + +bad_files=$( + for i in $(find_files); do + if ! diff -q <( head -n $COUNT "$i" ) <( head -n $COUNT "$FILE" ) &>/dev/null; then + echo "$i" + fi + done +) + +if [[ -n "${bad_files}" ]]; then + echo 'FAIL' + echo 'The following file headers are not properly formatted:' + echo "${bad_files}" + exit 1 +fi