| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
set -euo pipefail |
| 4 |
|
| 5 |
if [ -t 1 ]; then |
| 6 |
RED=$'\E[00;31m' |
| 7 |
GREEN=$'\E[00;32m' |
| 8 |
RESET=$'\E[0m' |
| 9 |
else |
| 10 |
RED='' |
| 11 |
GREEN='' |
| 12 |
RESET='' |
| 13 |
fi |
| 14 |
|
| 15 |
echo '# Testing benchmarks' |
| 16 |
|
| 17 |
if ! command -v readarray &>/dev/null; then |
| 18 |
printf '%sSKIP%s\t%s\n' "${RED}" "${RESET}" \ |
| 19 |
"readarray not supported by this verison of bash" |
| 20 |
exit 0 |
| 21 |
fi |
| 22 |
|
| 23 |
# Go packages |
| 24 |
readarray -t PACKAGES < <(go list ./...) |
| 25 |
if ((${#PACKAGES[@]} == 0)); then |
| 26 |
printf '%sFAIL%s\t%s\n' "${RED}" "${RESET}" 'no Go packages' |
| 27 |
exit 1 |
| 28 |
fi |
| 29 |
|
| 30 |
TMP="$(mktemp -d -t 'strcase.XXXXXX')" |
| 31 |
trap 'rm -r "${TMP}"' EXIT |
| 32 |
|
| 33 |
for pkg in "${PACKAGES[@]}"; do |
| 34 |
out="${TMP}/${pkg//\//_}" |
| 35 |
# Run tests in parallel in a sub-shell |
| 36 |
( |
| 37 |
if ! go test -run '^$' -shuffle on -bench . -benchtime 1us "${pkg}" &>"${out}"; then |
| 38 |
echo '' |
| 39 |
cat "${out}" |
| 40 |
echo '' |
| 41 |
echo "# ${pkg}" |
| 42 |
\grep --color=auto --after-context=1 --extended-regexp -- \ |
| 43 |
'-+ FAIL:.*' "${out}" |
| 44 |
echo '' |
| 45 |
printf '%sFAIL%s\t%s\n' "${RED}" "${RESET}" "${pkg}" |
| 46 |
touch "${TMP}/fail" |
| 47 |
else |
| 48 |
printf '%sok%s\t%s\n' "${GREEN}" "${RESET}" "${pkg}" |
| 49 |
fi |
| 50 |
) & |
| 51 |
done |
| 52 |
|
| 53 |
wait |
| 54 |
|
| 55 |
if [[ -f "${TMP}/fail" ]]; then |
| 56 |
exit 1 |
| 57 |
fi |
| 58 |
exit 0 |