Skip to content

Commit

Permalink
Merge pull request #137 from tonistiigi/go-test-fixes
Browse files Browse the repository at this point in the history
tests: fixes for go tests
  • Loading branch information
crazy-max authored Jan 5, 2024
2 parents 263a0bd + 2a4d47b commit c4ed410
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 45 deletions.
96 changes: 55 additions & 41 deletions src/test-go.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,73 @@
load 'assert'
load 'test_helper'

@test "nogo" {
del go 2>/dev/null || true
run xx-go env
assert_failure
assert_output --partial "go: not found"
ensureGo() {
if command -v apk >/dev/null 2>/dev/null; then
add go
else
add golang
fi
add clang lld
}

setup_file() {
ensureGo
}

teardown_file() {
for p in linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6 linux/riscv64; do
TARGETPLATFORM=$p xxdel xx-c-essentials
root=/$(TARGETPLATFORM=$p xx-info triple)
if [ -d "$root" ] && [ "$root" != "/" ]; then
rm -rf "$root"
fi
done
del clang lld llvm
del pkgconfig || del pkg-config
if command -v apk >/dev/null 2>/dev/null; then
del go
else
del golang
fi
rm /tmp/a.out || true
rm -rf /var/cache/apt/*.bin || true
}

testEnv() {
run xx-go env
# single/double quotes changed in between go versions
run sh -c "xx-go env | sed 's/[\"'\'']//g'"
assert_success
assert_output --partial 'GOARCH="'"$(xx-info arch)"'"'
assert_output --partial 'GOOS="'"$(xx-info os)"'"'
assert_output --partial 'GOHOSTOS="'"$(TARGETOS= TARGETARCH= xx-info os)"'"'
assert_output --partial 'GOHOSTARCH="'"$(TARGETOS= TARGETARCH= xx-info arch)"'"'
assert_output --partial "GOARCH=$(xx-info arch)"
assert_output --partial "GOOS=$(xx-info os)"
assert_output --partial "GOHOSTOS=$(TARGETOS= TARGETARCH= xx-info os)"
assert_output --partial "GOHOSTARCH=$(TARGETOS= TARGETARCH= xx-info arch)"

case "$(xx-info arch)" in
"arm")
assert_output --partial 'GOARM="'"$expArm"'"'
assert_output --partial "GOARM=$expArm"
;;
"mips64"*)
assert_output --partial 'GOMIPS64="'"$expMips"'"'
assert_output --partial "GOMIPS64=$expMips"
;;
"mips"*)
assert_output --partial 'GOMIPS="'"$expMips"'"'
assert_output --partial "GOMIPS=$expMips"
;;
esac
}

@test "native-env" {
@test "nogo" {
if command -v apk >/dev/null 2>/dev/null; then
add go
del go
else
add golang
del golang
fi
run xx-go env
assert_failure
assert_output --partial "go: not found"
ensureGo
}

@test "native-env" {
testEnv
}

Expand Down Expand Up @@ -270,7 +303,6 @@ testHelloCGO() {
}

@test "native-hellocgo" {
add clang lld
unset TARGETARCH
testHelloCGO
}
Expand Down Expand Up @@ -319,12 +351,13 @@ testHelloCGO() {
add pkgconf || add pkg-config
xxadd xx-c-essentials
xxadd pkgconf || add pkg-config
run xx-go env
# single/double quotes changed in between go versions
run sh -c "xx-go env | sed 's/[\"'\'']//g'"
assert_success
assert_output --partial 'CC="'"$(xx-info triple)-clang"'"'
assert_output --partial 'CXX="'"$(xx-info triple)-clang++"'"'
assert_output --partial 'AR="'"$(xx-info triple)-ar"'"'
assert_output --partial 'PKG_CONFIG="'"$(xx-info triple)-pkg-config"'"'
assert_output --partial "CC=$(xx-info triple)-clang"
assert_output --partial "CXX=$(xx-info triple)-clang++"
assert_output --partial "AR=$(xx-info triple)-ar"
assert_output --partial "PKG_CONFIG=$(xx-info triple)-pkg-config"
}

@test "wrap-unwrap" {
Expand All @@ -351,22 +384,3 @@ testHelloCGO() {
assert_success
assert_output "$nativeArch"
}

@test "clean-packages" {
for p in linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6; do
TARGETPLATFORM=$p xxdel xx-c-essentials
root=/$(TARGETPLATFORM=$p xx-info triple)
if [ -d "$root" ] && [ "$root" != "/" ]; then
rm -rf "$root"
fi
done
del clang lld llvm
del pkgconfig || del pkg-config
if command -v apk >/dev/null 2>/dev/null; then
del go
else
del golang
fi
rm /tmp/a.out
rm -rf /var/cache/apt/*.bin || true
}
10 changes: 6 additions & 4 deletions src/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ xxadd() {

xxdel() {
if [ -f /etc/alpine-release ]; then
xx-apk add "$@" 2>/dev/null || true
xx-apk del "$@" 2>/dev/null || true
else
xxrun xx-apt install -y --autoremove "$@" 2>/dev/null || true
xxrun xx-apt remove -y --autoremove "$@" 2>/dev/null || true
fi
}

Expand Down Expand Up @@ -78,15 +78,17 @@ supportRiscV() {
return 0
}

versionGTE() { test "$(printf '%s\n' "$@" | sort -V | tail -n 1)" = "$1"; }

supportRiscVGo() {
go version | grep -E "1.14|1.15|1.16|1.17|1.18|1.19" >/dev/null 2>&1
versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.14"
}

supportRiscVCGo() {
if ! supportRiscV; then
return 1
fi
go version | egrep -E "1.16|1.17|1.18|1.19" >/dev/null 2>&1
versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.16"
}

supportRC() {
Expand Down

0 comments on commit c4ed410

Please sign in to comment.