diff options
author | Brad Fitzpatrick <bradfitz@golang.org> | 2011-05-02 12:38:13 -0700 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2011-05-02 12:38:13 -0700 |
commit | 79142b3db0805babde269f7f889e0e098a2b6486 (patch) | |
tree | d2459d5594edbe7f370406b8a1cfc79beb791e63 /misc | |
parent | 91707067183b6829763fd88e7a1c845eab596214 (diff) | |
download | go-79142b3db0805babde269f7f889e0e098a2b6486.tar.gz |
os: make Setenv update C environment variables
Fixes issue 1569
R=rsc, bradfitzwork
CC=golang-dev
http://codereview.appspot.com/4456045
Diffstat (limited to 'misc')
-rw-r--r-- | misc/cgo/test/Makefile | 1 | ||||
-rw-r--r-- | misc/cgo/test/cgo_test.go | 1 | ||||
-rw-r--r-- | misc/cgo/test/env.go | 34 |
3 files changed, 36 insertions, 0 deletions
diff --git a/misc/cgo/test/Makefile b/misc/cgo/test/Makefile index 893540d97..43c45f416 100644 --- a/misc/cgo/test/Makefile +++ b/misc/cgo/test/Makefile @@ -10,6 +10,7 @@ CGOFILES=\ align.go\ basic.go\ callback.go\ + env.go\ issue1222.go\ issue1328.go\ issue1560.go\ diff --git a/misc/cgo/test/cgo_test.go b/misc/cgo/test/cgo_test.go index e23da1577..94fba15db 100644 --- a/misc/cgo/test/cgo_test.go +++ b/misc/cgo/test/cgo_test.go @@ -25,3 +25,4 @@ func TestZeroArgCallback(t *testing.T) { testZeroArgCallback(t) } func TestBlocking(t *testing.T) { testBlocking(t) } func Test1328(t *testing.T) { test1328(t) } func TestParallelSleep(t *testing.T) { testParallelSleep(t) } +func TestSetEnv(t *testing.T) { testSetEnv(t) } diff --git a/misc/cgo/test/env.go b/misc/cgo/test/env.go new file mode 100644 index 000000000..53e80c7c4 --- /dev/null +++ b/misc/cgo/test/env.go @@ -0,0 +1,34 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package cgotest + +/* +#include <stdlib.h> +*/ +import "C" +import ( + "os" + "testing" + "unsafe" +) + +// This is really an os package test but here for convenience. +func testSetEnv(t *testing.T) { + const key = "CGO_OS_TEST_KEY" + const val = "CGO_OS_TEST_VALUE" + os.Setenv(key, val) + keyc := C.CString(key) + defer C.free(unsafe.Pointer(keyc)) + v := C.getenv(keyc) + if v == (*C.char)(unsafe.Pointer(uintptr(0))) { + t.Fatal("getenv returned NULL") + } + vs := C.GoString(v) + if vs != val { + t.Fatalf("getenv() = %q; want %q", vs, val) + } +} + + |