@@ -15,6 +15,8 @@ import { subTestAtCursor, testAtCursor } from '../../src/goTest';
1515import { MockExtensionContext } from '../mocks/MockContext' ;
1616import { Env } from './goplsTestEnv.utils' ;
1717import * as testUtils from '../../src/testUtils' ;
18+ import * as config from '../../src/config' ;
19+ import { MockCfg } from '../mocks/MockCfg' ;
1820
1921suite ( 'Code lenses for testing and benchmarking' , function ( ) {
2022 this . timeout ( 20000 ) ;
@@ -223,7 +225,6 @@ suite('Code lenses for testing and benchmarking', function () {
223225 type : 'go' ,
224226 request : 'launch' ,
225227 args : [ '-test.run' , '^TestSample$/^sample_test_passing$' ] ,
226- buildFlags : '' ,
227228 env : { } ,
228229 sessionID : undefined ,
229230 mode : 'test' ,
@@ -309,7 +310,6 @@ suite('Code lenses with stretchr/testify/suite', function () {
309310 type : 'go' ,
310311 request : 'launch' ,
311312 args : [ '-test.run' , '^TestExampleTestSuite$/^TestExample$' ] ,
312- buildFlags : '' ,
313313 env : { } ,
314314 sessionID : undefined ,
315315 mode : 'test' ,
@@ -337,12 +337,32 @@ suite('Code lenses with stretchr/testify/suite', function () {
337337 type : 'go' ,
338338 request : 'launch' ,
339339 args : [ '-test.run' , '^TestExampleTestSuite$/^TestExampleInAnotherFile$' ] ,
340- buildFlags : '' ,
341340 env : { } ,
342341 sessionID : undefined ,
343342 mode : 'test' ,
344343 envFile : null ,
345344 program : ''
346345 } ) ;
347346 } ) ;
348- } ) ;
347+
348+ // Regression test for golang/vscode-go#3933: build flag values that contain spaces
349+ // (e.g. -ldflags "-X k=v") must be passed as an array so delve sees each flag as a
350+ // separate argument. Joining them into a single string corrupts the value.
351+ test ( 'Debug test at cursor preserves buildFlags as array' , async ( ) => {
352+ const goConfig = new MockCfg ( {
353+ buildFlags : [ '-ldflags' , '-X github.com/org/pkg/info.version=v25.8.0' ]
354+ } ) ;
355+ sinon . stub ( config , 'getGoConfig' ) . returns ( goConfig ) ;
356+ const startDebuggingStub = sinon . stub ( vscode . debug , 'startDebugging' ) . returns ( Promise . resolve ( true ) ) ;
357+
358+ const editor = await vscode . window . showTextDocument ( vscode . Uri . file ( path . join ( testdataDir , 'suite_test.go' ) ) ) ;
359+ editor . selection = new vscode . Selection ( 25 , 4 , 25 , 4 ) ;
360+
361+ const result = await testAtCursor ( 'debug' ) ( ctx , env . goCtx ) ( [ ] ) ;
362+ assert . strictEqual ( result , true ) ;
363+
364+ assert . strictEqual ( startDebuggingStub . callCount , 1 , 'expected one call to startDebugging' ) ;
365+ const gotConfig = startDebuggingStub . getCall ( 0 ) . args [ 1 ] as vscode . DebugConfiguration ;
366+ assert . deepStrictEqual ( gotConfig . buildFlags , [ '-ldflags' , '-X github.com/org/pkg/info.version=v25.8.0' ] ) ;
367+ } ) ;
368+ } ) ;
0 commit comments