github.com/go-xe2/third@v1.0.3/golang.org/x/sys/unix/syscall_test.go (about) 1 // Copyright 2013 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. 4 5 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris 6 7 package unix_test 8 9 import ( 10 "fmt" 11 "testing" 12 13 "github.com/go-xe2/third/golang.org/x/sys/unix" 14 ) 15 16 func testSetGetenv(t *testing.T, key, value string) { 17 err := unix.Setenv(key, value) 18 if err != nil { 19 t.Fatalf("Setenv failed to set %q: %v", value, err) 20 } 21 newvalue, found := unix.Getenv(key) 22 if !found { 23 t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value) 24 } 25 if newvalue != value { 26 t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value) 27 } 28 } 29 30 func TestEnv(t *testing.T) { 31 testSetGetenv(t, "TESTENV", "AVALUE") 32 // make sure TESTENV gets set to "", not deleted 33 testSetGetenv(t, "TESTENV", "") 34 } 35 36 func TestItoa(t *testing.T) { 37 // Make most negative integer: 0x8000... 38 i := 1 39 for i<<1 != 0 { 40 i <<= 1 41 } 42 if i >= 0 { 43 t.Fatal("bad math") 44 } 45 s := unix.Itoa(i) 46 f := fmt.Sprint(i) 47 if s != f { 48 t.Fatalf("itoa(%d) = %s, want %s", i, s, f) 49 } 50 } 51 52 func TestUname(t *testing.T) { 53 var utsname unix.Utsname 54 err := unix.Uname(&utsname) 55 if err != nil { 56 t.Fatalf("Uname: %v", err) 57 } 58 59 t.Logf("OS: %s/%s %s", utsname.Sysname[:], utsname.Machine[:], utsname.Release[:]) 60 }