Source file
test/fixedbugs/issue37975.go
1
2
3
4
5
6
7
8
9 package main
10
11 import "strings"
12
13 func main() {
14
15
16 var x byte
17 _ = make([]int, x, 300)
18
19 capOutOfRange := func() {
20 i := 2
21 s := make([]int, i, 1)
22 s[0] = 1
23 }
24 lenOutOfRange := func() {
25 i := -1
26 s := make([]int, i, 3)
27 s[0] = 1
28 }
29
30 tests := []struct {
31 f func()
32 panicStr string
33 }{
34 {capOutOfRange, "cap out of range"},
35 {lenOutOfRange, "len out of range"},
36 }
37
38 for _, tc := range tests {
39 shouldPanic(tc.panicStr, tc.f)
40 }
41
42 }
43
44 func shouldPanic(str string, f func()) {
45 defer func() {
46 err := recover()
47 runtimeErr := err.(error).Error()
48 if !strings.Contains(runtimeErr, str) {
49 panic("got panic " + runtimeErr + ", want " + str)
50 }
51 }()
52
53 f()
54 }
55
View as plain text