Refactor testfiles script

This commit is contained in:
Julian Kornberger 2018-05-13 22:18:20 +02:00
parent bd398847ba
commit a05943bf0d
3 changed files with 29 additions and 26 deletions

View File

@ -25,30 +25,7 @@ do
done done
# Failures have incomplete results, so don't send # Failures have incomplete results, so don't send
if [ "$FAIL" -eq 0 ]; then [ "$FAIL" -ne 0 ] && exit 1
goveralls -service=$CI -v -coverprofile=profile.cov goveralls -service=$CI -v -coverprofile=profile.cov
bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN -f profile.cov bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN -f profile.cov
fi
# Test if every package has testfiles
for dir in $(find . -name "*.go" -printf '%h\0'| sort -zu | sed -z 's/$/\n/');
do
# ignore ./vendor/ completely
[[ $dir == ./vendor/* ]] && continue
if [ "$(ls $dir/*_test.go 2> /dev/null | wc -l)" -eq "0" ]; then
echo -n "no test files for $dir";
case $dir in
'.' | './database/graphite')
echo " - but ignored";
continue
;;
*)
echo "";
FAIL=1;
;;
esac
fi
done
exit $FAIL

25
.test-testfiles Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python
# checks if every desired package has test files
import os
import re
import sys
source_re = re.compile(".*\.go")
test_re = re.compile(".*_test\.go")
missing = False
for root, dirs, files in os.walk("."):
# ignore some paths
if root == "." or root == "./database/graphite" or root.startswith("./vendor") or root.startswith("./."):
continue
# source files but not test files?
if len(filter(source_re.match, files)) > 0 and len(filter(test_re.match, files)) == 0:
print("no test files for {}".format(root))
missing = True
if missing:
sys.exit(1)
else:
print("every package has test files")

View File

@ -10,6 +10,7 @@ install:
- go get golang.org/x/tools/cmd/cover - go get golang.org/x/tools/cmd/cover
script: script:
- ./.test-coverage travis-ci - ./.test-coverage travis-ci
- ./.test-testfiles
- ./.travis.gofmt.sh - ./.travis.gofmt.sh
- find . -type f -name '*.go' | grep -v '^./vendor/' | xargs misspell -error - find . -type f -name '*.go' | grep -v '^./vendor/' | xargs misspell -error
- go install github.com/FreifunkBremen/yanic - go install github.com/FreifunkBremen/yanic