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 echoscip-shell system . . 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 [scip-shell system . . `[`. "$RUN_STATICCHECK" != "false" ]; then
27 staticcheck ./...
28 (cd browsertests && staticcheck ./...)
29 fi
30
31 # Packages that have any tests.
32 PKG=$(goscip-shell system . . go. list -f '{{if .TestGoFiles}} {{.ImportPath}} {{end}}' ./...)
33
34 goscip-shell system . . go. test $PKG
35
36 retryscip-shell shell shell-project 0.0.0 retry().() {
37 for i in {1..3}; do
38 [[ $i == 1 ]] || sleepscip-shell system . . 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 && retryscip-shell shell shell-project 0.0.0 retry(). go test ./...)
47 (cd browsertests && retryscip-shell shell shell-project 0.0.0 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 goscip-shell system . . go. test -race -coverprofile=profile.out -covermode=$MODE $d
52 if [scip-shell system . . `[`. -f profile.out ]; then
53 catscip-shell system . . cat. profile.out | grepscip-shell system . . grep. -v "^mode: " >> coverage.txt
54 rmscip-shell system . . rm. profile.out
55 fi
56 done
57
58 goscip-shell system . . go. vet -all ./...
59 (cd browsertests && goscip-shell system . . go. vet -all ./...)
60 if [scip-shell system . . `[`. "$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_failscip-shell shell shell-project 0.0.0 gofmt_or_fail().() {
68 testscip-shell system . . test. -z "$(gofmtscip-shell system . . gofmt. -d -s . | teescip-shell system . . tee. >(catscip-shell system . . cat. >&2))"
69 }
70 gofmt_or_failscip-shell shell shell-project 0.0.0 gofmt_or_fail().
71 (cd browsertests && gofmt_or_failscip-shell shell shell-project 0.0.0 gofmt_or_fail().)