@@ -18,13 +18,6 @@ import { DebugConfiguration, DebugProtocolMessage } from 'vscode';
18
18
import { DebugClient } from '@vscode/debugadapter-testsupport' ;
19
19
import { ILocation } from '@vscode/debugadapter-testsupport/lib/debugClient' ;
20
20
import { DebugProtocol } from 'vscode-debugprotocol' ;
21
- import {
22
- Delve ,
23
- escapeGoModPath ,
24
- GoDebugSession ,
25
- PackageBuildInfo ,
26
- RemoteSourcesAndPackages
27
- } from '../../src/debugAdapter/goDebug' ;
28
21
import * as extConfig from '../../src/config' ;
29
22
import { GoDebugConfigurationProvider , parseDebugProgramArgSync } from '../../src/goDebugConfiguration' ;
30
23
import { getBinPath , rmdirRecursive } from '../../src/util' ;
@@ -37,280 +30,6 @@ import { affectedByIssue832 } from './testutils';
37
30
// For debugging test and streaming the trace instead of buffering, set this.
38
31
const PRINT_TO_CONSOLE = false ;
39
32
40
- suite ( 'Path Manipulation Tests' , ( ) => {
41
- test ( 'escapeGoModPath works' , ( ) => {
42
- assert . strictEqual ( escapeGoModPath ( 'BurnSushi/test.go' ) , '!burn!sushi/test.go' ) ;
43
- } ) ;
44
- } ) ;
45
-
46
- suite ( 'GoDebugSession Tests' , async ( ) => {
47
- const workspaceFolder = '/usr/workspacefolder' ;
48
- const delve : Delve = { } as Delve ;
49
- let goDebugSession : GoDebugSession ;
50
- let remoteSourcesAndPackages : RemoteSourcesAndPackages ;
51
- let fileSystem : typeof fs ;
52
-
53
- let previousEnv : any ;
54
-
55
- setup ( ( ) => {
56
- previousEnv = Object . assign ( { } , process . env ) ;
57
-
58
- process . env . GOPATH = '/usr/gopath' ;
59
- process . env . GOROOT = '/usr/goroot' ;
60
- remoteSourcesAndPackages = new RemoteSourcesAndPackages ( ) ;
61
- // eslint-disable-next-line prettier/prettier
62
- fileSystem = ( { existsSync : ( ) => false } as unknown ) as typeof fs ;
63
- delve . program = workspaceFolder ;
64
- delve . isApiV1 = false ;
65
- goDebugSession = new GoDebugSession ( true , false , fileSystem ) ;
66
- goDebugSession [ 'delve' ] = delve ;
67
- goDebugSession [ 'remoteSourcesAndPackages' ] = remoteSourcesAndPackages ;
68
- } ) ;
69
-
70
- teardown ( ( ) => {
71
- process . env = previousEnv ;
72
- sinon . restore ( ) ;
73
- } ) ;
74
-
75
- test ( 'inferRemotePathFromLocalPath works' , ( ) => {
76
- const sourceFileMapping = new Map < string , string [ ] > ( ) ;
77
- sourceFileMapping . set ( 'main.go' , [ '/app/hello-world/main.go' , '/app/main.go' ] ) ;
78
- sourceFileMapping . set ( 'blah.go' , [ '/app/blah.go' ] ) ;
79
-
80
- remoteSourcesAndPackages . remoteSourceFilesNameGrouping = sourceFileMapping ;
81
-
82
- const inferredPath = goDebugSession [ 'inferRemotePathFromLocalPath' ] (
83
- 'C:\\Users\\Documents\\src\\hello-world\\main.go'
84
- ) ;
85
- assert . strictEqual ( inferredPath , '/app/hello-world/main.go' ) ;
86
- } ) ;
87
-
88
- test ( 'inferRemotePathFromLocalPath does not crash due to non-existing files' , ( ) => {
89
- const sourceFileMapping = new Map < string , string [ ] > ( ) ;
90
- sourceFileMapping . set ( 'main.go' , [ '/app/hello-world/main.go' , '/app/main.go' ] ) ;
91
-
92
- remoteSourcesAndPackages . remoteSourceFilesNameGrouping = sourceFileMapping ;
93
-
94
- // Non-existing file.
95
- const inferredPath = goDebugSession [ 'inferRemotePathFromLocalPath' ] (
96
- 'C:\\Users\\Documents\\src\\hello-world\\main-copy.go'
97
- ) ;
98
- assert . strictEqual ( inferredPath , undefined ) ;
99
- } ) ;
100
-
101
- test ( 'inferLocalPathFromRemoteGoPackage works for package in workspaceFolder' , ( ) => {
102
- const remotePath = '/src/hello-world/morestrings/morestrings.go' ;
103
- const helloPackage : PackageBuildInfo = {
104
- ImportPath : 'hello-world/morestrings' ,
105
- DirectoryPath : '/src/hello-world/morestrings' ,
106
- Files : [ '/src/hello-world/morestrings/lessstrings.go' , '/src/hello-world/morestrings/morestrings.go' ]
107
- } ;
108
-
109
- const testPackage : PackageBuildInfo = {
110
- ImportPath : 'FooBar/test' ,
111
- DirectoryPath :
'remote/pkg/mod/!foo!bar/[email protected] ' ,
112
- Files :
[ 'remote/pkg/mod/!foo!bar/[email protected] /test.go' ]
113
- } ;
114
-
115
- const localPath = path . join ( workspaceFolder , 'hello-world/morestrings/morestrings.go' ) ;
116
- const existsSyncStub = sinon . stub ( fileSystem , 'existsSync' ) ;
117
- existsSyncStub . withArgs ( localPath ) . returns ( true ) ;
118
-
119
- remoteSourcesAndPackages . remotePackagesBuildInfo = [ helloPackage , testPackage ] ;
120
-
121
- goDebugSession [ 'localPathSeparator' ] = '/' ;
122
- const inferredLocalPath = goDebugSession [ 'inferLocalPathFromRemoteGoPackage' ] ( remotePath ) ;
123
- assert . strictEqual ( inferredLocalPath , localPath ) ;
124
- } ) ;
125
-
126
- test ( 'inferLocalPathFromRemoteGoPackage works for package in GOPATH/pkg/mod' , ( ) => {
127
- const remotePath = 'remote/pkg/mod/!foo!bar/[email protected] /test.go' ;
128
- const helloPackage : PackageBuildInfo = {
129
- ImportPath : 'hello-world' ,
130
- DirectoryPath : '/src/hello-world' ,
131
- Files : [ 'src/hello-world/hello.go' , 'src/hello-world/world.go' ]
132
- } ;
133
-
134
- const testPackage : PackageBuildInfo = {
135
- ImportPath : 'FooBar/test' ,
136
- DirectoryPath :
'remote/pkg/mod/!foo!bar/[email protected] ' ,
137
- Files :
[ 'remote/pkg/mod/!foo!bar/[email protected] /test.go' ]
138
- } ;
139
-
140
- const localPath = path . join ( process . env . GOPATH ?? '' , 'pkg/mod/!foo!bar/[email protected] /test.go' ) ;
141
- const existsSyncStub = sinon . stub ( fileSystem , 'existsSync' ) ;
142
- existsSyncStub . withArgs ( localPath ) . returns ( true ) ;
143
-
144
- remoteSourcesAndPackages . remotePackagesBuildInfo = [ helloPackage , testPackage ] ;
145
-
146
- goDebugSession [ 'localPathSeparator' ] = '/' ;
147
- const inferredLocalPath = goDebugSession [ 'inferLocalPathFromRemoteGoPackage' ] ( remotePath ) ;
148
- assert . strictEqual ( inferredLocalPath , localPath ) ;
149
- } ) ;
150
-
151
- test ( 'inferLocalPathFromRemoteGoPackage works for package in GOPATH/pkg/mod with relative path' , ( ) => {
152
- const remotePath = '!foo!bar/[email protected] /test.go' ;
153
- const helloPackage : PackageBuildInfo = {
154
- ImportPath : 'hello-world' ,
155
- DirectoryPath : '/src/hello-world' ,
156
- Files : [ 'src/hello-world/hello.go' , 'src/hello-world/world.go' ]
157
- } ;
158
-
159
- const testPackage : PackageBuildInfo = {
160
- ImportPath : 'FooBar/test' ,
161
- DirectoryPath :
'!foo!bar/[email protected] ' ,
162
- Files :
[ '!foo!bar/[email protected] /test.go' ]
163
- } ;
164
-
165
- const localPath = path . join ( process . env . GOPATH ?? '' , 'pkg/mod/!foo!bar/[email protected] /test.go' ) ;
166
- const existsSyncStub = sinon . stub ( fileSystem , 'existsSync' ) ;
167
- existsSyncStub . withArgs ( localPath ) . returns ( true ) ;
168
-
169
- remoteSourcesAndPackages . remotePackagesBuildInfo = [ helloPackage , testPackage ] ;
170
-
171
- goDebugSession [ 'localPathSeparator' ] = '/' ;
172
- const inferredLocalPath = goDebugSession [ 'inferLocalPathFromRemoteGoPackage' ] ( remotePath ) ;
173
- assert . strictEqual ( inferredLocalPath , localPath ) ;
174
- } ) ;
175
-
176
- test ( 'inferLocalPathFromRemoteGoPackage works for package in GOPATH/src' , ( ) => {
177
- const remotePath = 'remote/gopath/src/foobar/[email protected] /test.go' ;
178
- const helloPackage : PackageBuildInfo = {
179
- ImportPath : 'hello-world' ,
180
- DirectoryPath : '/src/hello-world' ,
181
- Files : [ 'src/hello-world/hello.go' , 'src/hello-world/world.go' ]
182
- } ;
183
-
184
- const testPackage : PackageBuildInfo = {
185
- ImportPath : 'foobar/test' ,
186
- DirectoryPath :
'remote/gopath/src/foobar/[email protected] ' ,
187
- Files :
[ 'remote/gopath/src/foobar/[email protected] /test.go' ]
188
- } ;
189
-
190
- const localPath = path . join ( process . env . GOPATH ?? '' , 'src' , 'foobar/[email protected] /test.go' ) ;
191
- const existsSyncStub = sinon . stub ( fileSystem , 'existsSync' ) ;
192
- existsSyncStub . withArgs ( localPath ) . returns ( true ) ;
193
-
194
- remoteSourcesAndPackages . remotePackagesBuildInfo = [ helloPackage , testPackage ] ;
195
-
196
- goDebugSession [ 'localPathSeparator' ] = '/' ;
197
- const inferredLocalPath = goDebugSession [ 'inferLocalPathFromRemoteGoPackage' ] ( remotePath ) ;
198
- assert . strictEqual ( inferredLocalPath , localPath ) ;
199
- } ) ;
200
-
201
- test ( 'inferLocalPathFromRemoteGoPackage works for package in GOPATH/src with relative path' , ( ) => {
202
- const remotePath = 'foobar/[email protected] /test.go' ;
203
- const helloPackage : PackageBuildInfo = {
204
- ImportPath : 'hello-world' ,
205
- DirectoryPath : '/src/hello-world' ,
206
- Files : [ 'src/hello-world/hello.go' , 'src/hello-world/world.go' ]
207
- } ;
208
-
209
- const testPackage : PackageBuildInfo = {
210
- ImportPath : 'foobar/test' ,
211
- DirectoryPath :
'foobar/[email protected] ' ,
212
- Files :
[ 'foobar/[email protected] /test.go' ]
213
- } ;
214
-
215
- const localPath = path . join ( process . env . GOPATH ?? '' , 'src' , 'foobar/[email protected] /test.go' ) ;
216
- const existsSyncStub = sinon . stub ( fileSystem , 'existsSync' ) ;
217
- existsSyncStub . withArgs ( localPath ) . returns ( true ) ;
218
-
219
- remoteSourcesAndPackages . remotePackagesBuildInfo = [ helloPackage , testPackage ] ;
220
-
221
- goDebugSession [ 'localPathSeparator' ] = '/' ;
222
- const inferredLocalPath = goDebugSession [ 'inferLocalPathFromRemoteGoPackage' ] ( remotePath ) ;
223
- assert . strictEqual ( inferredLocalPath , localPath ) ;
224
- } ) ;
225
-
226
- test ( 'inferLocalPathFromRemoteGoPackage works for package in GOROOT/src' , ( ) => {
227
- const remotePath = 'remote/goroot/src/foobar/[email protected] /test.go' ;
228
- const helloPackage : PackageBuildInfo = {
229
- ImportPath : 'hello-world' ,
230
- DirectoryPath : '/src/hello-world' ,
231
- Files : [ 'src/hello-world/hello.go' , 'src/hello-world/world.go' ]
232
- } ;
233
-
234
- const testPackage : PackageBuildInfo = {
235
- ImportPath : 'foobar/test' ,
236
- DirectoryPath :
'remote/goroot/src/foobar/[email protected] ' ,
237
- Files :
[ 'remote/goroot/src/foobar/[email protected] /test.go' ]
238
- } ;
239
-
240
- const localPath = path . join ( process . env . GOROOT ?? '' , 'src' , 'foobar/[email protected] /test.go' ) ;
241
- const existsSyncStub = sinon . stub ( fileSystem , 'existsSync' ) ;
242
- existsSyncStub . withArgs ( localPath ) . returns ( true ) ;
243
-
244
- remoteSourcesAndPackages . remotePackagesBuildInfo = [ helloPackage , testPackage ] ;
245
-
246
- goDebugSession [ 'localPathSeparator' ] = '/' ;
247
- const inferredLocalPath = goDebugSession [ 'inferLocalPathFromRemoteGoPackage' ] ( remotePath ) ;
248
- assert . strictEqual ( inferredLocalPath , localPath ) ;
249
- } ) ;
250
-
251
- test ( 'inferLocalPathFromRemoteGoPackage works for package in GOROOT/src with relative path' , ( ) => {
252
- const remotePath = 'foobar/[email protected] /test.go' ;
253
- const helloPackage : PackageBuildInfo = {
254
- ImportPath : 'hello-world' ,
255
- DirectoryPath : '/src/hello-world' ,
256
- Files : [ 'src/hello-world/hello.go' , 'src/hello-world/world.go' ]
257
- } ;
258
-
259
- const testPackage : PackageBuildInfo = {
260
- ImportPath : 'foobar/test' ,
261
- DirectoryPath :
'foobar/[email protected] ' ,
262
- Files :
[ 'foobar/[email protected] /test.go' ]
263
- } ;
264
-
265
- const localPath = path . join ( process . env . GOROOT ?? '' , 'src' , 'foobar/[email protected] /test.go' ) ;
266
- const existsSyncStub = sinon . stub ( fileSystem , 'existsSync' ) ;
267
- existsSyncStub . withArgs ( localPath ) . returns ( true ) ;
268
-
269
- remoteSourcesAndPackages . remotePackagesBuildInfo = [ helloPackage , testPackage ] ;
270
-
271
- goDebugSession [ 'localPathSeparator' ] = '/' ;
272
- const inferredLocalPath = goDebugSession [ 'inferLocalPathFromRemoteGoPackage' ] ( remotePath ) ;
273
- assert . strictEqual ( inferredLocalPath , localPath ) ;
274
- } ) ;
275
- } ) ;
276
-
277
- suite ( 'RemoteSourcesAndPackages Tests' , ( ) => {
278
- const helloPackage : PackageBuildInfo = {
279
- ImportPath : 'hello-world' ,
280
- DirectoryPath : '/src/hello-world' ,
281
- Files : [ 'src/hello-world/hello.go' , 'src/hello-world/world.go' ]
282
- } ;
283
- const testPackage : PackageBuildInfo = {
284
- ImportPath : 'test' ,
285
- DirectoryPath : '/src/test' ,
286
- Files : [ 'src/test/test.go' ]
287
- } ;
288
- const sources = [ 'src/hello-world/hello.go' , 'src/hello-world/world.go' , 'src/test/test.go' ] ;
289
- let remoteSourcesAndPackages : RemoteSourcesAndPackages ;
290
- let delve : Delve ;
291
- setup ( ( ) => {
292
- // eslint-disable-next-line prettier/prettier
293
- delve = ( { callPromise : ( ) => ( { } ) , isApiV1 : false } as unknown ) as Delve ;
294
- remoteSourcesAndPackages = new RemoteSourcesAndPackages ( ) ;
295
- } ) ;
296
-
297
- teardown ( ( ) => {
298
- sinon . restore ( ) ;
299
- } ) ;
300
-
301
- test ( 'initializeRemotePackagesAndSources retrieves remote packages and sources' , async ( ) => {
302
- const stub = sinon . stub ( delve , 'callPromise' ) ;
303
- stub . withArgs ( 'ListPackagesBuildInfo' , [ { IncludeFiles : true } ] ) . returns (
304
- Promise . resolve ( { List : [ helloPackage , testPackage ] } )
305
- ) ;
306
- stub . withArgs ( 'ListSources' , [ { } ] ) . returns ( Promise . resolve ( { Sources : sources } ) ) ;
307
-
308
- await remoteSourcesAndPackages . initializeRemotePackagesAndSources ( delve ) ;
309
- assert . deepEqual ( remoteSourcesAndPackages . remoteSourceFiles , sources ) ;
310
- assert . deepEqual ( remoteSourcesAndPackages . remotePackagesBuildInfo , [ helloPackage , testPackage ] ) ;
311
- } ) ;
312
- } ) ;
313
-
314
33
// Test suite adapted from:
315
34
// https://github.com/microsoft/vscode-mock-debug/blob/master/src/tests/adapter.test.ts
316
35
const testAll = ( ctx : Mocha . Context , isDlvDap : boolean , withConsole ?: string ) => {
0 commit comments