]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add goversion environment variable to testing script language
authorIan Lance Taylor <iant@golang.org>
Fri, 2 Nov 2018 23:38:11 +0000 (16:38 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 8 Nov 2018 01:56:34 +0000 (01:56 +0000)
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>
src/cmd/go/script_test.go
src/cmd/go/testdata/script/README

index bad0d48f37e143240fe5e5dd90e77b9c2b1ae069..31ddf02fb0a00b93138b51fdacf886be6d5a8b43 100644 (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.
index 73858103fd8e273f4de256015f6f315d7d4a4d58..22124b9fb89c663d569b85043b8510cb409f409d 100644 (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.