Debian Codegraph @

gcc/testsuite/go.test/test/fixedbugs/issue36705.go

raw
1 // +build cgo
2 // run
3
4 // Copyright 2020 The Go Authors. All rights reserved.
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
7
8 package main
9
10 // #include <stdlib.h>
11 // #include <unistd.h>
12 import "C"
13
14 import "os"
15
16 func main() {
17 os.Setenv("FOO", "bar")
18 s := C.GoString(C.getenv(C.CString("FOO")))
19 if s != "bar" {
20 panic("bad setenv, environment variable only has value \"" + s + "\"")
21 }
22 os.Unsetenv("FOO")
23 s = C.GoString(C.getenv(C.CString("FOO")))
24 if s != "" {
25 panic("bad unsetenv, environment variable still has value \"" + s + "\"")
26 }
27 }