@@ -18,7 +18,7 @@ import { FolderContext } from "@src/FolderContext";
1818import  {  Product ,  SwiftPackage  }  from  "@src/SwiftPackage" ; 
1919import  configuration ,  {  FolderConfiguration  }  from  "@src/configuration" ; 
2020import  {  SWIFT_LAUNCH_CONFIG_TYPE  }  from  "@src/debugger/debugAdapter" ; 
21- import  {  makeDebugConfigurations  }  from  "@src/debugger/launch" ; 
21+ import  {  makeDebugConfigurations ,   swiftPrelaunchBuildTaskArguments  }  from  "@src/debugger/launch" ; 
2222
2323import  { 
2424    MockedObject , 
@@ -301,3 +301,151 @@ suite("Launch Configurations Test", () => {
301301        expect ( mockLaunchWSConfig . update ) . to . not . have . been . called ; 
302302    } ) ; 
303303} ) ; 
304+ 
305+ suite ( "Swift PreLaunch Build Task Arguments Test" ,  ( )  =>  { 
306+     const  mockTasks  =  mockGlobalObject ( vscode ,  "tasks" ) ; 
307+ 
308+     setup ( ( )  =>  { 
309+         // Reset mocks before each test 
310+         mockTasks . fetchTasks . reset ( ) ; 
311+     } ) ; 
312+ 
313+     test ( "swiftPrelaunchBuildTaskArguments returns task args for Swift build task" ,  async  ( )  =>  { 
314+         const  expectedArgs  =  [ "build" ,  "--product" ,  "executable" ,  "--build-system" ] ; 
315+         const  mockTask  =  mockObject < vscode . Task > ( { 
316+             name : "swift: Build Debug executable" , 
317+             definition : { 
318+                 type : "swift" , 
319+                 args : expectedArgs , 
320+             } , 
321+             scope : vscode . TaskScope . Workspace , 
322+             source : "swift" , 
323+             isBackground : false , 
324+             presentationOptions : { } , 
325+             problemMatchers : [ ] , 
326+             runOptions : { } , 
327+         } ) ; 
328+ 
329+         mockTasks . fetchTasks . resolves ( [ instance ( mockTask ) ] ) ; 
330+ 
331+         const  launchConfig : vscode . DebugConfiguration  =  { 
332+             type : "swift" , 
333+             request : "launch" , 
334+             name : "Debug executable" , 
335+             preLaunchTask : "swift: Build Debug executable" , 
336+         } ; 
337+ 
338+         const  result  =  await  swiftPrelaunchBuildTaskArguments ( launchConfig ) ; 
339+         expect ( result ) . to . deep . equal ( expectedArgs ) ; 
340+     } ) ; 
341+ 
342+     test ( "swiftPrelaunchBuildTaskArguments returns undefined for non-Swift task" ,  async  ( )  =>  { 
343+         const  mockTask  =  mockObject < vscode . Task > ( { 
344+             name : "npm: build" , 
345+             definition : { 
346+                 type : "npm" , 
347+                 args : [ "run" ,  "build" ] , 
348+             } , 
349+             scope : vscode . TaskScope . Workspace , 
350+             source : "npm" , 
351+             isBackground : false , 
352+             presentationOptions : { } , 
353+             problemMatchers : [ ] , 
354+             runOptions : { } , 
355+         } ) ; 
356+ 
357+         mockTasks . fetchTasks . resolves ( [ instance ( mockTask ) ] ) ; 
358+ 
359+         const  launchConfig : vscode . DebugConfiguration  =  { 
360+             type : "swift" , 
361+             request : "launch" , 
362+             name : "Debug executable" , 
363+             preLaunchTask : "npm: build" , 
364+         } ; 
365+ 
366+         const  result  =  await  swiftPrelaunchBuildTaskArguments ( launchConfig ) ; 
367+         expect ( result ) . to . be . undefined ; 
368+     } ) ; 
369+ 
370+     test ( "swiftPrelaunchBuildTaskArguments returns undefined for Swift task without build arg" ,  async  ( )  =>  { 
371+         const  mockTask  =  mockObject < vscode . Task > ( { 
372+             name : "swift: Test" , 
373+             definition : { 
374+                 type : "swift" , 
375+                 args : [ "test" ,  "--build-system" ] , 
376+             } , 
377+             scope : vscode . TaskScope . Workspace , 
378+             source : "swift" , 
379+             isBackground : false , 
380+             presentationOptions : { } , 
381+             problemMatchers : [ ] , 
382+             runOptions : { } , 
383+         } ) ; 
384+ 
385+         mockTasks . fetchTasks . resolves ( [ instance ( mockTask ) ] ) ; 
386+ 
387+         const  launchConfig : vscode . DebugConfiguration  =  { 
388+             type : "swift" , 
389+             request : "launch" , 
390+             name : "Debug executable" , 
391+             preLaunchTask : "swift: Test" , 
392+         } ; 
393+ 
394+         const  result  =  await  swiftPrelaunchBuildTaskArguments ( launchConfig ) ; 
395+         expect ( result ) . to . be . undefined ; 
396+     } ) ; 
397+ 
398+     test ( "swiftPrelaunchBuildTaskArguments returns undefined for launch config without preLaunchTask" ,  async  ( )  =>  { 
399+         const  launchConfig : vscode . DebugConfiguration  =  { 
400+             type : "swift" , 
401+             request : "launch" , 
402+             name : "Debug executable" , 
403+         } ; 
404+ 
405+         const  result  =  await  swiftPrelaunchBuildTaskArguments ( launchConfig ) ; 
406+         expect ( result ) . to . be . undefined ; 
407+     } ) ; 
408+ 
409+     test ( "swiftPrelaunchBuildTaskArguments handles errors gracefully" ,  async  ( )  =>  { 
410+         mockTasks . fetchTasks . rejects ( new  Error ( "Failed to fetch tasks" ) ) ; 
411+ 
412+         const  launchConfig : vscode . DebugConfiguration  =  { 
413+             type : "swift" , 
414+             request : "launch" , 
415+             name : "Debug executable" , 
416+             preLaunchTask : "swift: Build Debug executable" , 
417+         } ; 
418+ 
419+         const  result  =  await  swiftPrelaunchBuildTaskArguments ( launchConfig ) ; 
420+         expect ( result ) . to . be . undefined ; 
421+     } ) ; 
422+ 
423+     test ( "swiftPrelaunchBuildTaskArguments handles task name variations" ,  async  ( )  =>  { 
424+         const  expectedArgs  =  [ "build" ,  "--product" ,  "executable" ,  "--build-system" ] ; 
425+         const  mockTask  =  mockObject < vscode . Task > ( { 
426+             name : "Build Debug executable" , 
427+             definition : { 
428+                 type : "swift" , 
429+                 args : expectedArgs , 
430+             } , 
431+             scope : vscode . TaskScope . Workspace , 
432+             source : "swift" , 
433+             isBackground : false , 
434+             presentationOptions : { } , 
435+             problemMatchers : [ ] , 
436+             runOptions : { } , 
437+         } ) ; 
438+ 
439+         mockTasks . fetchTasks . resolves ( [ instance ( mockTask ) ] ) ; 
440+ 
441+         const  launchConfig : vscode . DebugConfiguration  =  { 
442+             type : "swift" , 
443+             request : "launch" , 
444+             name : "Debug executable" , 
445+             preLaunchTask : "swift: Build Debug executable" , 
446+         } ; 
447+ 
448+         const  result  =  await  swiftPrelaunchBuildTaskArguments ( launchConfig ) ; 
449+         expect ( result ) . to . deep . equal ( expectedArgs ) ; 
450+     } ) ; 
451+ } ) ; 
0 commit comments