diff --git a/unix/syscall_unix_test.go b/unix/syscall_unix_test.go index c8a75062..0639ee97 100644 --- a/unix/syscall_unix_test.go +++ b/unix/syscall_unix_test.go @@ -782,6 +782,48 @@ func TestMkdev(t *testing.T) { } } +func TestPipe(t *testing.T) { + const s = "hello" + var pipes [2]int + err := unix.Pipe(pipes[:]) + if err != nil { + t.Fatalf("pipe: %v", err) + } + r := pipes[0] + w := pipes[1] + go func() { + n, err := unix.Write(w, []byte(s)) + if err != nil { + t.Errorf("bad write: %v", err) + return + } + if n != len(s) { + t.Errorf("bad write count: %d", n) + return + } + err = unix.Close(w) + if err != nil { + t.Errorf("bad close: %v", err) + return + } + }() + var buf [10 + len(s)]byte + n, err := unix.Read(r, buf[:]) + if err != nil { + t.Fatalf("bad read: %v", err) + } + if n != len(s) { + t.Fatalf("bad read count: %d", n) + } + if string(buf[:n]) != s { + t.Fatalf("bad contents: %s", string(buf[:n])) + } + err = unix.Close(r) + if err != nil { + t.Fatalf("bad close: %v", err) + } +} + func TestRenameat(t *testing.T) { defer chtmpdir(t)() @@ -896,42 +938,3 @@ func chtmpdir(t *testing.T) func() { os.RemoveAll(d) } } - -func TestPipe(t *testing.T) { - const s = "hello" - var pipes [2]int - unix.Pipe(pipes[:]) - r := pipes[0] - w := pipes[1] - go func() { - n, err := unix.Write(w, []byte(s)) - if err != nil { - t.Errorf("bad write: %s\n", err) - return - } - if n != len(s) { - t.Errorf("bad write count: %d\n", n) - return - } - err = unix.Close(w) - if err != nil { - t.Errorf("bad close: %s\n", err) - return - } - }() - var buf [10 + len(s)]byte - n, err := unix.Read(r, buf[:]) - if err != nil { - t.Fatalf("bad read: %s\n", err) - } - if n != len(s) { - t.Fatalf("bad read count: %d\n", n) - } - if string(buf[:n]) != s { - t.Fatalf("bad contents: %s\n", string(buf[:n])) - } - err = unix.Close(r) - if err != nil { - t.Fatalf("bad close: %s\n", err) - } -}