Skip to content

os,os/exec: should Environ record environment variables in the test log? #60057

@bcmills

Description

@bcmills

Since CL 81895, os.Getenv and os.LookupEnv both record the keys in the test log:
https://cs.opensource.google/go/go/+/master:src/os/env.go;l=98-115;drc=b2faff18ce28edad98303d2c3134dec1331fd7b5

However, os.Environ does not:
https://cs.opensource.google/go/go/+/master:src/os/env.go;l=137-141;drc=b2faff18ce28edad98303d2c3134dec1331fd7b5

This means that, for example, a program that iterates over os.Environ() looking for keys has different caching behavior than one that calls LookupEnv on those exact same keys. This difference is especially pronounced in tests that execute subprocesses, because the variables accessed by the subprocess (which may be very significant, especially in the case of libraries like golang.org/x/tools/go/packages!) do not end up recorded in the cache key.

(For example, see the odd-looking Getenv loop in testenv.GoToolPath!)

It's not obvious to me whether the difference is an intentional decision or an oversight. Either way, I think we should consider recording all keys in the test log whenever os.Environ or execenv.Default is called.

(CC @ianlancetaylor)

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions