summaryrefslogtreecommitdiff
path: root/src/pkg/io/pipe_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-12-15 15:35:38 -0800
committerRobert Griesemer <gri@golang.org>2009-12-15 15:35:38 -0800
commite4bd81f903362d998f7bfc02095935408aff0bc5 (patch)
tree05f75a90e239d33be427da4f9c5596d2fcb3dc96 /src/pkg/io/pipe_test.go
parentd9527dd16f72598b54a64550607bf892efa12384 (diff)
downloadgolang-e4bd81f903362d998f7bfc02095935408aff0bc5.tar.gz
1) Change default gofmt default settings for
parsing and printing to new syntax. Use -oldparser to parse the old syntax, use -oldprinter to print the old syntax. 2) Change default gofmt formatting settings to use tabs for indentation only and to use spaces for alignment. This will make the code alignment insensitive to an editor's tabwidth. Use -spaces=false to use tabs for alignment. 3) Manually changed src/exp/parser/parser_test.go so that it doesn't try to parse the parser's source files using the old syntax (they have new syntax now). 4) gofmt -w src misc test/bench 3rd set of files. R=rsc CC=golang-dev http://codereview.appspot.com/180048
Diffstat (limited to 'src/pkg/io/pipe_test.go')
-rw-r--r--src/pkg/io/pipe_test.go130
1 files changed, 65 insertions, 65 deletions
diff --git a/src/pkg/io/pipe_test.go b/src/pkg/io/pipe_test.go
index df83c3ade..793bed459 100644
--- a/src/pkg/io/pipe_test.go
+++ b/src/pkg/io/pipe_test.go
@@ -5,118 +5,118 @@
package io_test
import (
- "fmt";
- . "io";
- "os";
- "strings";
- "testing";
- "time";
+ "fmt"
+ . "io"
+ "os"
+ "strings"
+ "testing"
+ "time"
)
func checkWrite(t *testing.T, w Writer, data []byte, c chan int) {
- n, err := w.Write(data);
+ n, err := w.Write(data)
if err != nil {
t.Errorf("write: %v", err)
}
if n != len(data) {
t.Errorf("short write: %d != %d", n, len(data))
}
- c <- 0;
+ c <- 0
}
// Test a single read/write pair.
func TestPipe1(t *testing.T) {
- c := make(chan int);
- r, w := Pipe();
- var buf = make([]byte, 64);
- go checkWrite(t, w, strings.Bytes("hello, world"), c);
- n, err := r.Read(buf);
+ c := make(chan int)
+ r, w := Pipe()
+ var buf = make([]byte, 64)
+ go checkWrite(t, w, strings.Bytes("hello, world"), c)
+ n, err := r.Read(buf)
if err != nil {
t.Errorf("read: %v", err)
} else if n != 12 || string(buf[0:12]) != "hello, world" {
t.Errorf("bad read: got %q", buf[0:n])
}
- <-c;
- r.Close();
- w.Close();
+ <-c
+ r.Close()
+ w.Close()
}
func reader(t *testing.T, r Reader, c chan int) {
- var buf = make([]byte, 64);
+ var buf = make([]byte, 64)
for {
- n, err := r.Read(buf);
+ n, err := r.Read(buf)
if err == os.EOF {
- c <- 0;
- break;
+ c <- 0
+ break
}
if err != nil {
t.Errorf("read: %v", err)
}
- c <- n;
+ c <- n
}
}
// Test a sequence of read/write pairs.
func TestPipe2(t *testing.T) {
- c := make(chan int);
- r, w := Pipe();
- go reader(t, r, c);
- var buf = make([]byte, 64);
+ c := make(chan int)
+ r, w := Pipe()
+ go reader(t, r, c)
+ var buf = make([]byte, 64)
for i := 0; i < 5; i++ {
- p := buf[0 : 5+i*10];
- n, err := w.Write(p);
+ p := buf[0 : 5+i*10]
+ n, err := w.Write(p)
if n != len(p) {
t.Errorf("wrote %d, got %d", len(p), n)
}
if err != nil {
t.Errorf("write: %v", err)
}
- nn := <-c;
+ nn := <-c
if nn != n {
t.Errorf("wrote %d, read got %d", n, nn)
}
}
- w.Close();
- nn := <-c;
+ w.Close()
+ nn := <-c
if nn != 0 {
t.Errorf("final read got %d", nn)
}
}
type pipeReturn struct {
- n int;
- err os.Error;
+ n int
+ err os.Error
}
// Test a large write that requires multiple reads to satisfy.
func writer(w WriteCloser, buf []byte, c chan pipeReturn) {
- n, err := w.Write(buf);
- w.Close();
- c <- pipeReturn{n, err};
+ n, err := w.Write(buf)
+ w.Close()
+ c <- pipeReturn{n, err}
}
func TestPipe3(t *testing.T) {
- c := make(chan pipeReturn);
- r, w := Pipe();
- var wdat = make([]byte, 128);
+ c := make(chan pipeReturn)
+ r, w := Pipe()
+ var wdat = make([]byte, 128)
for i := 0; i < len(wdat); i++ {
wdat[i] = byte(i)
}
- go writer(w, wdat, c);
- var rdat = make([]byte, 1024);
- tot := 0;
+ go writer(w, wdat, c)
+ var rdat = make([]byte, 1024)
+ tot := 0
for n := 1; n <= 256; n *= 2 {
- nn, err := r.Read(rdat[tot : tot+n]);
+ nn, err := r.Read(rdat[tot : tot+n])
if err != nil && err != os.EOF {
t.Fatalf("read: %v", err)
}
// only final two reads should be short - 1 byte, then 0
- expect := n;
+ expect := n
if n == 128 {
expect = 1
} else if n == 256 {
- expect = 0;
+ expect = 0
if err != os.EOF {
t.Fatalf("read at end: %v", err)
}
@@ -124,9 +124,9 @@ func TestPipe3(t *testing.T) {
if nn != expect {
t.Fatalf("read %d, expected %d, got %d", n, expect, nn)
}
- tot += nn;
+ tot += nn
}
- pr := <-c;
+ pr := <-c
if pr.n != 128 || pr.err != nil {
t.Fatalf("write 128: %d, %v", pr.n, pr.err)
}
@@ -143,14 +143,14 @@ func TestPipe3(t *testing.T) {
// Test read after/before writer close.
type closer interface {
- CloseWithError(os.Error) os.Error;
- Close() os.Error;
+ CloseWithError(os.Error) os.Error
+ Close() os.Error
}
type pipeTest struct {
- async bool;
- err os.Error;
- closeWithError bool;
+ async bool
+ err os.Error
+ closeWithError bool
}
func (p pipeTest) String() string {
@@ -167,8 +167,8 @@ var pipeTests = []pipeTest{
}
func delayClose(t *testing.T, cl closer, ch chan int, tt pipeTest) {
- time.Sleep(1e6); // 1 ms
- var err os.Error;
+ time.Sleep(1e6) // 1 ms
+ var err os.Error
if tt.closeWithError {
err = cl.CloseWithError(tt.err)
} else {
@@ -177,22 +177,22 @@ func delayClose(t *testing.T, cl closer, ch chan int, tt pipeTest) {
if err != nil {
t.Errorf("delayClose: %v", err)
}
- ch <- 0;
+ ch <- 0
}
func TestPipeReadClose(t *testing.T) {
for _, tt := range pipeTests {
- c := make(chan int, 1);
- r, w := Pipe();
+ c := make(chan int, 1)
+ r, w := Pipe()
if tt.async {
go delayClose(t, w, c, tt)
} else {
delayClose(t, w, c, tt)
}
- var buf = make([]byte, 64);
- n, err := r.Read(buf);
- <-c;
- want := tt.err;
+ var buf = make([]byte, 64)
+ n, err := r.Read(buf)
+ <-c
+ want := tt.err
if want == nil {
want = os.EOF
}
@@ -212,16 +212,16 @@ func TestPipeReadClose(t *testing.T) {
func TestPipeWriteClose(t *testing.T) {
for _, tt := range pipeTests {
- c := make(chan int, 1);
- r, w := Pipe();
+ c := make(chan int, 1)
+ r, w := Pipe()
if tt.async {
go delayClose(t, r, c, tt)
} else {
delayClose(t, r, c, tt)
}
- n, err := WriteString(w, "hello, world");
- <-c;
- expect := tt.err;
+ n, err := WriteString(w, "hello, world")
+ <-c
+ expect := tt.err
if expect == nil {
expect = os.EPIPE
}