diff --git a/src/test-go.bats b/src/test-go.bats index 0aadce1f..92d56bd2 100755 --- a/src/test-go.bats +++ b/src/test-go.bats @@ -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 } @@ -270,7 +303,6 @@ testHelloCGO() { } @test "native-hellocgo" { - add clang lld unset TARGETARCH testHelloCGO } @@ -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" { @@ -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 -} diff --git a/src/test_helper.bash b/src/test_helper.bash index f50f8b5d..21c18f97 100644 --- a/src/test_helper.bash +++ b/src/test_helper.bash @@ -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 } @@ -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() {