diff options
author | Russ Cox <rsc@golang.org> | 2011-03-11 14:47:44 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-03-11 14:47:44 -0500 |
commit | 3f915f51a8d16e97ac631dfb4dd5946ca675a2b8 (patch) | |
tree | 296090b5a1d922cdddce36fc4160f8d411b57f50 /test/chan | |
parent | 8bf34e335686816f7fe7e28614b2c7a3e04e9e7c (diff) | |
download | go-3f915f51a8d16e97ac631dfb4dd5946ca675a2b8.tar.gz go-3f915f51a8d16e97ac631dfb4dd5946ca675a2b8.zip |
go code: replace closed(c) with x, ok := <-c
R=golang-dev, rog, bradfitzwork, r
CC=golang-dev
https://golang.org/cl/4243072
Diffstat (limited to 'test/chan')
-rw-r--r-- | test/chan/perm.go | 15 | ||||
-rw-r--r-- | test/chan/select3.go | 20 |
2 files changed, 24 insertions, 11 deletions
diff --git a/test/chan/perm.go b/test/chan/perm.go index c725829d13..038ff94e36 100644 --- a/test/chan/perm.go +++ b/test/chan/perm.go @@ -22,21 +22,18 @@ func main() { c <- 0 // ok <-c // ok - //TODO(rsc): uncomment when this syntax is valid for receive+check closed - // x, ok := <-c // ok - // _, _ = x, ok + x, ok := <-c // ok + _, _ = x, ok cr <- 0 // ERROR "send" <-cr // ok - //TODO(rsc): uncomment when this syntax is valid for receive+check closed - // x, ok = <-cr // ok - // _, _ = x, ok + x, ok = <-cr // ok + _, _ = x, ok cs <- 0 // ok <-cs // ERROR "receive" - ////TODO(rsc): uncomment when this syntax is valid for receive+check closed - //// x, ok = <-cs // ERROR "receive" - //// _, _ = x, ok + x, ok = <-cs // ERROR "receive" + _, _ = x, ok select { case c <- 0: // ok diff --git a/test/chan/select3.go b/test/chan/select3.go index 47941063c0..b4e8f8e4bf 100644 --- a/test/chan/select3.go +++ b/test/chan/select3.go @@ -88,12 +88,16 @@ func main() { ch <- 7 }) - // receiving (a small number of times) from a closed channel never blocks + // receiving from a closed channel never blocks testBlock(never, func() { for i := 0; i < 10; i++ { if <-closedch != 0 { panic("expected zero value when reading from closed channel") } + if x, ok := <-closedch; x != 0 || ok { + println("closedch:", x, ok) + panic("expected 0, false from closed channel") + } } }) @@ -191,12 +195,24 @@ func main() { case <-closedch: } }) + testBlock(never, func() { + select { + case x := <-closedch: + _ = x + } + }) + testBlock(never, func() { + select { + case x, ok := <-closedch: + _, _ = x, ok + } + }) testPanic(always, func() { select { case closedch <- 7: } }) - + // select should not get confused if it sees itself testBlock(always, func() { c := make(chan int) |