github.com/HACKERALERT/Picocrypt/src/external/sys@v0.0.0-20210609020157-e519952f829f/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  	"fmt"
    12  	"testing"
    13  
    14  	"golang.org/x/sys/unix"
    15  )
    16  
    17  func testSetGetenv(t *testing.T, key, value string) {
    18  	err := unix.Setenv(key, value)
    19  	if err != nil {
    20  		t.Fatalf("Setenv failed to set %q: %v", value, err)
    21  	}
    22  	newvalue, found := unix.Getenv(key)
    23  	if !found {
    24  		t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value)
    25  	}
    26  	if newvalue != value {
    27  		t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value)
    28  	}
    29  }
    30  
    31  func TestEnv(t *testing.T) {
    32  	testSetGetenv(t, "TESTENV", "AVALUE")
    33  	// make sure TESTENV gets set to "", not deleted
    34  	testSetGetenv(t, "TESTENV", "")
    35  }
    36  
    37  func TestItoa(t *testing.T) {
    38  	// Make most negative integer: 0x8000...
    39  	i := 1
    40  	for i<<1 != 0 {
    41  		i <<= 1
    42  	}
    43  	if i >= 0 {
    44  		t.Fatal("bad math")
    45  	}
    46  	s := unix.Itoa(i)
    47  	f := fmt.Sprint(i)
    48  	if s != f {
    49  		t.Fatalf("itoa(%d) = %s, want %s", i, s, f)
    50  	}
    51  }
    52  
    53  func TestUname(t *testing.T) {
    54  	var utsname unix.Utsname
    55  	err := unix.Uname(&utsname)
    56  	if err != nil {
    57  		t.Fatalf("Uname: %v", err)
    58  	}
    59  
    60  	t.Logf("OS: %s/%s %s", utsname.Sysname[:], utsname.Machine[:], utsname.Release[:])
    61  }
    62  
    63  // Test that this compiles. (Issue #31735)
    64  func TestStatFieldNames(t *testing.T) {
    65  	var st unix.Stat_t
    66  	var _ *unix.Timespec
    67  	_ = &st.Atim
    68  	_ = &st.Mtim
    69  	_ = &st.Ctim
    70  	_ = int64(st.Mtim.Sec)
    71  	_ = int64(st.Mtim.Nsec)
    72  }