This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
test.sh
executable file
·67 lines (58 loc) · 2.11 KB
/
test.sh
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
#!/usr/bin/env bash
# Copyright 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
mkdir -p profiles/
# Since quite a few tests have sleeps, running nproc + 2 tests should result in most
# effective parallelisation.
NPAR="$(($(nproc) + 2))"
# Skip running go vet in cron, since the code hasn't changed.
if [ "$CRON" != "true" ]; then
echo "Vet: go vet"
go vet
fi
echo "Test: Running $NPAR in parallel"
# Run tests with coverage for all barista packages
go list ./... \
| grep -v /samples/ \
| sed "s|_$PWD|.|" \
| tac \
| xargs -n1 -P$NPAR -IPKG sh -c \
'for try in `seq 1 3`; do
go test \
-timeout 90s \
-coverprofile=profiles/$(echo "PKG" | sed -e "s|./||" -e "s|/|_|g").out \
-covermode=atomic \
"PKG" \
&& exit 0
done
exit 1'
echo "Test: Logging with -tags baristadebuglog"
# Debug log tests need the build tag, otherwise the nop versions will be used.
go test -tags baristadebuglog -coverprofile=profiles/logging_real.out -covermode=atomic github.com/soumya92/barista/logging
# Remove all _capi.go coverage since those will intentionally not be tested.
for profile in profiles/*.out; do
perl -i -ne 'print unless /_capi\.go:/' "$profile"
done
# Merge all code coverage reports. Doing this here means that after running
# ./test.sh,
# go tool cover -html=c.out
# will show a coverage report instead of complaining about a bad format.
grep -E '^mode: \w+$' "$(find profiles/ -name '*.out' -print -quit)" > c.out
grep -hEv '^(mode: \w+)?$' profiles/*.out >> c.out
rm -rf profiles/
echo "Test: Samples"
# Run tests only for samples.
# This is just to make sure that all samples compile.
go test ./samples/...