mirror of
https://github.com/golang/go
synced 2024-11-18 12:44:49 -07:00
os: rewrite LookupEnv's test
GOROOT is not dependably set. When I first wrote this test, I thought it was a waste of time because the function can't fail if the other environment functions work, but I didn't want to add functionality without testing it. Of course, the test broke, and I learned something: GOROOT is not set on iOS or, to put it more broadly, the world continues to surprise me with its complexity and horror, such as a version of cat with syntax coloring. In that vein, I built this test around smallpox. Change-Id: Ifa6c218a927399d05c47954fdcaea1015e558fb6 Reviewed-on: https://go-review.googlesource.com/9791 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
f09a660eab
commit
072a26331a
@ -96,13 +96,17 @@ func TestUnsetenv(t *testing.T) {
|
||||
}
|
||||
|
||||
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.
|
||||
const smallpox = "SMALLPOX" // No one has smallpox.
|
||||
value, ok := LookupEnv(smallpox) // Should not exist.
|
||||
if ok || value != "" {
|
||||
t.Errorf("%s is set: %q", v, value)
|
||||
t.Fatalf("%s=%q", smallpox, value)
|
||||
}
|
||||
err := Setenv(smallpox, "virus")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to release smallpox virus")
|
||||
}
|
||||
value, ok = LookupEnv(smallpox)
|
||||
if !ok {
|
||||
t.Errorf("smallpox release failed; world remains safe but LookupEnv is broken")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user