Skip to content

Commit

Permalink
Refactor testfiles script
Browse files Browse the repository at this point in the history
  • Loading branch information
corny committed May 15, 2018
1 parent df1921f commit d692f82
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
29 changes: 3 additions & 26 deletions .test-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,7 @@ do
done

# Failures have incomplete results, so don't send
if [ "$FAIL" -eq 0 ]; then
goveralls -service=$CI -v -coverprofile=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
[ "$FAIL" -ne 0 ] && exit 1

exit $FAIL
goveralls -service=$CI -v -coverprofile=profile.cov
bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN -f profile.cov
25 changes: 25 additions & 0 deletions .test-testfiles
Original file line number Diff line number Diff line change
@@ -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")
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ install:
- go get golang.org/x/tools/cmd/cover
script:
- ./.test-coverage travis-ci
- ./.test-testfiles
- ./.travis.gofmt.sh
- find . -type f -name '*.go' | grep -v '^./vendor/' | xargs misspell -error
- go install github.com/FreifunkBremen/yanic

0 comments on commit d692f82

Please sign in to comment.