1// run
2
3// Copyright 2018 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.
6
7package main
8
9import (
10	"strings"
11)
12
13type T struct{}
14
15const maxInt = int(^uint(0) >> 1)
16
17func main() {
18	s := make([]T, maxInt)
19	shouldPanic("len out of range", func() { s = append(s, T{}) })
20	var oneElem = make([]T, 1)
21	shouldPanic("len out of range", func() { s = append(s, oneElem...) })
22}
23
24func shouldPanic(str string, f func()) {
25	defer func() {
26		err := recover()
27		if err == nil {
28			panic("did not panic")
29		}
30		s := err.(error).Error()
31		if !strings.Contains(s, str) {
32			panic("got panic " + s + ", want " + str)
33		}
34	}()
35
36	f()
37}
38