github.com/tcnksm/go@v0.0.0-20141208075154-439b32936367/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  	"syscall"
    10  	"testing"
    11  )
    12  
    13  func testSetGetenv(t *testing.T, key, value string) {
    14  	err := syscall.Setenv(key, value)
    15  	if err != nil {
    16  		t.Fatalf("Setenv failed to set %q: %v", value, err)
    17  	}
    18  	newvalue, found := syscall.Getenv(key)
    19  	if !found {
    20  		t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value)
    21  	}
    22  	if newvalue != value {
    23  		t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value)
    24  	}
    25  }
    26  
    27  func TestEnv(t *testing.T) {
    28  	testSetGetenv(t, "TESTENV", "AVALUE")
    29  	// make sure TESTENV gets set to "", not deleted
    30  	testSetGetenv(t, "TESTENV", "")
    31  }
    32  
    33  func TestItoa(t *testing.T) {
    34  	// Make most negative integer: 0x8000...
    35  	i := 1
    36  	for i<<1 != 0 {
    37  		i <<= 1
    38  	}
    39  	if i >= 0 {
    40  		t.Fatal("bad math")
    41  	}
    42  	s := syscall.Itoa(i)
    43  	f := fmt.Sprint(i)
    44  	if s != f {
    45  		t.Fatalf("itoa(%d) = %s, want %s", i, s, f)
    46  	}
    47  }