mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
os: implement and smoketest os.Unsetenv
This commit is contained in:
+6
-2
@@ -17,8 +17,12 @@ func Setenv(key, value string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Unsetenv(_ string) error {
|
||||
return ErrNotImplemented
|
||||
func Unsetenv(key string) error {
|
||||
err := syscall.Unsetenv(key)
|
||||
if err != nil {
|
||||
return NewSyscallError("unsetenv", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func LookupEnv(key string) (string, bool) {
|
||||
|
||||
@@ -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