From a05943bf0d30a806ee6ca3a6c31ba9fd1e7c1a72 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Sun, 13 May 2018 22:18:20 +0200 Subject: [PATCH] Refactor testfiles script --- .test-coverage | 29 +++-------------------------- .test-testfiles | 25 +++++++++++++++++++++++++ .travis.yml | 1 + 3 files changed, 29 insertions(+), 26 deletions(-) create mode 100755 .test-testfiles diff --git a/.test-coverage b/.test-coverage index cc6efbf..8874e70 100755 --- a/.test-coverage +++ b/.test-coverage @@ -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 +[ "$FAIL" -ne 0 ] && exit 1 -# 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 +goveralls -service=$CI -v -coverprofile=profile.cov +bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN -f profile.cov diff --git a/.test-testfiles b/.test-testfiles new file mode 100755 index 0000000..57dbe56 --- /dev/null +++ b/.test-testfiles @@ -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") diff --git a/.travis.yml b/.travis.yml index 344557c..3c90ae4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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