-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
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)