1
0
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:
Ian Lance Taylor 2018-11-02 16:38:11 -07:00
parent 67018e9b68
commit 5d6e8f3142
2 changed files with 13 additions and 0 deletions

View File

@ -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.

View File

@ -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.