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.
12 "golang.org/x/tools/internal/stack"
15 func TestProcess(t *testing.T) {
16 for _, test := range []struct{ name, input, expect string }{{
22 input: `goroutine 1 [running]:`,
26 1 goroutines, 1 unique
31 goroutine 1 [running]:
32 package.function(args)
39 1 goroutines, 1 unique
44 goroutine 1 [running]:
45 package1.functionA(args)
47 package2.functionB(args)
49 package3.functionC(args)
54 file1.go:10: functionA
55 file2.go:20: functionB
56 file3.go:30: functionC
58 1 goroutines, 1 unique
63 goroutine 1 [running]:
64 package1.functionA(args)
66 goroutine 2 [running]:
67 package2.functionB(args)
72 file1.go:10: functionA
75 file2.go:20: functionB
77 2 goroutines, 2 unique
82 goroutine 1 [running]:
83 package1.functionA(args)
85 goroutine 2 [running]:
86 package1.functionA(args)
91 file1.go:10: functionA
93 2 goroutines, 1 unique
96 name: `alternating_call`,
98 goroutine 1 [running]:
99 package1.functionA(args)
101 goroutine 2 [running]:
102 package2.functionB(args)
104 goroutine 3 [running]:
105 package1.functionA(args)
107 goroutine 4 [running]:
108 package2.functionB(args)
110 goroutine 5 [running]:
111 package1.functionA(args)
113 goroutine 6 [running]:
114 package2.functionB(args)
118 [running]: $1, $3, $5
119 file1.go:10: functionA
121 [running]: $2, $4, $6
122 file2.go:20: functionB
124 6 goroutines, 2 unique
129 goroutine 1 [running]:
130 package3.functionC(args)
132 goroutine 2 [running]:
133 package2.functionB(args)
135 goroutine 3 [running]:
136 package1.functionA(args)
141 file1.go:10: functionA
144 file2.go:20: functionB
147 file3.go:30: functionC
149 3 goroutines, 3 unique
156 goroutine 53 [running]:
157 golang.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
159 golang.org/x/tools/internal/jsonrpc2.(*Conn).Run(0xc000204330, 0x1240c20, 0xc000204270, 0x1209570, 0xc000212120, 0x1242700)
160 /work/tools/internal/jsonrpc2/jsonrpc2.go:187 +0x777
161 golang.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
163 created by golang.org/x/tools/internal/jsonrpc2_test.run
164 /work/tools/internal/jsonrpc2/jsonrpc2_test.go:121 +0x263
165 FAIL golang.org/x/tools/internal/jsonrpc2 0.252s
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
177 1 goroutines, 1 unique
179 FAIL golang.org/x/tools/internal/jsonrpc2 0.252s
183 t.Run(test.name, func(t *testing.T) {
184 buf := &bytes.Buffer{}
185 stack.Process(buf, strings.NewReader(test.input))
186 expect := strings.TrimSpace(test.expect)
187 got := strings.TrimSpace(buf.String())
189 t.Errorf("got:\n%s\nexpect:\n%s", got, expect)