mirror of
https://github.com/golang/go
synced 2024-11-12 09:20:22 -07:00
cmd/go: add goversion environment variable to testing script language
Updates #28221 Change-Id: I8a1e352cd9122bce200d45c6b19955cb50308d71 Reviewed-on: https://go-review.googlesource.com/c/147280 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
67018e9b68
commit
5d6e8f3142
@ -11,6 +11,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"go/build"
|
||||
"internal/testenv"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -104,6 +105,7 @@ func (ts *testScript) setup() {
|
||||
"GOROOT=" + testGOROOT,
|
||||
tempEnvName() + "=" + filepath.Join(ts.workdir, "tmp"),
|
||||
"devnull=" + os.DevNull,
|
||||
"goversion=" + goVersion(ts),
|
||||
":=" + string(os.PathListSeparator),
|
||||
}
|
||||
|
||||
@ -130,6 +132,16 @@ func (ts *testScript) setup() {
|
||||
}
|
||||
}
|
||||
|
||||
// goVersion returns the current Go version.
|
||||
func goVersion(ts *testScript) string {
|
||||
tags := build.Default.ReleaseTags
|
||||
version := tags[len(tags)-1]
|
||||
if !regexp.MustCompile(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`).MatchString(version) {
|
||||
ts.fatalf("invalid go version %q", version)
|
||||
}
|
||||
return version[2:]
|
||||
}
|
||||
|
||||
var execCache par.Cache
|
||||
|
||||
// run runs the test script.
|
||||
|
1
src/cmd/go/testdata/script/README
vendored
1
src/cmd/go/testdata/script/README
vendored
@ -36,6 +36,7 @@ Scripts also have access to these other environment variables:
|
||||
PATH=<actual PATH>
|
||||
TMPDIR=$WORK/tmp
|
||||
devnull=<value of os.DevNull>
|
||||
goversion=<current Go version; for example, 1.12>
|
||||
|
||||
The environment variable $exe (lowercase) is an empty string on most systems, ".exe" on Windows.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user