-
Notifications
You must be signed in to change notification settings - Fork 1
/
runtests
executable file
·94 lines (79 loc) · 1.85 KB
/
runtests
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
#!/bin/bash
help() {
cat - <<EOF
Run a set of relay tests.
usage: runtests [options] [<small|medium|large> ...]
At least one test size class must be provided.
Options:
-b Run benchmarks as well as tests
-c Produce coverage profile files for each package
-v Generate verbose test output
-r Detect races
-h Show help
EOF
exit 0
}
fatal() {
echo $1
exit 1
}
get_script_dir() {
dirname ${BASH_SOURCE[0]}
}
bench=0
cover=0
verbose=0
race=0
while getopts ":bchrv" opt; do
case $opt in
b) bench=1 ;;
c) cover=1 ;;
v) verbose=1 ;;
r) race=1 ;;
h) help ;;
\?) fatal "invalid option: -$OPTARG" ;;
esac
done
# Shift options away to get to the remaining positional arguments
shifts=$(( $OPTIND - 1 ))
for i in `seq $shifts`; do
shift
done
# Validate test sizes
test_sizes=$@
if [[ $test_sizes == "" ]]; then
fatal "at least one size of tests must be selected ('small', 'medium' or 'large')"
fi
for test_size in $test_sizes; do
case $test_size in
small) ;; medium) ;; large) ;;
*) fatal "invalid test size (value must be 'small', 'medium' or 'large')" ;;
esac
done
# Ensure the tests are run from the correct directory
cd $(get_script_dir)
# Tests for each package are run separately as -coverprofile only
# works on a single package.
exitcode=0
packages=$(go list ./... | grep -v vendor)
for package in $packages; do
cmd="go test -tags='$test_sizes'"
if [[ $verbose -eq 1 ]]; then
cmd="$cmd -v"
fi
if [[ $race -eq 1 ]]; then
cmd="$cmd -race"
fi
if [[ $bench -eq 1 ]]; then
cmd="$cmd -bench=."
fi
if [[ $cover -eq 1 ]]; then
cmd="$cmd -coverprofile=$GOPATH/src/$package/cover.out"
fi
cmd="$cmd $package"
eval $cmd
if [[ $? -ne 0 ]]; then
exitcode=1
fi
done
exit $exitcode