Fixes #9676.
Change-Id: I32fe474cdfa09aff91daa4b10ac4df28ffdaa649
Reviewed-on: https://go-review.googlesource.com/9741
Reviewed-by: Ian Lance Taylor <iant@golang.org>
return v
}
+// LookupEnv retrieves the value of the environment variable named
+// by the key. If the variable is present in the environment the
+// value (which may be empty) is returned and the boolean is true.
+// Otherwise the returned value will be empty and the boolean will
+// be false.
+func LookupEnv(key string) (string, bool) {
+ return syscall.Getenv(key)
+}
+
// Setenv sets the value of the environment variable named by the key.
// It returns an error, if any.
func Setenv(key, value string) error {
t.Fatal("Unsetenv didn't clear TestUnsetenv")
}
}
+
+func TestLookupEnv(t *testing.T) {
+ value, ok := LookupEnv("GOROOT") // Should be set.
+ if !ok {
+ t.Errorf("GOROOT is not set")
+ }
+ const v = "Variable That Does Not Exist"
+ value, ok = LookupEnv(v) // Should not be set.
+ if ok || value != "" {
+ t.Errorf("%s is set: %q", v, value)
+ }
+}