test: Streamline test suite a little
This change aims to streamline the integrationtest suite and reduce friction when running (parts of) test suites. Changes: - add `test-testname` to makefile to easily run one suite - made skipping tests first class citizen in test.sh (all available testsuites and the reasons they are skipped are now better exposed and discovered) - suppress some output of gotest unless there is an error - no longer build binary for examples and gotest suites - removed .SILENT from makefile as it being applied to only some targets makes it feel weird (I just learned about this option btw, feel free to comment on this change) - move individual tests out of `test.sh` and into `test-misc.sh` - introduced the concept of testsuites to `test.sh`
This commit is contained in:
92
test.sh
92
test.sh
@@ -1,54 +1,94 @@
|
||||
#!/bin/bash -e
|
||||
# test suite...
|
||||
echo running test.sh
|
||||
echo "ENV:"
|
||||
env
|
||||
# runs all (or selected) test suite(s) in test/ and aggregates results
|
||||
# Usage:
|
||||
# ./test.sh
|
||||
# ./test.sh gofmt
|
||||
|
||||
failures=''
|
||||
function run-test()
|
||||
# library of utility functions
|
||||
# shellcheck disable=SC1091
|
||||
. test/util.sh
|
||||
|
||||
# allow specifying a single testsuite to run
|
||||
testsuite="$1"
|
||||
|
||||
# print environment when running all testsuites
|
||||
test -z "$testsuite" && (echo "ENV:"; env; echo; )
|
||||
|
||||
# run a test and record failures
|
||||
function run-testsuite()
|
||||
{
|
||||
$@ || failures=$( [ -n "$failures" ] && echo "$failures\\n$@" || echo "$@" )
|
||||
testname="$(basename "$1" .sh)"
|
||||
# if not running all test or this test is not explicitly selected, skip it
|
||||
if test -z "$testsuite" || test "test-$testsuite" = "$testname";then
|
||||
$@ || failures=$( [ -n "$failures" ] && echo "$failures\\n$@" || echo "$@" )
|
||||
fi
|
||||
}
|
||||
|
||||
# ensure there is no trailing whitespace or other whitespace errors
|
||||
run-test git diff-tree --check $(git hash-object -t tree /dev/null) HEAD
|
||||
# only run test if it is explicitly selected, otherwise report it is skipped
|
||||
function skip-testsuite()
|
||||
{
|
||||
testname=$(basename "$1" .sh)
|
||||
# show skip message only when running full suite
|
||||
if test -z "$testsuite";then
|
||||
echo skipping "$@" "($REASON)"
|
||||
echo 'SKIP'
|
||||
else
|
||||
# if a skipped suite is explicity called, run it anyway
|
||||
if test "test-$testsuite" == "$testname";then
|
||||
run-testsuite "$@"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# ensure entries to authors file are sorted
|
||||
start=$(($(grep -n '^[[:space:]]*$' AUTHORS | awk -F ':' '{print $1}' | head -1) + 1))
|
||||
run-test diff <(tail -n +$start AUTHORS | sort) <(tail -n +$start AUTHORS)
|
||||
# used at the end to tell if everything went fine
|
||||
failures=''
|
||||
|
||||
run-test ./test/test-gofmt.sh
|
||||
run-test ./test/test-yamlfmt.sh
|
||||
run-test ./test/test-bashfmt.sh
|
||||
run-test ./test/test-headerfmt.sh
|
||||
run-test ./test/test-commit-message.sh
|
||||
run-test ./test/test-govet.sh
|
||||
run-test ./test/test-examples.sh
|
||||
run-test ./test/test-gotest.sh
|
||||
run-testsuite ./test/test-misc.sh
|
||||
run-testsuite ./test/test-gofmt.sh
|
||||
run-testsuite ./test/test-yamlfmt.sh
|
||||
run-testsuite ./test/test-bashfmt.sh
|
||||
run-testsuite ./test/test-headerfmt.sh
|
||||
run-testsuite ./test/test-commit-message.sh
|
||||
run-testsuite ./test/test-govet.sh
|
||||
run-testsuite ./test/test-examples.sh
|
||||
run-testsuite ./test/test-gotest.sh
|
||||
|
||||
# skipping: https://github.com/purpleidea/mgmt/issues/327
|
||||
# run-test ./test/test-crossbuild.sh
|
||||
|
||||
# do these longer tests only when running on ci
|
||||
if env | grep -q -e '^TRAVIS=true$' -e '^JENKINS_URL=' -e '^BUILD_TAG=jenkins'; then
|
||||
run-test ./test/test-shell.sh
|
||||
#run-test ./test/test-gotest.sh --race # XXX: temporarily disabled...
|
||||
run-testsuite ./test/test-shell.sh
|
||||
skip-testsuite ./test/test-gotest.sh --race # XXX: temporarily disabled...
|
||||
else
|
||||
REASON="CI server only test" skip-testsuite ./test/test-shell.sh
|
||||
REASON="CI server only test" skip-testsuite ./test/test-gotest.sh --race # XXX: temporarily disabled...
|
||||
fi
|
||||
|
||||
run-test ./test/test-gometalinter.sh
|
||||
run-testsuite ./test/test-gometalinter.sh
|
||||
|
||||
# FIXME: this now fails everywhere :(
|
||||
#run-test ./test/test-reproducible.sh
|
||||
skip-testsuite ./test/test-reproducible.sh
|
||||
|
||||
# run omv tests on jenkins physical hosts only
|
||||
if env | grep -q -e '^JENKINS_URL=' -e '^BUILD_TAG=jenkins'; then
|
||||
run-test ./test/test-omv.sh
|
||||
run-testsuite ./test/test-omv.sh
|
||||
else
|
||||
REASON="CI server only test" skip-testsuite ./test/test-omv.sh
|
||||
fi
|
||||
run-test ./test/test-golint.sh # test last, because this test is somewhat arbitrary
|
||||
|
||||
REASON="https://github.com/purpleidea/mgmt/issues/327" skip-testsuite ./test/test-crossbuild.sh
|
||||
|
||||
run-testsuite ./test/test-golint.sh # test last, because this test is somewhat arbitrary
|
||||
|
||||
if [[ -n "$failures" ]]; then
|
||||
echo 'FAIL'
|
||||
echo 'The following tests have failed:'
|
||||
echo -e "$failures"
|
||||
echo
|
||||
echo 'You can rerun a single suite like so:'
|
||||
echo
|
||||
echo 'make test-gofmt'
|
||||
exit 1
|
||||
fi
|
||||
echo 'ALL PASSED'
|
||||
|
||||
Reference in New Issue
Block a user