2017-04-21 09:23:45 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-09-15 19:38:54 +00:00
|
|
|
set -e
|
|
|
|
|
2017-11-20 14:26:03 +00:00
|
|
|
if ! test -e autogen/genstatic/gen.go; then
|
2015-11-01 15:35:01 +00:00
|
|
|
echo >&2 'error: generate must be run before test-unit'
|
2015-09-15 19:38:54 +00:00
|
|
|
false
|
|
|
|
fi
|
|
|
|
|
|
|
|
RED=$'\033[31m'
|
|
|
|
GREEN=$'\033[32m'
|
|
|
|
TEXTRESET=$'\033[0m' # reset the foreground colour
|
|
|
|
|
|
|
|
# This helper function walks the current directory looking for directories
|
|
|
|
# holding certain files ($1 parameter), and prints their paths on standard
|
|
|
|
# output, one per line.
|
|
|
|
find_dirs() {
|
|
|
|
find . -not \( \
|
|
|
|
\( \
|
|
|
|
-path './integration/*' \
|
2015-10-13 18:19:34 +00:00
|
|
|
-o -path './vendor/*' \
|
2015-09-15 19:38:54 +00:00
|
|
|
-o -path './.git/*' \
|
|
|
|
\) \
|
|
|
|
-prune \
|
|
|
|
\) -name "$1" -print0 | xargs -0n1 dirname | sort -u
|
|
|
|
}
|
|
|
|
|
|
|
|
TESTFLAGS="-cover -coverprofile=cover.out ${TESTFLAGS}"
|
|
|
|
|
2016-03-23 22:06:22 +00:00
|
|
|
if [ -n "$VERBOSE" ]; then
|
|
|
|
TESTFLAGS="${TESTFLAGS} -v"
|
|
|
|
fi
|
|
|
|
|
2015-09-15 19:38:54 +00:00
|
|
|
if [ -z "$TESTDIRS" ]; then
|
|
|
|
TESTDIRS=$(find_dirs '*_test.go')
|
|
|
|
fi
|
|
|
|
|
|
|
|
TESTS_FAILED=()
|
|
|
|
|
|
|
|
for dir in $TESTDIRS; do
|
|
|
|
echo '+ go test' $TESTFLAGS "${dir}"
|
2015-10-13 18:19:34 +00:00
|
|
|
go test ${TESTFLAGS} ${dir}
|
2015-09-15 19:38:54 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
TESTS_FAILED+=("$dir")
|
|
|
|
echo
|
|
|
|
echo "${RED}Tests failed: $dir${TEXTRESET}"
|
|
|
|
sleep 1 # give it a second, so observers watching can take note
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
|
|
|
|
# if some tests fail, we want the bundlescript to fail, but we want to
|
|
|
|
# try running ALL the tests first, hence TESTS_FAILED
|
|
|
|
if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then
|
|
|
|
echo "${RED}Test failures in: ${TESTS_FAILED[@]}${TEXTRESET}"
|
|
|
|
echo
|
|
|
|
false
|
|
|
|
else
|
|
|
|
echo "${GREEN}Test success${TEXTRESET}"
|
|
|
|
echo
|
|
|
|
true
|
|
|
|
fi
|