GoPLS Viewer

Home|gopls/internal/stack/stack_test.go
1// Copyright 2020 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package stack_test
6
7import (
8    "bytes"
9    "strings"
10    "testing"
11
12    "golang.org/x/tools/internal/stack"
13)
14
15func TestProcess(t *testing.T) {
16    for _test := range []struct{ nameinputexpect string }{{
17        name:   `empty`,
18        input:  ``,
19        expect``,
20    }, {
21        name:  `no_frame`,
22        input`goroutine 1 [running]:`,
23        expect`
24[running]: $1
25
261 goroutines, 1 unique
27`,
28    }, {
29        name`one_frame`,
30        input`
31goroutine 1 [running]:
32package.function(args)
33    file.go:10
34`,
35        expect`
36[running]: $1
37file.go:10: function
38
391 goroutines, 1 unique
40`,
41    }, {
42        name`one_call`,
43        input`
44goroutine 1 [running]:
45package1.functionA(args)
46    file1.go:10
47package2.functionB(args)
48    file2.go:20
49package3.functionC(args)
50    file3.go:30
51`,
52        expect`
53[running]: $1
54file1.go:10: functionA
55file2.go:20: functionB
56file3.go:30: functionC
57
581 goroutines, 1 unique
59`,
60    }, {
61        name`two_call`,
62        input`
63goroutine 1 [running]:
64package1.functionA(args)
65    file1.go:10
66goroutine 2 [running]:
67package2.functionB(args)
68    file2.go:20
69`,
70        expect`
71[running]: $1
72file1.go:10: functionA
73
74[running]: $2
75file2.go:20: functionB
76
772 goroutines, 2 unique
78`,
79    }, {
80        name`merge_call`,
81        input`
82goroutine 1 [running]:
83package1.functionA(args)
84    file1.go:10
85goroutine 2 [running]:
86package1.functionA(args)
87    file1.go:10
88`,
89        expect`
90[running]: $1, $2
91file1.go:10: functionA
92
932 goroutines, 1 unique
94`,
95    }, {
96        name`alternating_call`,
97        input`
98goroutine 1 [running]:
99package1.functionA(args)
100    file1.go:10
101goroutine 2 [running]:
102package2.functionB(args)
103    file2.go:20
104goroutine 3 [running]:
105package1.functionA(args)
106    file1.go:10
107goroutine 4 [running]:
108package2.functionB(args)
109    file2.go:20
110goroutine 5 [running]:
111package1.functionA(args)
112    file1.go:10
113goroutine 6 [running]:
114package2.functionB(args)
115    file2.go:20
116`,
117        expect`
118[running]: $1, $3, $5
119file1.go:10: functionA
120
121[running]: $2, $4, $6
122file2.go:20: functionB
123
1246 goroutines, 2 unique
125`,
126    }, {
127        name`sort_calls`,
128        input`
129goroutine 1 [running]:
130package3.functionC(args)
131    file3.go:30
132goroutine 2 [running]:
133package2.functionB(args)
134    file2.go:20
135goroutine 3 [running]:
136package1.functionA(args)
137    file1.go:10
138`,
139        expect`
140[running]: $3
141file1.go:10: functionA
142
143[running]: $2
144file2.go:20: functionB
145
146[running]: $1
147file3.go:30: functionC
148
1493 goroutines, 3 unique
150`,
151    }, {
152        name`real_single`,
153        input`
154panic: oops
155
156goroutine 53 [running]:
157golang.org/x/tools/internal/jsonrpc2_test.testHandler.func1(0x1240c20, 0xc000013350, 0xc0000133b0, 0x1240ca0, 0xc00002ab00, 0x3, 0x3)
158    /work/tools/internal/jsonrpc2/jsonrpc2_test.go:160 +0x74c
159golang.org/x/tools/internal/jsonrpc2.(*Conn).Run(0xc000204330, 0x1240c20, 0xc000204270, 0x1209570, 0xc000212120, 0x1242700)
160    /work/tools/internal/jsonrpc2/jsonrpc2.go:187 +0x777
161golang.org/x/tools/internal/jsonrpc2_test.run.func1(0x123ebe0, 0xc000206018, 0x123ec20, 0xc000206010, 0xc0002080a0, 0xc000204330, 0x1240c20, 0xc000204270, 0xc000212120)
162    /work/tools/internal/jsonrpc2/jsonrpc2_test.go:131 +0xe2
163created by golang.org/x/tools/internal/jsonrpc2_test.run
164    /work/tools/internal/jsonrpc2/jsonrpc2_test.go:121 +0x263
165FAIL    golang.org/x/tools/internal/jsonrpc2    0.252s
166FAIL
167`,
168        expect`
169panic: oops
170
171[running]: $53
172/work/tools/internal/jsonrpc2/jsonrpc2_test.go:160: testHandler.func1
173/work/tools/internal/jsonrpc2/jsonrpc2.go:187:      (*Conn).Run
174/work/tools/internal/jsonrpc2/jsonrpc2_test.go:131: run.func1
175/work/tools/internal/jsonrpc2/jsonrpc2_test.go:121: run
176
1771 goroutines, 1 unique
178
179FAIL    golang.org/x/tools/internal/jsonrpc2    0.252s
180FAIL
181`,
182    }} {
183        t.Run(test.name, func(t *testing.T) {
184            buf := &bytes.Buffer{}
185            stack.Process(bufstrings.NewReader(test.input))
186            expect := strings.TrimSpace(test.expect)
187            got := strings.TrimSpace(buf.String())
188            if got != expect {
189                t.Errorf("got:\n%s\nexpect:\n%s"gotexpect)
190            }
191        })
192    }
193}
194
MembersX
strings
stack
TestProcess.RangeStmt_296.test
TestProcess.RangeStmt_296.BlockStmt.BlockStmt.buf
TestProcess.RangeStmt_296.BlockStmt.BlockStmt.got
testing
TestProcess
TestProcess.t
TestProcess.RangeStmt_296.BlockStmt.BlockStmt.expect
Members
X