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
|
#!/usr/bin/env bash
set -euo pipefail
if [ -t 1 ]; then
RED=$'\E[00;31m'
GREEN=$'\E[00;32m'
RESET=$'\E[0m'
else
RED=''
GREEN=''
RESET=''
fi
echo '# Testing benchmarks'
if ! command -v readarray &>/dev/null; then
printf '%sSKIP%s\t%s\n' "${RED}" "${RESET}" \
"readarray not supported by this verison of bash"
exit 0
fi
# Go packages
readarray -t PACKAGES < <(go list ./...)
if ((${#PACKAGES[@]} == 0)); then
printf '%sFAIL%s\t%s\n' "${RED}" "${RESET}" 'no Go packages'
exit 1
fi
TMP="$(mktemp -d -t 'strcase.XXXXXX')"
trap 'rm -r "${TMP}"' EXIT
for pkg in "${PACKAGES[@]}"; do
out="${TMP}/${pkg//\//_}"
# Run tests in parallel in a sub-shell
(
if ! go test -run '^$' -shuffle on -bench . -benchtime 1us "${pkg}" &>"${out}"; then
echo ''
cat "${out}"
echo ''
echo "# ${pkg}"
\grep --color=auto --after-context=1 --extended-regexp -- \
'-+ FAIL:.*' "${out}"
echo ''
printf '%sFAIL%s\t%s\n' "${RED}" "${RESET}" "${pkg}"
touch "${TMP}/fail"
else
printf '%sok%s\t%s\n' "${GREEN}" "${RESET}" "${pkg}"
fi
) &
done
wait
if [[ -f "${TMP}/fail" ]]; then
exit 1
fi
exit 0
|