github.com/letsencrypt/go@v0.0.0-20160714163537-4054769a31f6/src/syscall/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  package syscall_test
     6  
     7  import (
     8  	"fmt"
     9  	"internal/testenv"
    10  	"os"
    11  	"syscall"
    12  	"testing"
    13  )
    14  
    15  func testSetGetenv(t *testing.T, key, value string) {
    16  	err := syscall.Setenv(key, value)
    17  	if err != nil {
    18  		t.Fatalf("Setenv failed to set %q: %v", value, err)
    19  	}
    20  	newvalue, found := syscall.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 TestItoa(t *testing.T) {
    36  	// Make most negative integer: 0x8000...
    37  	i := 1
    38  	for i<<1 != 0 {
    39  		i <<= 1
    40  	}
    41  	if i >= 0 {
    42  		t.Fatal("bad math")
    43  	}
    44  	s := syscall.Itoa(i)
    45  	f := fmt.Sprint(i)
    46  	if s != f {
    47  		t.Fatalf("itoa(%d) = %s, want %s", i, s, f)
    48  	}
    49  }
    50  
    51  // Check that permuting child process fds doesn't interfere with
    52  // reporting of fork/exec status. See Issue 14979.
    53  func TestExecErrPermutedFds(t *testing.T) {
    54  	testenv.MustHaveExec(t)
    55  
    56  	attr := &os.ProcAttr{Files: []*os.File{os.Stdin, os.Stderr, os.Stdout}}
    57  	_, err := os.StartProcess("/", []string{"/"}, attr)
    58  	if err == nil {
    59  		t.Fatalf("StartProcess of invalid program returned err = nil")
    60  	}
    61  }