From 4b43913f4062f811c1c29a8b871b91877b46be52 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 29 Feb 2024 20:17:09 +0700 Subject: [PATCH] cmd/internal/testdir: support -godebug 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov Reviewed-by: Matthew Dempsky Reviewed-by: Dmitri Shuralyov --- src/cmd/internal/testdir/testdir_test.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cmd/internal/testdir/testdir_test.go b/src/cmd/internal/testdir/testdir_test.go index a26733d856b0c7..6f1c56eb2dea52 100644 --- a/src/cmd/internal/testdir/testdir_test.go +++ b/src/cmd/internal/testdir/testdir_test.go @@ -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