-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·41 lines (35 loc) · 1.33 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
#!/usr/bin/env bash
# shellcheck disable=SC2086
set -e
# testpkg tests a given `pkg` using the package's `Makefile` or directly using `go test` and `go vet`.
#
# @param: pkg name of the package
# @env: GOTEST_ARGS extra test arguments for `go test` or `make test GOTEST_ARGS=GOTEST_ARGS`
#
testpkg() {
set -e
pkg="$1"
echo -n "testing '$pkg', "
if test -e "$pkg/Makefile"; then
echo "found '$pkg/Makefile'"
run make -C "$pkg" test
else
if test -e "$pkg/go.mod"
then tests="./..."; echo "found go.mod for package '$pkg', entering dir '$pkg'"; cd "$pkg"
else tests="./$pkg/..."; echo "found subpackage '$pkg', running subpackage tests";
fi
prefix=".cache/$pkg"
mkdir -p "$(dirname "$prefix")"
test -z "$GOTEST_ARGS" || echo "using GOTEST_ARGS=$GOTEST_ARGS as additional go test arguments"
touch "$prefix.log"
run go test -race $GOTEST_ARGS $tests 2>&1 | tee "$prefix.log"
run go vet $tests
fi
if test -e "$pkg/go.mod" && ! test -f "$pkg/LICENSE"; then
echo "ERROR: standalone package $pkg needs a hard-copied LICENSE file"
return 1
fi
}
# run prints a command before running it, similar to how `make` echos commands.
run() { echo "$*"; "$@"; }
for pkg in "$@"; do testpkg "$pkg"; done