-
Notifications
You must be signed in to change notification settings - Fork 9
/
test-big-cover.sh
executable file
·61 lines (52 loc) · 1.76 KB
/
test-big-cover.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
#!/bin/bash
set -e
source "$(dirname $0)/variables.sh"
TARGET=${1:-cover.out}
EXCLUDE_FILE=${2:-.excludecoverage}
LOG=${3:-test.log}
SRC_ROOT=${SRC_ROOT:-.}
rm $TARGET &>/dev/null || true
echo "mode: count" > $TARGET
echo "" > $LOG
DIRS=""
for DIR in $SRC;
do
if ls $DIR/*_test.go &> /dev/null; then
DIRS="$DIRS $DIR"
fi
done
PROFILE_REG="profile_reg.tmp"
PROFILE_BIG="profile_big.tmp"
TEST_EXIT=0
# run big tests one by one
TEST_FLAGS="-v -timeout 5m -covermode atomic"
echo "test-cover begin: concurrency 1, +big"
for DIR in $DIRS; do
if cat $DIR/*_test.go | grep "// +build" | grep "big" &>/dev/null; then
# extract only the tests marked "big"
BIG_TESTS=$(cat <(go test $DIR -tags big -list '.*' | grep -v '^ok' | grep -v 'no test files' ) \
<(go test $DIR -list '.*' | grep -v '^ok' | grep -v 'no test files') \
| sort | uniq -u | paste -sd' ' -)
# defaults to all if the split vars are unset
pick_subset "$BIG_TESTS" TESTS $SPLIT_IDX $TOTAL_SPLITS
TESTS=$(echo ${TESTS} | tr ' ' '|')
go test $TEST_FLAGS -tags big -run $TESTS -coverprofile $PROFILE_BIG \
-coverpkg $(go list ./$SRC_ROOT/... | grep -v /vendor/ | paste -sd, -) \
$DIR | tee $LOG
BIG_TEST_EXIT=${PIPESTATUS[0]}
# Only set TEST_EXIT if its already zero to be prevent overwriting non-zero exit codes
if [ "$TEST_EXIT" = "0" ]; then
TEST_EXIT=$BIG_TEST_EXIT
fi
if [ "$BIG_TEST_EXIT" != "0" ]; then
continue
fi
if [ -s $PROFILE_BIG ]; then
cat $PROFILE_BIG | tail -n +2 >> $PROFILE_REG
fi
fi
done
filter_cover_profile $PROFILE_REG $TARGET $EXCLUDE_FILE
find . -not -path '*/vendor/*' | grep \\.tmp$ | xargs -I{} rm {}
echo "test-cover result: $TEST_EXIT"
exit $TEST_EXIT