blob: 846c4873d28aadda67541932ebebbd93638cdb90 [file] [log] [blame]
Alex Brainman04b405c2013-06-27 10:11:30 +10001// 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
5package syscall_test
6
7import (
Russ Coxab766382014-09-18 19:40:06 -04008 "fmt"
Alex Brainman04b405c2013-06-27 10:11:30 +10009 "syscall"
10 "testing"
11)
12
13func 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
27func TestEnv(t *testing.T) {
28 testSetGetenv(t, "TESTENV", "AVALUE")
29 // make sure TESTENV gets set to "", not deleted
30 testSetGetenv(t, "TESTENV", "")
31}
Russ Coxab766382014-09-18 19:40:06 -040032
33func 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}