-
-
Notifications
You must be signed in to change notification settings - Fork 315
/
test.sh
executable file
·128 lines (112 loc) · 4.02 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash -e
# runs all (or selected) test suite(s) in test/ and aggregates results
# Usage:
# ./test.sh
# ./test.sh gofmt
# 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
fold_start environment
test -z "$testsuite" && (echo "ENV:"; env | sort; echo;)
fold_end environment
# make it easy to split test into blocks
label-block() {
if $(env | grep -q -e '^TEST_BLOCK='"$1"'$') || $(! env | grep -q -e '^TEST_BLOCK=') || $(env | grep -q -e '^TEST_BLOCK=$'); then
return 0
else
return 1 # not my block
fi
}
# run a test and record failures
function run-testsuite() {
testname="$(basename "$1" .sh)"
# if not running all tests or if this test is not explicitly selected, skip it
if test -z "$testsuite" || test "test-$testsuite" = "$testname"; then
fold_start "$testname"
description="$testname ($@)"
"$@" || failures=$([ -n "$failures" ] && echo "$failures\\n$description" || echo "$description")
fold_end "$testname"
fi
}
# 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
}
# used at the end to tell if everything went fine
failures=''
if label-block "basic"; then
run-testsuite ./test/test-vet.sh
run-testsuite ./test/test-misc.sh
run-testsuite ./test/test-gofmt.sh
run-testsuite ./test/test-mclfmt.sh
run-testsuite ./test/test-yamlfmt.sh
run-testsuite ./test/test-bashfmt.sh
run-testsuite ./test/test-headerfmt.sh
run-testsuite ./test/test-markdownlint.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
# FIXME: this fails with go.mod
skip-testsuite ./test/test-gometalinter.sh
run-testsuite ./test/test-golint.sh # test last, because this test is somewhat arbitrary
# FIXME: this now fails everywhere :(
skip-testsuite ./test/test-reproducible.sh
fi
# skipping: https://github.com/purpleidea/mgmt/issues/327
# run-test ./test/test-crossbuild.sh
# do these longer tests only when running on ci
if in_env; then
if label-block "shell"; then
run-testsuite ./test/test-shell.sh
fi
if label-block "race"; then
run-testsuite ./test/test-gotest.sh --race
run-testsuite ./test/test-integration.sh --race
fi
# XXX: fix and enable these on travis (sudo: go: command not found)
#run-testsuite ./test/test-gotest.sh --root
#run-testsuite ./test/test-gotest.sh --root --race
#run-testsuite ./test/test-integration.sh --root
#run-testsuite ./test/test-integration.sh --root --race
else
REASON="CI server only test" skip-testsuite ./test/test-shell.sh
REASON="CI server only test" skip-testsuite ./test/test-gotest.sh --race
REASON="CI server only test" skip-testsuite ./test/test-integration.sh
REASON="CI server only test" skip-testsuite ./test/test-integration.sh --race
REASON="CI server only test" skip-testsuite ./test/test-gotest.sh --root
REASON="CI server only test" skip-testsuite ./test/test-gotest.sh --root --race
REASON="CI server only test" skip-testsuite ./test/test-integration.sh --root
REASON="CI server only test" skip-testsuite ./test/test-integration.sh --root --race
fi
# run omv tests on jenkins physical hosts only
if env | grep -q -e '^JENKINS_URL=' -e '^BUILD_TAG=jenkins'; then
run-testsuite ./test/test-omv.sh
else
REASON="CI server only test" skip-testsuite ./test/test-omv.sh
fi
REASON="https://github.com/purpleidea/mgmt/issues/327" skip-testsuite ./test/test-crossbuild.sh
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` or `make test-shell-<testname>`'
exit 1
fi
echo 'ALL PASSED'