You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.5 KiB
Plaintext
110 lines
3.5 KiB
Plaintext
3 years ago
|
# We use a simple Go program to report many Go versions.
|
||
|
# The program also errors on any command other than "go version",
|
||
|
# which saves us having to rebuild main.go many times.
|
||
|
go build -o .bin/go$exe ./fakego
|
||
3 years ago
|
env PATH=${WORK}/.bin${:}${PATH}
|
||
4 years ago
|
|
||
3 years ago
|
# An empty go version.
|
||
2 years ago
|
env TOOLCHAIN_GOVERSION=''
|
||
4 years ago
|
! garble build
|
||
2 years ago
|
stderr 'Go version is too old; please upgrade to Go 1\.18\.x or newer'
|
||
4 years ago
|
|
||
3 years ago
|
# We should error on a devel version that's too old.
|
||
3 years ago
|
# Note that they lacked the "goN.M-" prefix.
|
||
2 years ago
|
env TOOLCHAIN_GOVERSION='devel +afb5fca Sun Aug 07 00:00:00 2020 +0000'
|
||
4 years ago
|
! garble build
|
||
2 years ago
|
stderr 'Go version is too old; please upgrade to Go 1\.18\.x or newer'
|
||
4 years ago
|
|
||
3 years ago
|
# Another form of old version; with an old "goN.M-" prefix.
|
||
2 years ago
|
env TOOLCHAIN_GOVERSION='devel go1.15-afb5fca Sun Aug 07 00:00:00 2020 +0000'
|
||
3 years ago
|
! garble build
|
||
2 years ago
|
stderr 'Go version "devel go1\.15-.*2020.*" is too old; please upgrade to Go 1\.18\.x'
|
||
3 years ago
|
|
||
2 years ago
|
# A current devel version should be fine.
|
||
|
# Note that we don't look at devel version timestamps.
|
||
|
env GARBLE_TEST_GOVERSION='go1.18'
|
||
|
env TOOLCHAIN_GOVERSION='devel go1.18-ad97d204f0 Sun Sep 12 16:46:58 2021 +0000'
|
||
4 years ago
|
! garble build
|
||
3 years ago
|
stderr 'mocking the real build'
|
||
4 years ago
|
|
||
3 years ago
|
# We should error on a stable version that's too old.
|
||
2 years ago
|
env TOOLCHAIN_GOVERSION='go1.14'
|
||
4 years ago
|
! garble build
|
||
2 years ago
|
stderr 'Go version "go1\.14" is too old; please upgrade to Go 1\.18\.x or newer'
|
||
4 years ago
|
|
||
3 years ago
|
# We should accept a future stable version.
|
||
2 years ago
|
# Note that we need to bump the version of Go that supposedly built it, too.
|
||
|
env GARBLE_TEST_GOVERSION='go1.28.2'
|
||
|
env TOOLCHAIN_GOVERSION='go1.28.2'
|
||
4 years ago
|
! garble build
|
||
3 years ago
|
stderr 'mocking the real build'
|
||
|
|
||
3 years ago
|
# We should accept custom devel strings.
|
||
2 years ago
|
env TOOLCHAIN_GOVERSION='devel go1.18-somecustomversion'
|
||
|
! garble build
|
||
|
stderr 'mocking the real build'
|
||
|
|
||
|
# The current toolchain may be older than the one that built garble.
|
||
2 years ago
|
env GARBLE_TEST_GOVERSION='go1.19'
|
||
|
env TOOLCHAIN_GOVERSION='go1.18.3'
|
||
2 years ago
|
! garble build
|
||
|
stderr 'mocking the real build'
|
||
|
|
||
|
# The current toolchain may be equal to the one that built garble.
|
||
|
env GARBLE_TEST_GOVERSION='devel go1.19-6673d5d701 Sun Mar 20 16:05:03 2022 +0000'
|
||
|
env TOOLCHAIN_GOVERSION='devel go1.19-6673d5d701 Sun Mar 20 16:05:03 2022 +0000'
|
||
|
! garble build
|
||
|
stderr 'mocking the real build'
|
||
|
|
||
|
# The current toolchain must not be newer than the one that built garble.
|
||
2 years ago
|
env GARBLE_TEST_GOVERSION='go1.18'
|
||
|
env TOOLCHAIN_GOVERSION='go1.19.1'
|
||
2 years ago
|
! garble build
|
||
2 years ago
|
stderr 'garble was built with "go1\.18" and is being used with "go1\.19\.1"; please rebuild garble with the newer version'
|
||
2 years ago
|
|
||
|
# We'll error even if the difference is a minor (bugfix) level.
|
||
|
# In practice it probably wouldn't matter, but in theory it could still lead to tricky bugs.
|
||
|
env GARBLE_TEST_GOVERSION='go1.18.11'
|
||
|
env TOOLCHAIN_GOVERSION='go1.18.14'
|
||
|
! garble build
|
||
|
stderr 'garble was built with "go1\.18\.11" and is being used with "go1\.18\.14"; please rebuild garble with the newer version'
|
||
|
|
||
|
# If garble builds itself and is then used, it won't know what version built it.
|
||
|
# As a fallback, we drop the comparison against the toolchain's version.
|
||
|
env GARBLE_TEST_GOVERSION='bogus version'
|
||
2 years ago
|
env TOOLCHAIN_GOVERSION='go1.18.3'
|
||
3 years ago
|
! garble build
|
||
|
stderr 'mocking the real build'
|
||
|
|
||
3 years ago
|
-- go.mod --
|
||
|
module test/main
|
||
4 years ago
|
|
||
2 years ago
|
go 1.18
|
||
4 years ago
|
-- main.go --
|
||
|
package main
|
||
|
|
||
3 years ago
|
func main() {}
|
||
|
|
||
|
-- fakego/main.go --
|
||
|
package main
|
||
4 years ago
|
|
||
3 years ago
|
import (
|
||
3 years ago
|
"encoding/json"
|
||
3 years ago
|
"fmt"
|
||
|
"os"
|
||
|
)
|
||
4 years ago
|
|
||
3 years ago
|
func main() {
|
||
3 years ago
|
if len(os.Args) > 0 && os.Args[1] == "env" {
|
||
|
enc, _ := json.Marshal(struct{
|
||
|
GOVERSION string
|
||
|
} {
|
||
2 years ago
|
GOVERSION: os.Getenv("TOOLCHAIN_GOVERSION"),
|
||
3 years ago
|
})
|
||
|
fmt.Printf("%s\n", enc)
|
||
3 years ago
|
return
|
||
|
}
|
||
|
fmt.Fprintln(os.Stderr, "mocking the real build")
|
||
|
os.Exit(1)
|
||
|
}
|