forked from canonical/snapweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-checks
executable file
·120 lines (98 loc) · 2.46 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
#!/bin/sh
set -eu
if which goctest >/dev/null; then
goctest="goctest"
else
goctest="go test"
fi
STATIC=""
UNIT_GO=""
UNIT_JS=""
case "${1:-all}" in
all)
STATIC="yes"
UNIT_GO="yes"
UNIT_JS="yes"
;;
--static)
STATIC="yes"
;;
--unit)
UNIT_GO="yes"
UNIT_JS="yes"
;;
--unit-go)
UNIT_GO="yes"
;;
--unit-js)
UNIT_JS="yes"
;;
*)
echo "Wrong flag ${1}. To run a single suite use --static, --unit, --unit-go or --unit-js."
exit 1
esac
# Append the coverage profile of a package to the project coverage.
append_go_coverage() {
local profile="$1"
if [ -f $profile ]; then
cat $profile | grep -v "mode: set" >> .coverage-go/coverage.out
rm $profile
fi
}
if [ ! -z "$STATIC" ] || [ ! -z "$UNIT_GO" ]; then
sh ./get-go-deps.sh
fi
if [ ! -z "$STATIC" ]; then
# Run static tests.
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 ./...
echo Install golint
go get -d github.com/golang/lint/golint
(
cd $GOPATH/src/github.com/golang/lint
# revert to the last commit before go 1.5 support was dropped
git checkout c6242afa6ced3be489e1184eb80bc2d85f1f5e7b .
)
go install github.com/golang/lint/golint
export PATH=$PATH:$GOPATH/bin
echo Running lint
lint=$(golint ./...)
if [ -n "$lint" ]; then
echo "Lint complains:"
echo $lint
exit 1
fi
fi
if [ ! -z "$UNIT_GO" ]; then
echo Building
go build -v github.com/snapcore/snapweb/...
# Prepare the coverage output profile.
rm -rf .coverage-go
mkdir .coverage-go
echo "mode: set" > .coverage-go/coverage.out
# tests
echo Running tests from $(pwd)
for pkg in $(go list ./... | grep -v integration-tests); do
$goctest -v -coverprofile=.coverage-go/profile.out $pkg
append_go_coverage .coverage-go/profile.out
done
fi
if [ ! -z "$UNIT_JS" ]; then
# www
echo Obtaining npm dependencies
npm install --loglevel error
rm -rf .coverage-js
# js unit tests
echo "Running js unit tests (set JS_TESTER to override)"
${JS_TESTER:- ./node_modules/karma/bin/karma start --single-run}
cat .coverage-js/text-summary.txt
fi
echo "All good, what could possibly go wrong"