Add windows implementation of Clearenv for tests

Apparently `Clearenv` in Windows just sets the variables to ""
main
Jesse Szwedko 8 years ago
parent e367fafa3d
commit b4a64dc08d

@ -191,7 +191,7 @@ func TestContext_IsSet_fromEnv(t *testing.T) {
unparsableIsSet, uIsSet bool
)
os.Clearenv()
clearenv()
os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
os.Setenv("APP_PASSWORD", "")
a := App{
@ -256,7 +256,7 @@ func TestContext_GlobalIsSet_fromEnv(t *testing.T) {
unparsableIsSet, uIsSet bool
)
os.Clearenv()
clearenv()
os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
os.Setenv("APP_PASSWORD", "")
a := App{

@ -0,0 +1,9 @@
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
package cli
import "os"
func clearenv() {
os.Clearenv()
}

@ -0,0 +1,20 @@
package cli
import (
"os"
"syscall"
)
// os.Clearenv() doesn't actually unset variables on Windows
// See: https://github.com/golang/go/issues/17902
func clearenv() {
for _, s := range os.Environ() {
for j := 1; j < len(s); j++ {
if s[j] == '=' {
keyp, _ := syscall.UTF16PtrFromString(s[0:j])
syscall.SetEnvironmentVariable(keyp, nil)
break
}
}
}
}
Loading…
Cancel
Save