golang.org/x/sys@v0.20.1-0.20240517151509-673e0f94c16d/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 7 package unix_test 8 9 import ( 10 "testing" 11 12 "golang.org/x/sys/unix" 13 ) 14 15 func testSetGetenv(t *testing.T, key, value string) { 16 err := unix.Setenv(key, value) 17 if err != nil { 18 t.Fatalf("Setenv failed to set %q: %v", value, err) 19 } 20 newvalue, found := unix.Getenv(key) 21 if !found { 22 t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value) 23 } 24 if newvalue != value { 25 t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value) 26 } 27 } 28 29 func TestEnv(t *testing.T) { 30 testSetGetenv(t, "TESTENV", "AVALUE") 31 // make sure TESTENV gets set to "", not deleted 32 testSetGetenv(t, "TESTENV", "") 33 } 34 35 func TestUname(t *testing.T) { 36 var utsname unix.Utsname 37 err := unix.Uname(&utsname) 38 if err != nil { 39 t.Fatalf("Uname: %v", err) 40 } 41 42 t.Logf("OS: %s/%s %s", utsname.Sysname[:], utsname.Machine[:], utsname.Release[:]) 43 } 44 45 // Test that this compiles. (Issue #31735) 46 func TestStatFieldNames(t *testing.T) { 47 var st unix.Stat_t 48 var _ *unix.Timespec 49 _ = &st.Atim 50 _ = &st.Mtim 51 _ = &st.Ctim 52 _ = int64(st.Mtim.Sec) 53 _ = int64(st.Mtim.Nsec) 54 }