introduce TDF_compare_debug, omit OBJ_TYPE_REF casts with it
[official-gcc.git] / libgo / misc / cgo / test / env.go
blobb2081b72837a02a40531387a21cbf2dd24a77e71
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package cgotest
7 /*
8 #include <stdlib.h>
9 */
10 import "C"
11 import (
12 "os"
13 "runtime"
14 "testing"
15 "unsafe"
18 // This is really an os package test but here for convenience.
19 func testSetEnv(t *testing.T) {
20 if runtime.GOOS == "windows" {
21 // Go uses SetEnvironmentVariable on windows. Howerver,
22 // C runtime takes a *copy* at process startup of thei
23 // OS environment, and stores it in environ/envp.
24 // It is this copy that getenv/putenv manipulate.
25 t.Logf("skipping test")
26 return
28 const key = "CGO_OS_TEST_KEY"
29 const val = "CGO_OS_TEST_VALUE"
30 os.Setenv(key, val)
31 keyc := C.CString(key)
32 defer C.free(unsafe.Pointer(keyc))
33 v := C.getenv(keyc)
34 if uintptr(unsafe.Pointer(v)) == 0 {
35 t.Fatal("getenv returned NULL")
37 vs := C.GoString(v)
38 if vs != val {
39 t.Fatalf("getenv() = %q; want %q", vs, val)