mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-14 19:27:58 +08:00
12 lines
298 B
Go
12 lines
298 B
Go
package testutil
|
|
|
|
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) }
|
|
}
|