Debian Codegraph @

test

raw
1 #!/usr/bin/env bash
2
3 set -eu
4
5 echo "Checking for license headers..."
6 EXPECTED_HEADER='//
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.'
18
19 HEADER_CHECK_FAILED=0
20
21 for file in $(find config internal validate tests -name \*.go -type f -not -name schema.go); do
22 # Don't check the first line because the year will vary
23 HEADER="$(head -n 13 ${file} | tail -n 12)"
24 if [ "${HEADER}" != "${EXPECTED_HEADER}" ]; then
25 echo "${file} is missing the Apache License header"
26 HEADER_CHECK_FAILED=1
27 fi
28 done
29
30 if [ "${HEADER_CHECK_FAILED}" -ne 0 ]; then
31 exit 1
32 fi
33
34 source ./build
35
36 SRC=$(find . -name '*.go' -not -path "./vendor/*")
37
38 PKG=$(go list ./... | \
39 grep --invert-match vendor | grep --invert-match tests)
40
41 # https://github.com/golang/go/issues/15067
42 PKG_VET=$(go list ./... | \
43 grep --invert-match vendor | \
44 grep --invert-match internal/log)
45
46 echo "Checking gofix..."
47 go tool fix -diff $SRC
48
49 echo "Checking gofmt..."
50 res=$(gofmt -d -e -s $SRC)
51 echo "${res}"
52 if [ -n "${res}" ]; then
53 exit 1
54 fi
55
56 echo "Checking govet..."
57 go vet $PKG_VET
58
59 echo "Running tests..."
60 if [ "$GOARCH" == amd64 ]; then
61 go test -timeout 60s -cover $@ ${PKG} --race
62 else
63 go test -timeout 60s -cover $@ ${PKG}
64 fi
65
66 echo "Checking docs..."
67 go run internal/util/tools/docs/docs.go
68 # Ensure every platform is listed in supported-platforms.md
69 platforms=$(grep -A 1 configs.Register internal/platform/platform.go | grep name: | cut -f2 -d\")
70 if [ -z "${platforms}" ]; then
71 echo "Found no platform IDs; update $0" >&2
72 exit 1
73 fi
74 for id in ${platforms}; do
75 case "${id}" in
76 file) ;; # Undocumented platform ID for testing
77 *)
78 if ! grep -qF "\`${id}\`" docs/supported-platforms.md; then
79 echo "Undocumented platform ID: $id" >&2
80 exit 1
81 fi
82 ;;
83 esac
84 done
85
86 echo "Success"