From c994e9c029bf8f058b64c60f1cda5f07075a5823 Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 23 Mar 2011 21:13:57 +0000 Subject: Send on a closed channel panics. Calling close on a closed channel panics. Don't limit number of receives on a closed channel. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@171364 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/testsuite/go.test/test/chan/select3.go | 14 +++++--------- gcc/testsuite/go.test/test/closedchan.go | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'gcc') diff --git a/gcc/testsuite/go.test/test/chan/select3.go b/gcc/testsuite/go.test/test/chan/select3.go index a1a2ef50b56..9877b12a98c 100644 --- a/gcc/testsuite/go.test/test/chan/select3.go +++ b/gcc/testsuite/go.test/test/chan/select3.go @@ -97,13 +97,9 @@ func main() { } }) - // sending (a small number of times) to a closed channel is not specified - // but the current implementation doesn't block: test that different - // implementations behave the same - testBlock(never, func() { - for i := 0; i < 10; i++ { - closedch <- 7 - } + // sending to a closed channel panics. + testPanic(always, func() { + closedch <- 7 }) // receiving from a non-ready channel always blocks @@ -189,13 +185,13 @@ func main() { } }) - // selects with closed channels don't block + // selects with closed channels behave like ordinary operations testBlock(never, func() { select { case <-closedch: } }) - testBlock(never, func() { + testPanic(always, func() { select { case closedch <- 7: } diff --git a/gcc/testsuite/go.test/test/closedchan.go b/gcc/testsuite/go.test/test/closedchan.go index c7c759be3b3..8126d5a4e4c 100644 --- a/gcc/testsuite/go.test/test/closedchan.go +++ b/gcc/testsuite/go.test/test/closedchan.go @@ -100,6 +100,15 @@ func (c SChan) Impl() string { return "(select)" } +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("did not panic") + } + }() + f() +} + func test1(c Chan) { // not closed until the close signal (a zero value) has been received. if c.Closed() { @@ -128,18 +137,15 @@ func test1(c Chan) { } // send should work with ,ok too: sent a value without blocking, so ok == true. - ok := c.Nbsend(1) - if !ok { - println("test1: send on closed got not ok", c.Impl()) - } + shouldPanic(func(){c.Nbsend(1)}) - // but the value should have been discarded. + // the value should have been discarded. if x := c.Recv(); x != 0 { println("test1: recv on closed got non-zero after send on closed:", x, c.Impl()) } // similarly Send. - c.Send(2) + shouldPanic(func(){c.Send(2)}) if x := c.Recv(); x != 0 { println("test1: recv on closed got non-zero after send on closed:", x, c.Impl()) } -- cgit v1.2.1