unix: fix infinite recursion in itoa

Bring in http://golang.org/cl/138650044 from syscall package.

Change-Id: I554b0b31b981c682b6826644564971321a55c9e4
Reviewed-on: https://go-review.googlesource.com/10030
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Ian Lance Taylor
2015-05-13 20:12:53 +00:00
parent 3dec8fc77c
commit 082a6a3a8b
3 changed files with 29 additions and 1 deletions
+17
View File
@@ -7,6 +7,7 @@
package unix_test
import (
"fmt"
"testing"
"golang.org/x/sys/unix"
@@ -31,3 +32,19 @@ func TestEnv(t *testing.T) {
// make sure TESTENV gets set to "", not deleted
testSetGetenv(t, "TESTENV", "")
}
func TestItoa(t *testing.T) {
// Make most negative integer: 0x8000...
i := 1
for i<<1 != 0 {
i <<= 1
}
if i >= 0 {
t.Fatal("bad math")
}
s := unix.Itoa(i)
f := fmt.Sprint(i)
if s != f {
t.Fatalf("itoa(%d) = %s, want %s", i, s, f)
}
}