Debian Codegraph @

test.sh

raw symbols SCIP
1 # Copyright 2017 Google Inc. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15
16 #!/usr/bin/env bash
17
18 set -e
19 set -x
20 MODE=atomic
21 echo "mode: $MODE" > coverage.txt
22
23 # Note: browsertests is in a separate module and is therefore not
24 # covered by a local ./... pattern.
25
26 if [ "$RUN_STATICCHECK" != "false" ]; then
27 staticcheck ./...
28 (cd browsertests && staticcheck ./...)
29 fi
30
31 # Packages that have any tests.
32 PKG=$(go list -f '{{if .TestGoFiles}} {{.ImportPath}} {{end}}' ./...)
33
34 go test $PKG
35
36 retry() {
37 for i in {1..3}; do
38 [[ $i == 1 ]] || sleep 10 # Backing off after a failed attempt.
39 "${@}" && return 0
40 done
41 return 1
42 }
43
44 # Retry browser tests in case of error since they are flaky.
45 # See https://github.com/google/pprof/issues/925.
46 (cd browsertests && retry go test ./...)
47 (cd browsertests && retry go test -race ./...)
48
49 # Skip browsertests since it test-only code and gives no useful coverage info
50 for d in $PKG; do
51 go test -race -coverprofile=profile.out -covermode=$MODE $d
52 if [ -f profile.out ]; then
53 cat profile.out | grep -v "^mode: " >> coverage.txt
54 rm profile.out
55 fi
56 done
57
58 go vet -all ./...
59 (cd browsertests && go vet -all ./...)
60 if [ "$RUN_GOLANGCI_LINTER" != "false" ]; then
61 golangci-lint run -D errcheck --timeout=3m ./... # TODO: Enable errcheck back.
62 (cd browsertests && golangci-lint run --timeout=3m ./...)
63 fi
64
65 # A workaround for gofmt returning zero exit code even if there is diff.
66 # See https://github.com/golang/go/issues/46289.
67 gofmt_or_fail() {
68 test -z "$(gofmt -d -s . | tee >(cat >&2))"
69 }
70 gofmt_or_fail
71 (cd browsertests && gofmt_or_fail)