You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.3 KiB

  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. // +build darwin dragonfly freebsd linux netbsd openbsd solaris
  5. package unix_test
  6. import (
  7. "fmt"
  8. "testing"
  9. "golang.org/x/sys/unix"
  10. )
  11. func testSetGetenv(t *testing.T, key, value string) {
  12. err := unix.Setenv(key, value)
  13. if err != nil {
  14. t.Fatalf("Setenv failed to set %q: %v", value, err)
  15. }
  16. newvalue, found := unix.Getenv(key)
  17. if !found {
  18. t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value)
  19. }
  20. if newvalue != value {
  21. t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value)
  22. }
  23. }
  24. func TestEnv(t *testing.T) {
  25. testSetGetenv(t, "TESTENV", "AVALUE")
  26. // make sure TESTENV gets set to "", not deleted
  27. testSetGetenv(t, "TESTENV", "")
  28. }
  29. func TestItoa(t *testing.T) {
  30. // Make most negative integer: 0x8000...
  31. i := 1
  32. for i<<1 != 0 {
  33. i <<= 1
  34. }
  35. if i >= 0 {
  36. t.Fatal("bad math")
  37. }
  38. s := unix.Itoa(i)
  39. f := fmt.Sprint(i)
  40. if s != f {
  41. t.Fatalf("itoa(%d) = %s, want %s", i, s, f)
  42. }
  43. }
  44. func TestUname(t *testing.T) {
  45. var utsname unix.Utsname
  46. err := unix.Uname(&utsname)
  47. if err != nil {
  48. t.Fatalf("Uname: %v", err)
  49. }
  50. t.Logf("OS: %s/%s %s", utsname.Sysname[:], utsname.Machine[:], utsname.Release[:])
  51. }