mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 07:07:33 -04:00
unix: small fixes for TestPipe
Check error returned by Pipe, use %v to format error values and strip trailing newlines from Errorf messages. Also move TestPipe above the test helper functions. Change-Id: Id431c8ffbcf525347cb4c138df69f92cc730f54a Reviewed-on: https://go-review.googlesource.com/c/sys/+/283592 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
73548a7a48
commit
1d4d2d3355
+42
-39
@@ -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) {
|
func TestRenameat(t *testing.T) {
|
||||||
defer chtmpdir(t)()
|
defer chtmpdir(t)()
|
||||||
|
|
||||||
@@ -896,42 +938,3 @@ func chtmpdir(t *testing.T) func() {
|
|||||||
os.RemoveAll(d)
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user