elvish/pkg/testutil/temp_env.go

12 lines
298 B
Go
Raw Normal View History

package testutil
2019-11-25 08:51:49 +08:00
import "os"
// WithTempEnv sets an environment variable to a temporary value, and returns a
// function for restoring the old value.
func WithTempEnv(name, value string) func() {
oldValue := os.Getenv(name)
os.Setenv(name, value)
return func() { os.Setenv(name, oldValue) }
}