]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/testdir: support -godebug
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 29 Feb 2024 13:17:09 +0000 (20:17 +0700)
committerGopher Robot <gobot@golang.org>
Thu, 29 Feb 2024 23:23:40 +0000 (23:23 +0000)
Similar with what we are doing for -goexperiment.

For #65778

Change-Id: I7dda69512a3ffb491e3de31941ae1c3d34fececf
Reviewed-on: https://go-review.googlesource.com/c/go/+/568156
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/cmd/internal/testdir/testdir_test.go

index a26733d856b0c799ac4d260852a8bca2d6ca6363..6f1c56eb2dea525f33cd1d09df6389302eb7ddd7 100644 (file)
@@ -62,6 +62,7 @@ var (
        goarch       string // Target GOARCH
        cgoEnabled   bool
        goExperiment string
+       goDebug      string
 
        // dirs are the directories to look for *.go files in.
        // TODO(bradfitz): just use all directories?
@@ -100,6 +101,7 @@ func Test(t *testing.T) {
                GOOS         string
                GOARCH       string
                GOEXPERIMENT string
+               GODEBUG      string
                CGO_ENABLED  string
        }
        if err := json.NewDecoder(stdout).Decode(&env); err != nil {
@@ -112,6 +114,7 @@ func Test(t *testing.T) {
        goarch = env.GOARCH
        cgoEnabled, _ = strconv.ParseBool(env.CGO_ENABLED)
        goExperiment = env.GOEXPERIMENT
+       goDebug = env.GODEBUG
 
        common := testCommon{
                gorootTestDir: filepath.Join(testenv.GOROOT(t), "test"),
@@ -537,6 +540,7 @@ func (t test) run() error {
        }
 
        goexp := goExperiment
+       godebug := goDebug
 
        // collect flags
        for len(args) > 0 && strings.HasPrefix(args[0], "-") {
@@ -569,6 +573,14 @@ func (t test) run() error {
                        goexp += args[0]
                        runenv = append(runenv, "GOEXPERIMENT="+goexp)
 
+               case "-godebug": // set GODEBUG environment
+                       args = args[1:]
+                       if godebug != "" {
+                               godebug += ","
+                       }
+                       godebug += args[0]
+                       runenv = append(runenv, "GODEBUG="+godebug)
+
                default:
                        flags = append(flags, args[0])
                }
@@ -1014,7 +1026,7 @@ func (t test) run() error {
                runInDir = ""
                var out []byte
                var err error
-               if len(flags)+len(args) == 0 && t.goGcflagsIsEmpty() && !*linkshared && goarch == runtime.GOARCH && goos == runtime.GOOS && goexp == goExperiment {
+               if len(flags)+len(args) == 0 && t.goGcflagsIsEmpty() && !*linkshared && goarch == runtime.GOARCH && goos == runtime.GOOS && goexp == goExperiment && godebug == goDebug {
                        // If we're not using special go command flags,
                        // skip all the go command machinery.
                        // This avoids any time the go command would