This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
run-checks
executable file
·136 lines (114 loc) · 2.88 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
#!/bin/bash
set -eu
if which goctest >/dev/null; then
goctest="goctest"
else
goctest="go test"
fi
STATIC_GO=""
STATIC_JS=""
UNIT_GO=""
UNIT_JS=""
export PHANTOMJS_BIN=`pwd`/node_modules/.bin/phantomjs
[ "$#" -eq 0 ] && args="--all" || args="$@"
for arg in $args; do
case "$arg" in
--all)
STATIC_GO="yes"
STATIC_JS="yes"
UNIT_GO="yes"
UNIT_JS="yes"
;;
--go)
STATIC_GO="yes"
UNIT_GO="yes"
;;
--js)
STATIC_JS="yes"
UNIT_JS="yes"
;;
--static)
STATIC_GO="yes"
STATIC_JS="yes"
;;
--static-go)
STATIC_GO="yes"
;;
--static-js)
STATIC_JS="yes"
;;
--unit)
UNIT_GO="yes"
UNIT_JS="yes"
;;
--unit-go)
UNIT_GO="yes"
;;
--unit-js)
UNIT_JS="yes"
;;
--skip-npm-install)
SKIP_NPM_INSTALL="yes"
;;
*)
echo "Wrong flag ${1}. To run a single suite use --static, --static-go, --static-js, --unit, --unit-go, --unit-js or --all to run all tests."
exit 1
esac
done
# 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_GO" ]; then
# Run go static tests.
echo Checking formatting
fmt=$(gofmt -l .)
if [ -n "$fmt" ]; then
echo "Formatting wrong in following files"
echo "$fmt"
echo "Getting formating diff..."
fmt_diff=$(gofmt -d .)
echo "$fmt_diff"
exit 1
fi
# go vet
echo Running vet
go vet ./...
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 "$STATIC_JS" ]; then
npm run js:lint
fi
if [ ! -z "$UNIT_GO" ]; then
echo Building
go build 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 -coverprofile=.coverage-go/profile.out $pkg
append_go_coverage .coverage-go/profile.out
done
fi
if [ ! -z "$UNIT_JS" ]; then
rm -rf .coverage-js
# js unit tests
echo "Running js unit tests (set JS_TESTER to override)"
NODE_ENV=test ${JS_TESTER:- ./node_modules/karma/bin/karma start --single-run}
cat .coverage-js/text-summary.txt
fi
echo "\nAll good, what could possibly go wrong"