summaryrefslogtreecommitdiff
path: root/test/chan
diff options
context:
space:
mode:
Diffstat (limited to 'test/chan')
-rw-r--r--test/chan/perm.go15
-rw-r--r--test/chan/select3.go20
2 files changed, 24 insertions, 11 deletions
diff --git a/test/chan/perm.go b/test/chan/perm.go
index c725829d1..038ff94e3 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 47941063c..b4e8f8e4b 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)