github.com/Kalvelign/golang-windows-sys-lib@v0.0.0-20221121121202-63da651435e1/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 //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris 6 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris 7 8 package unix_test 9 10 import ( 11 "testing" 12 13 "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 TestUname(t *testing.T) { 37 var utsname unix.Utsname 38 err := unix.Uname(&utsname) 39 if err != nil { 40 t.Fatalf("Uname: %v", err) 41 } 42 43 t.Logf("OS: %s/%s %s", utsname.Sysname[:], utsname.Machine[:], utsname.Release[:]) 44 } 45 46 // Test that this compiles. (Issue #31735) 47 func TestStatFieldNames(t *testing.T) { 48 var st unix.Stat_t 49 var _ *unix.Timespec 50 _ = &st.Atim 51 _ = &st.Mtim 52 _ = &st.Ctim 53 _ = int64(st.Mtim.Sec) 54 _ = int64(st.Mtim.Nsec) 55 }