forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-checks
executable file
·181 lines (154 loc) · 3.86 KB
/
run-checks
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/sh
export LANG=C.UTF-8
export LANGUAGE=en
set -eu
if which goctest >/dev/null; then
goctest="goctest"
else
goctest="go test"
fi
STATIC=
UNIT=
SPREAD=
DEPRECATED=
case "${1:-all}" in
all)
STATIC=1
UNIT=1
DEPRECATED=1
;;
--static)
STATIC=1
;;
--unit)
UNIT=1
;;
--spread)
SPREAD=1
;;
--integration)
DEPRECATED=1
;;
*)
echo "Wrong flag ${1}. To run a single suite use --static, --unit, --spread, or --integration."
exit 1
esac
CURRENTTRAP="true"
EXIT_CODE=99
store_exit_code() {
EXIT_CODE=$?
}
exit_with_exit_code() {
exit $EXIT_CODE
}
addtrap() {
CURRENTTRAP="$CURRENTTRAP ; $1"
trap "store_exit_code; $CURRENTTRAP ; exit_with_exit_code" EXIT
}
endmsg() {
if [ $EXIT_CODE -eq 0 ]; then
p="success.txt"
m="All good, what could possibly go wrong."
else
p="failure.txt"
m="Crushing failure and despair."
fi
echo
if [ -t 1 -a -z "$STATIC" ]; then
cat "data/$p"
else
echo "$m"
fi
}
addtrap endmsg
# Append the coverage profile of a package to the project coverage.
append_coverage() {
local profile="$1"
if [ -f $profile ]; then
cat $profile | grep -v "mode: set" | cat >> .coverage/coverage.out
rm $profile
fi
}
if [ "$STATIC" = 1 ]; then
./get-deps.sh
# Run static tests.
echo Checking docs
./mdlint.py docs/*.md
echo Checking formatting
fmt=$(gofmt -l .)
if [ -n "$fmt" ]; then
echo "Formatting wrong in following files"
echo "$fmt"
exit 1
fi
# go vet
echo Running vet
go vet ./...
# golint
echo Install golint
go get github.com/golang/lint/golint
export PATH=$PATH:$GOPATH/bin
echo Running lint
lint=$(golint ./...)
if [ -n "$lint" ]; then
echo "Lint complains:"
echo "$lint"
# don't exit 1
fi
fi
if [ "$UNIT" = 1 ]; then
./get-deps.sh
# Prepare the coverage output profile.
rm -rf .coverage
mkdir .coverage
echo "mode: set" > .coverage/coverage.out
echo Building
go build -tags=excludeintegration -v github.com/snapcore/snapd/...
# tests
echo Running tests from $(pwd)
for pkg in $(go list ./... | grep -v integration-tests); do
$goctest -tags=excludeintegration -v -coverprofile=.coverage/profile.out $pkg
append_coverage .coverage/profile.out
done
echo Building the integration tests
TMP_INTEGRATION="$(mktemp)"
addtrap "rm -f \"$TMP_INTEGRATION\""
go build -v -o $TMP_INTEGRATION github.com/snapcore/snapd/integration-tests/
# the rabbit hole
echo Running the tests for the integration testutils
for pkg in $(go list ./integration-tests/testutils/...); do
$goctest -v -coverprofile=.coverage/profile.out $pkg
append_coverage .coverage/profile.out
done
fi
if [ "$SPREAD" = 1 ]; then
TMP_SPREAD="$(mktemp -d)"
addtrap "rm -rf \"$TMP_SPREAD\""
export PATH=$TMP_SPREAD:$PATH
( cd $TMP_SPREAD && curl -s -O https://niemeyer.s3.amazonaws.com/spread-amd64.tar.gz && tar xzvf spread-amd64.tar.gz )
spread -v
fi
if [ "$DEPRECATED" = 1 ]; then
./get-deps.sh
# deprecated integration suite in kvm
if which adt-run >/dev/null 2>&1; then
echo "Running integration tests on rolling edge"
result=0
go run integration-tests/main.go --snappy-from-branch || result=$?
# print the results.
if which subunit2pyunit >/dev/null 2>&1; then
subunit2pyunit /tmp/snappy-test/output/artifacts/results.subunit
fi
if [ "$result" -ne 0 ]; then
exit $result
fi
fi
fi
UNCLEAN="$(git status -s|grep ^??)" || true
if [ -n "$UNCLEAN" ]; then
cat <<EOF
There are files left in the git tree after the tests:
$UNCLEAN
EOF
exit 1
fi