forked from travis-ci/gimme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests
executable file
·101 lines (89 loc) · 2.35 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
95
96
97
98
99
100
101
#!/usr/bin/env bash
# vim:noexpandtab:ts=2:sw=2:
set -e
set -o pipefail
main() {
local target="${1}"
shift
local go_bootstrap_version="${1}"
shift
sanity_checks "$@"
echo "---> using bootstrap version ${go_bootstrap_version}"
eval "$(./gimme "${go_bootstrap_version}")"
"_test_${target}" "$@"
}
die() {
printf >&2 '***> %s\n' "$*"
exit 1
}
can_resolve_version() {
local GIMME_TYPE='binary'
export GIMME_TYPE
local want="${1}"
local verbose="${2:-false}"
local ev r
ev=0
r="$(./gimme --resolve "${want}" 2>/dev/null)" || ev=$?
if ! [[ -n "${r}" ]]; then
die "no output resolving input version '${want}'"
fi
case $ev in
0) true ;;
2) die "failed to resolve version '${want}'" ;;
*) die "unexpected error resolving version '${want}'" ;;
esac
if $verbose; then
printf '%s\n' "${r}"
fi
}
sanity_checks() {
echo "---> doing sanity checks that all known versions resolve"
local v got
for v in ${RUNTESTS_EXTRA_RESOLVE:-}; do
can_resolve_version "$v"
done
for v in "$@" 1; do
case "${v}" in
master) continue ;;
go*) v="${v#go}" ;;
esac
[[ $v == 1 ]] || can_resolve_version "${v}"
if [[ "${v}" =~ ^[0-9.]+$ ]]; then
got="$(can_resolve_version "${v}.x" true)"
[[ "$got" =~ ^[0-9.]+$ ]] || die "resolved '${v}.x' to non-stable '${got}'"
fi
done
}
_test_native() {
for v in "${@}"; do
echo "---> eval \$(./gimme ${v})"
(
eval "$(./gimme "${v}")"
[[ "$(go env GOOS)" == "$(go env GOHOSTOS)" && "$(go env GOARCH)" == "$(go env GOHOSTARCH)" ]] || exit 1
) || exit 1
done
}
_test_arm() {
for v in "${@}"; do
echo "---> eval \$(GIMME_OS=linux GIMME_ARCH=arm ./gimme ${v})"
(
eval "$(GIMME_OS=linux GIMME_ARCH=arm ./gimme "${v}")"
[[ "$(go env GOOS)" == 'linux' && "$(go env GOARCH)" == 'arm' ]] || exit 1
) || exit 1
done
}
_test_arm64() {
for v in "${@}"; do
if [[ "$(echo "${v}" | tr -d '[:alpha:]' | tr -d '.' | cut -b1-2)" -lt 15 && "${v}" != "tip" && "${v}" != "master" ]]; then
echo "---> skipping ${v} because it probably won't work o_o"
continue
fi
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then cgo=1; else cgo=0; fi
echo "---> eval \$(GIMME_OS=linux GIMME_ARCH=arm64 GIMME_CGO_ENABLED=$cgo ./gimme $v)"
(
eval "$(GIMME_OS=linux GIMME_ARCH=arm64 GIMME_CGO_ENABLED=$cgo ./gimme "${v}")"
[[ "$(go env GOOS)" == 'linux' && "$(go env GOARCH)" == 'arm64' ]] || exit 1
) || exit 1
done
}
main "$@"