@@ -162,7 +162,7 @@ suite('Application Diagnostics - Checks if launch.json is invalid', () => {
162162 const diagnostics = await diagnosticService . diagnose ( undefined ) ;
163163 expect ( diagnostics ) . to . be . deep . equal (
164164 [ new InvalidLaunchJsonDebuggerDiagnostic ( DiagnosticCodes . InvalidDebuggerTypeDiagnostic , undefined ) ] ,
165- 'not the same '
165+ 'Diagnostics returned are not as expected '
166166 ) ;
167167 workspaceService . verifyAll ( ) ;
168168 fs . verifyAll ( ) ;
@@ -187,7 +187,32 @@ suite('Application Diagnostics - Checks if launch.json is invalid', () => {
187187 const diagnostics = await diagnosticService . diagnose ( undefined ) ;
188188 expect ( diagnostics ) . to . be . deep . equal (
189189 [ new InvalidLaunchJsonDebuggerDiagnostic ( DiagnosticCodes . JustMyCodeDiagnostic , undefined ) ] ,
190- 'not the same'
190+ 'Diagnostics returned are not as expected'
191+ ) ;
192+ workspaceService . verifyAll ( ) ;
193+ fs . verifyAll ( ) ;
194+ } ) ;
195+
196+ test ( 'Should return ConfigPythonPathDiagnostic if file launch.json contains string "{config:python.pythonPath}"' , async ( ) => {
197+ const fileContents = 'Hello I am launch.json, I contain string {config:python.pythonPath}' ;
198+ workspaceService
199+ . setup ( ( w ) => w . hasWorkspaceFolders )
200+ . returns ( ( ) => true )
201+ . verifiable ( TypeMoq . Times . once ( ) ) ;
202+ workspaceService
203+ . setup ( ( w ) => w . workspaceFolders )
204+ . returns ( ( ) => [ workspaceFolder ] )
205+ . verifiable ( TypeMoq . Times . once ( ) ) ;
206+ fs . setup ( ( w ) => w . fileExists ( TypeMoq . It . isAny ( ) ) )
207+ . returns ( ( ) => Promise . resolve ( true ) )
208+ . verifiable ( TypeMoq . Times . once ( ) ) ;
209+ fs . setup ( ( w ) => w . readFile ( TypeMoq . It . isAny ( ) ) )
210+ . returns ( ( ) => Promise . resolve ( fileContents ) )
211+ . verifiable ( TypeMoq . Times . once ( ) ) ;
212+ const diagnostics = await diagnosticService . diagnose ( undefined ) ;
213+ expect ( diagnostics ) . to . be . deep . equal (
214+ [ new InvalidLaunchJsonDebuggerDiagnostic ( DiagnosticCodes . ConfigPythonPathDiagnostic , undefined , false ) ] ,
215+ 'Diagnostics returned are not as expected'
191216 ) ;
192217 workspaceService . verifyAll ( ) ;
193218 fs . verifyAll ( ) ;
@@ -215,13 +240,13 @@ suite('Application Diagnostics - Checks if launch.json is invalid', () => {
215240 new InvalidLaunchJsonDebuggerDiagnostic ( DiagnosticCodes . InvalidDebuggerTypeDiagnostic , undefined ) ,
216241 new InvalidLaunchJsonDebuggerDiagnostic ( DiagnosticCodes . JustMyCodeDiagnostic , undefined )
217242 ] ,
218- 'not the same '
243+ 'Diagnostics returned are not as expected '
219244 ) ;
220245 workspaceService . verifyAll ( ) ;
221246 fs . verifyAll ( ) ;
222247 } ) ;
223248
224- test ( 'All InvalidLaunchJsonDebugger diagnostics should display 2 options to with one command' , async ( ) => {
249+ test ( 'All InvalidLaunchJsonDebugger diagnostics with `shouldShowPrompt` set to `true` should display a prompt with 2 buttons where clicking the first button will invoke a command' , async ( ) => {
225250 for ( const code of [
226251 DiagnosticCodes . InvalidDebuggerTypeDiagnostic ,
227252 DiagnosticCodes . JustMyCodeDiagnostic ,
@@ -233,6 +258,10 @@ suite('Application Diagnostics - Checks if launch.json is invalid', () => {
233258 . setup ( ( d ) => d . code )
234259 . returns ( ( ) => code )
235260 . verifiable ( TypeMoq . Times . atLeastOnce ( ) ) ;
261+ diagnostic
262+ . setup ( ( d ) => d . shouldShowPrompt )
263+ . returns ( ( ) => true )
264+ . verifiable ( TypeMoq . Times . atLeastOnce ( ) ) ;
236265 messageHandler
237266 . setup ( ( m ) => m . handle ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
238267 . callback ( ( _ , opts : MessageCommandPrompt ) => ( options = opts ) )
@@ -254,6 +283,39 @@ suite('Application Diagnostics - Checks if launch.json is invalid', () => {
254283 }
255284 } ) ;
256285
286+ test ( 'All InvalidLaunchJsonDebugger diagnostics with `shouldShowPrompt` set to `false` should directly fix launch.json' , async ( ) => {
287+ for ( const code of [ DiagnosticCodes . ConfigPythonPathDiagnostic ] ) {
288+ let called = false ;
289+ ( diagnosticService as any ) . fixLaunchJson = ( ) => {
290+ called = true ;
291+ } ;
292+ const diagnostic = TypeMoq . Mock . ofType < IDiagnostic > ( ) ;
293+ diagnostic
294+ . setup ( ( d ) => d . code )
295+ . returns ( ( ) => code )
296+ . verifiable ( TypeMoq . Times . atLeastOnce ( ) ) ;
297+ diagnostic
298+ . setup ( ( d ) => d . shouldShowPrompt )
299+ . returns ( ( ) => false )
300+ . verifiable ( TypeMoq . Times . atLeastOnce ( ) ) ;
301+ messageHandler
302+ . setup ( ( m ) => m . handle ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
303+ . verifiable ( TypeMoq . Times . never ( ) ) ;
304+ baseWorkspaceService
305+ . setup ( ( c ) => c . getWorkspaceFolder ( TypeMoq . It . isAny ( ) ) )
306+ . returns ( ( ) => workspaceFolder )
307+ . verifiable ( TypeMoq . Times . atLeastOnce ( ) ) ;
308+
309+ await diagnosticService . handle ( [ diagnostic . object ] ) ;
310+
311+ diagnostic . verifyAll ( ) ;
312+ commandFactory . verifyAll ( ) ;
313+ messageHandler . verifyAll ( ) ;
314+ baseWorkspaceService . verifyAll ( ) ;
315+ expect ( called ) . to . equal ( true , '' ) ;
316+ }
317+ } ) ;
318+
257319 test ( 'All InvalidLaunchJsonDebugger diagnostics should display message twice if invoked twice' , async ( ) => {
258320 for ( const code of [
259321 DiagnosticCodes . InvalidDebuggerTypeDiagnostic ,
@@ -407,4 +469,29 @@ suite('Application Diagnostics - Checks if launch.json is invalid', () => {
407469 workspaceService . verifyAll ( ) ;
408470 fs . verifyAll ( ) ;
409471 } ) ;
472+
473+ test ( 'File launch.json is fixed correctly when code equals ConfigPythonPathDiagnostic ' , async ( ) => {
474+ const launchJson = 'This string contains {config:python.pythonPath}' ;
475+ const correctedlaunchJson = 'This string contains {config:python.interpreterPath}' ;
476+ workspaceService
477+ . setup ( ( w ) => w . hasWorkspaceFolders )
478+ . returns ( ( ) => true )
479+ . verifiable ( TypeMoq . Times . once ( ) ) ;
480+ workspaceService
481+ . setup ( ( w ) => w . workspaceFolders )
482+ . returns ( ( ) => [ workspaceFolder ] )
483+ . verifiable ( TypeMoq . Times . once ( ) ) ;
484+ fs . setup ( ( w ) => w . fileExists ( TypeMoq . It . isAny ( ) ) )
485+ . returns ( ( ) => Promise . resolve ( true ) )
486+ . verifiable ( TypeMoq . Times . once ( ) ) ;
487+ fs . setup ( ( w ) => w . readFile ( TypeMoq . It . isAny ( ) ) )
488+ . returns ( ( ) => Promise . resolve ( launchJson ) )
489+ . verifiable ( TypeMoq . Times . atLeastOnce ( ) ) ;
490+ fs . setup ( ( w ) => w . writeFile ( TypeMoq . It . isAnyString ( ) , correctedlaunchJson ) )
491+ . returns ( ( ) => Promise . resolve ( ) )
492+ . verifiable ( TypeMoq . Times . once ( ) ) ;
493+ await ( diagnosticService as any ) . fixLaunchJson ( DiagnosticCodes . ConfigPythonPathDiagnostic ) ;
494+ workspaceService . verifyAll ( ) ;
495+ fs . verifyAll ( ) ;
496+ } ) ;
410497} ) ;
0 commit comments