mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 05:23:40 +00:00
os: implement and smoketest os.Unsetenv
This commit is contained in:
@@ -7,6 +7,7 @@ package os_test
|
||||
import (
|
||||
. "os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -20,6 +21,31 @@ func TestConsistentEnviron(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnsetenv(t *testing.T) {
|
||||
const testKey = "GO_TEST_UNSETENV"
|
||||
set := func() bool {
|
||||
prefix := testKey + "="
|
||||
for _, key := range Environ() {
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
if err := Setenv(testKey, "1"); err != nil {
|
||||
t.Fatalf("Setenv: %v", err)
|
||||
}
|
||||
if !set() {
|
||||
t.Error("Setenv didn't set TestUnsetenv")
|
||||
}
|
||||
if err := Unsetenv(testKey); err != nil {
|
||||
t.Fatalf("Unsetenv: %v", err)
|
||||
}
|
||||
if set() {
|
||||
t.Fatal("Unsetenv didn't clear TestUnsetenv")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupEnv(t *testing.T) {
|
||||
const smallpox = "SMALLPOX" // No one has smallpox.
|
||||
value, ok := LookupEnv(smallpox) // Should not exist.
|
||||
|
||||
Reference in New Issue
Block a user