Skip to content

Commit 5d6e8f3

Browse files
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 67018e9 commit 5d6e8f3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/cmd/go/script_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"bytes"
1212
"context"
1313
"fmt"
14+
"go/build"
1415
"internal/testenv"
1516
"io/ioutil"
1617
"os"
@@ -104,6 +105,7 @@ func (ts *testScript) setup() {
104105
"GOROOT=" + testGOROOT,
105106
tempEnvName() + "=" + filepath.Join(ts.workdir, "tmp"),
106107
"devnull=" + os.DevNull,
108+
"goversion=" + goVersion(ts),
107109
":=" + string(os.PathListSeparator),
108110
}
109111

@@ -130,6 +132,16 @@ func (ts *testScript) setup() {
130132
}
131133
}
132134

135+
// goVersion returns the current Go version.
136+
func goVersion(ts *testScript) string {
137+
tags := build.Default.ReleaseTags
138+
version := tags[len(tags)-1]
139+
if !regexp.MustCompile(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`).MatchString(version) {
140+
ts.fatalf("invalid go version %q", version)
141+
}
142+
return version[2:]
143+
}
144+
133145
var execCache par.Cache
134146

135147
// run runs the test script.

src/cmd/go/testdata/script/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Scripts also have access to these other environment variables:
3636
PATH=<actual PATH>
3737
TMPDIR=$WORK/tmp
3838
devnull=<value of os.DevNull>
39+
goversion=<current Go version; for example, 1.12>
3940

4041
The environment variable $exe (lowercase) is an empty string on most systems, ".exe" on Windows.
4142

0 commit comments

Comments
 (0)