Skip to content

Commit

Permalink
cmd/internal/testdir: support -godebug
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cuonglm authored and gopherbot committed Feb 29, 2024
1 parent b79a480 commit 4b43913
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/cmd/internal/testdir/testdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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 {
Expand All @@ -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"),
Expand Down Expand Up @@ -537,6 +540,7 @@ func (t test) run() error {
}

goexp := goExperiment
godebug := goDebug

// collect flags
for len(args) > 0 && strings.HasPrefix(args[0], "-") {
Expand Down Expand Up @@ -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])
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4b43913

Please sign in to comment.