github.com/elves/elvish@v0.15.0/pkg/testutil/temp_env_test.go (about) 1 package testutil 2 3 import ( 4 "os" 5 "testing" 6 ) 7 8 func TestWithTempEnv(t *testing.T) { 9 envName := "ELVISH_TEST_ENV" 10 os.Setenv(envName, "old value") 11 12 restore := WithTempEnv(envName, "new value") 13 if os.Getenv(envName) != "new value" { 14 t.Errorf("did not set to new value") 15 } 16 restore() 17 if os.Getenv(envName) != "old value" { 18 t.Errorf("did not restore to old value") 19 } 20 }