3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test the cap predeclared function applied to channels.
18 const ptrSize = unsafe.Sizeof((*byte)(nil))
22 if len(c) != 0 || cap(c) != 10 {
23 println("chan len/cap ", len(c), cap(c), " want 0 10")
27 for i := 0; i < 3; i++ {
30 if len(c) != 3 || cap(c) != 10 {
31 println("chan len/cap ", len(c), cap(c), " want 3 10")
36 if len(c) != 0 || cap(c) != 0 {
37 println("chan len/cap ", len(c), cap(c), " want 0 0")
42 shouldPanic("makechan: size out of range", func() { _ = make(T, n) })
43 shouldPanic("makechan: size out of range", func() { _ = make(T, int64(n)) })
45 // Test mem > maxAlloc
46 var n2 int64 = 1 << 59
47 shouldPanic("makechan: size out of range", func() { _ = make(T, int(n2)) })
48 // Test elem.size*cap overflow
50 shouldPanic("makechan: size out of range", func() { _ = make(T, int(n2)) })
53 shouldPanic("makechan: size out of range", func() { _ = make(T, n) })
54 shouldPanic("makechan: size out of range", func() { _ = make(T, int64(n)) })
58 func shouldPanic(str string, f func()) {
62 panic("did not panic")
64 s := err.(error).Error()
65 if !strings.Contains(s, str) {
66 panic("got panic " + s + ", want " + str)