@@ -41,6 +41,7 @@ public class DebugServiceTests : IDisposable
41
41
private readonly BlockingCollection < DebuggerStoppedEventArgs > debuggerStoppedQueue = new ( ) ;
42
42
private readonly WorkspaceService workspace ;
43
43
private readonly ScriptFile debugScriptFile ;
44
+ private readonly ScriptFile oddPathScriptFile ;
44
45
private readonly ScriptFile variableScriptFile ;
45
46
private readonly TestReadLine testReadLine = new ( ) ;
46
47
@@ -68,9 +69,10 @@ public DebugServiceTests()
68
69
69
70
debugService . DebuggerStopped += OnDebuggerStopped ;
70
71
71
- // Load the test debug files
72
+ // Load the test debug files.
72
73
workspace = new WorkspaceService ( NullLoggerFactory . Instance ) ;
73
74
debugScriptFile = GetDebugScript ( "DebugTest.ps1" ) ;
75
+ oddPathScriptFile = GetDebugScript ( "Debug' W&ith $Params [Test].ps1" ) ;
74
76
variableScriptFile = GetDebugScript ( "VariableTest.ps1" ) ;
75
77
}
76
78
@@ -105,16 +107,16 @@ private VariableDetailsBase[] GetVariables(string scopeName)
105
107
return debugService . GetVariables ( scope . Id ) ;
106
108
}
107
109
108
- private Task ExecutePowerShellCommand ( string command , params string [ ] args )
110
+ private Task ExecuteScriptFileAsync ( string scriptFilePath , params string [ ] args )
109
111
{
110
112
return psesHost . ExecutePSCommandAsync (
111
- PSCommandHelpers . BuildDotSourceCommandWithArguments ( string . Concat ( '"' , command , '"' ) , args ) ,
113
+ PSCommandHelpers . BuildDotSourceCommandWithArguments ( PSCommandHelpers . EscapeScriptFilePath ( scriptFilePath ) , args ) ,
112
114
CancellationToken . None ) ;
113
115
}
114
116
115
- private Task ExecuteDebugFile ( ) => ExecutePowerShellCommand ( debugScriptFile . FilePath ) ;
117
+ private Task ExecuteDebugFileAsync ( ) => ExecuteScriptFileAsync ( debugScriptFile . FilePath ) ;
116
118
117
- private Task ExecuteVariableScriptFile ( ) => ExecutePowerShellCommand ( variableScriptFile . FilePath ) ;
119
+ private Task ExecuteVariableScriptFileAsync ( ) => ExecuteScriptFileAsync ( variableScriptFile . FilePath ) ;
118
120
119
121
private void AssertDebuggerPaused ( )
120
122
{
@@ -201,27 +203,22 @@ await debugService.SetCommandBreakpointsAsync(
201
203
[ MemberData ( nameof ( DebuggerAcceptsScriptArgsTestData ) ) ]
202
204
public async Task DebuggerAcceptsScriptArgs ( string [ ] args )
203
205
{
204
- // The path is intentionally odd (some escaped chars but not all) because we are testing
205
- // the internal path escaping mechanism - it should escape certain chars ([, ] and space) but
206
- // it should not escape already escaped chars.
207
- ScriptFile debugWithParamsFile = GetDebugScript ( "Debug W&ith Params [Test].ps1" ) ;
208
-
209
206
BreakpointDetails [ ] breakpoints = await debugService . SetLineBreakpointsAsync (
210
- debugWithParamsFile ,
211
- new [ ] { BreakpointDetails . Create ( debugWithParamsFile . FilePath , 3 ) } ) . ConfigureAwait ( true ) ;
207
+ oddPathScriptFile ,
208
+ new [ ] { BreakpointDetails . Create ( oddPathScriptFile . FilePath , 3 ) } ) . ConfigureAwait ( true ) ;
212
209
213
210
Assert . Single ( breakpoints ) ;
214
211
Assert . Collection ( breakpoints , ( breakpoint ) =>
215
212
{
216
213
// TODO: The drive letter becomes lower cased on Windows for some reason.
217
- Assert . Equal ( debugWithParamsFile . FilePath , breakpoint . Source , ignoreCase : true ) ;
214
+ Assert . Equal ( oddPathScriptFile . FilePath , breakpoint . Source , ignoreCase : true ) ;
218
215
Assert . Equal ( 3 , breakpoint . LineNumber ) ;
219
216
Assert . True ( breakpoint . Verified ) ;
220
217
} ) ;
221
218
222
- Task _ = ExecutePowerShellCommand ( debugWithParamsFile . FilePath , args ) ;
219
+ Task _ = ExecuteScriptFileAsync ( oddPathScriptFile . FilePath , args ) ;
223
220
224
- AssertDebuggerStopped ( debugWithParamsFile . FilePath , 3 ) ;
221
+ AssertDebuggerStopped ( oddPathScriptFile . FilePath , 3 ) ;
225
222
226
223
VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
227
224
@@ -273,8 +270,7 @@ public async Task DebuggerSetsAndClearsFunctionBreakpoints()
273
270
breakpoints = await debugService . SetCommandBreakpointsAsync (
274
271
new [ ] { CommandBreakpointDetails . Create ( "Get-Host" ) } ) . ConfigureAwait ( true ) ;
275
272
276
- Assert . Single ( breakpoints ) ;
277
- Assert . Equal ( "Get-Host" , breakpoints [ 0 ] . Name ) ;
273
+ Assert . Equal ( "Get-Host" , Assert . Single ( breakpoints ) . Name ) ;
278
274
279
275
breakpoints = await debugService . SetCommandBreakpointsAsync (
280
276
Array . Empty < CommandBreakpointDetails > ( ) ) . ConfigureAwait ( true ) ;
@@ -288,7 +284,7 @@ public async Task DebuggerStopsOnFunctionBreakpoints()
288
284
CommandBreakpointDetails [ ] breakpoints = await debugService . SetCommandBreakpointsAsync (
289
285
new [ ] { CommandBreakpointDetails . Create ( "Write-Host" ) } ) . ConfigureAwait ( true ) ;
290
286
291
- Task _ = ExecuteDebugFile ( ) ;
287
+ Task _ = ExecuteDebugFileAsync ( ) ;
292
288
AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
293
289
294
290
VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
@@ -355,7 +351,7 @@ await debugService.SetLineBreakpointsAsync(
355
351
BreakpointDetails . Create ( debugScriptFile . FilePath , 7 )
356
352
} ) . ConfigureAwait ( true ) ;
357
353
358
- Task _ = ExecuteDebugFile ( ) ;
354
+ Task _ = ExecuteDebugFileAsync ( ) ;
359
355
AssertDebuggerStopped ( debugScriptFile . FilePath , 5 ) ;
360
356
debugService . Continue ( ) ;
361
357
AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
@@ -373,7 +369,7 @@ await debugService.SetLineBreakpointsAsync(
373
369
BreakpointDetails . Create ( debugScriptFile . FilePath , 7 , null , $ "$i -eq { breakpointValue1 } -or $i -eq { breakpointValue2 } ") ,
374
370
} ) . ConfigureAwait ( true ) ;
375
371
376
- Task _ = ExecuteDebugFile ( ) ;
372
+ Task _ = ExecuteDebugFileAsync ( ) ;
377
373
AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
378
374
379
375
VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
@@ -409,7 +405,7 @@ await debugService.SetLineBreakpointsAsync(
409
405
BreakpointDetails . Create ( debugScriptFile . FilePath , 6 , null , null , $ "{ hitCount } ") ,
410
406
} ) . ConfigureAwait ( true ) ;
411
407
412
- Task _ = ExecuteDebugFile ( ) ;
408
+ Task _ = ExecuteDebugFileAsync ( ) ;
413
409
AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
414
410
415
411
VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
@@ -430,7 +426,7 @@ await debugService.SetLineBreakpointsAsync(
430
426
debugScriptFile ,
431
427
new [ ] { BreakpointDetails . Create ( debugScriptFile . FilePath , 6 , null , "$i % 2 -eq 0" , $ "{ hitCount } ") } ) . ConfigureAwait ( true ) ;
432
428
433
- Task _ = ExecuteDebugFile ( ) ;
429
+ Task _ = ExecuteDebugFileAsync ( ) ;
434
430
AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
435
431
436
432
VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
@@ -498,7 +494,7 @@ public async Task DebuggerBreaksWhenRequested()
498
494
{
499
495
IReadOnlyList < LineBreakpoint > confirmedBreakpoints = await GetConfirmedBreakpoints ( debugScriptFile ) . ConfigureAwait ( true ) ;
500
496
Assert . Equal ( 0 , confirmedBreakpoints . Count ) ;
501
- Task _ = ExecuteDebugFile ( ) ;
497
+ Task _ = ExecuteDebugFileAsync ( ) ;
502
498
// NOTE: This must be run on a separate thread so the async event handlers can fire.
503
499
await Task . Run ( ( ) => debugService . Break ( ) ) . ConfigureAwait ( true ) ;
504
500
AssertDebuggerPaused ( ) ;
@@ -507,7 +503,7 @@ public async Task DebuggerBreaksWhenRequested()
507
503
[ Fact ]
508
504
public async Task DebuggerRunsCommandsWhileStopped ( )
509
505
{
510
- Task _ = ExecuteDebugFile ( ) ;
506
+ Task _ = ExecuteDebugFileAsync ( ) ;
511
507
// NOTE: This must be run on a separate thread so the async event handlers can fire.
512
508
await Task . Run ( ( ) => debugService . Break ( ) ) . ConfigureAwait ( true ) ;
513
509
AssertDebuggerPaused ( ) ;
@@ -529,7 +525,7 @@ await debugService.SetCommandBreakpointsAsync(
529
525
new [ ] { CommandBreakpointDetails . Create ( "Write-Host" ) } ) . ConfigureAwait ( true ) ;
530
526
531
527
ScriptFile testScript = GetDebugScript ( "PSDebugContextTest.ps1" ) ;
532
- Task _ = ExecutePowerShellCommand ( testScript . FilePath ) ;
528
+ Task _ = ExecuteScriptFileAsync ( testScript . FilePath ) ;
533
529
AssertDebuggerStopped ( testScript . FilePath , 11 ) ;
534
530
535
531
VariableDetails prompt = await debugService . EvaluateExpressionAsync ( "prompt" , false ) . ConfigureAwait ( true ) ;
@@ -582,12 +578,10 @@ public async Task RecordsF5CommandInPowerShellHistory()
582
578
CancellationToken . None ) . ConfigureAwait ( true ) ;
583
579
584
580
// Check the PowerShell history
585
- Assert . Single ( historyResult ) ;
586
- Assert . Equal ( ". '" + debugScriptFile . FilePath + "'" , historyResult [ 0 ] ) ;
581
+ Assert . Equal ( ". '" + debugScriptFile . FilePath + "'" , Assert . Single ( historyResult ) ) ;
587
582
588
583
// Check the stubbed PSReadLine history
589
- Assert . Single ( testReadLine . history ) ;
590
- Assert . Equal ( ". '" + debugScriptFile . FilePath + "'" , testReadLine . history [ 0 ] ) ;
584
+ Assert . Equal ( ". '" + debugScriptFile . FilePath + "'" , Assert . Single ( testReadLine . history ) ) ;
591
585
}
592
586
593
587
[ Fact ]
@@ -606,12 +600,25 @@ public async Task RecordsF8CommandInHistory()
606
600
CancellationToken . None ) . ConfigureAwait ( true ) ;
607
601
608
602
// Check the PowerShell history
609
- Assert . Single ( historyResult ) ;
610
- Assert . Equal ( script , historyResult [ 0 ] ) ;
603
+ Assert . Equal ( script , Assert . Single ( historyResult ) ) ;
611
604
612
605
// Check the stubbed PSReadLine history
613
- Assert . Single ( testReadLine . history ) ;
614
- Assert . Equal ( script , testReadLine . history [ 0 ] ) ;
606
+ Assert . Equal ( script , Assert . Single ( testReadLine . history ) ) ;
607
+ }
608
+
609
+ [ Fact ]
610
+ public async Task OddFilePathsLaunchCorrectly ( )
611
+ {
612
+ ConfigurationDoneHandler configurationDoneHandler = new (
613
+ NullLoggerFactory . Instance , null , debugService , null , null , psesHost , workspace , null , psesHost ) ;
614
+ await configurationDoneHandler . LaunchScriptAsync ( oddPathScriptFile . FilePath ) . ConfigureAwait ( true ) ;
615
+
616
+ IReadOnlyList < string > historyResult = await psesHost . ExecutePSCommandAsync < string > (
617
+ new PSCommand ( ) . AddScript ( "(Get-History).CommandLine" ) ,
618
+ CancellationToken . None ) . ConfigureAwait ( true ) ;
619
+
620
+ // Check the PowerShell history
621
+ Assert . Equal ( ". " + PSCommandHelpers . EscapeScriptFilePath ( oddPathScriptFile . FilePath ) , Assert . Single ( historyResult ) ) ;
615
622
}
616
623
617
624
[ Fact ]
@@ -621,7 +628,7 @@ await debugService.SetLineBreakpointsAsync(
621
628
variableScriptFile ,
622
629
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 8 ) } ) . ConfigureAwait ( true ) ;
623
630
624
- Task _ = ExecuteVariableScriptFile ( ) ;
631
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
625
632
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
626
633
627
634
VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
@@ -639,7 +646,7 @@ await debugService.SetLineBreakpointsAsync(
639
646
variableScriptFile ,
640
647
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 21 ) } ) . ConfigureAwait ( true ) ;
641
648
642
- Task _ = ExecuteVariableScriptFile ( ) ;
649
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
643
650
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
644
651
645
652
VariableDetailsBase [ ] variables = GetVariables ( VariableContainerDetails . LocalScopeName ) ;
@@ -689,7 +696,7 @@ await debugService.SetLineBreakpointsAsync(
689
696
variableScriptFile ,
690
697
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 14 ) } ) . ConfigureAwait ( true ) ;
691
698
692
- Task _ = ExecuteVariableScriptFile ( ) ;
699
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
693
700
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
694
701
695
702
VariableScope [ ] scopes = debugService . GetVariableScopes ( 0 ) ;
@@ -743,7 +750,7 @@ await debugService.SetLineBreakpointsAsync(
743
750
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 14 ) } ) . ConfigureAwait ( true ) ;
744
751
745
752
// Execute the script and wait for the breakpoint to be hit
746
- Task _ = ExecuteVariableScriptFile ( ) ;
753
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
747
754
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
748
755
749
756
VariableScope [ ] scopes = debugService . GetVariableScopes ( 0 ) ;
@@ -799,7 +806,7 @@ await debugService.SetLineBreakpointsAsync(
799
806
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 15 ) } ) . ConfigureAwait ( true ) ;
800
807
801
808
// Execute the script and wait for the breakpoint to be hit
802
- Task _ = ExecuteVariableScriptFile ( ) ;
809
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
803
810
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
804
811
805
812
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
@@ -819,7 +826,7 @@ await debugService.SetLineBreakpointsAsync(
819
826
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 11 ) } ) . ConfigureAwait ( true ) ;
820
827
821
828
// Execute the script and wait for the breakpoint to be hit
822
- Task _ = ExecuteVariableScriptFile ( ) ;
829
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
823
830
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
824
831
825
832
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
@@ -852,7 +859,7 @@ await debugService.SetLineBreakpointsAsync(
852
859
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 16 ) } ) . ConfigureAwait ( true ) ;
853
860
854
861
// Execute the script and wait for the breakpoint to be hit
855
- Task _ = ExecuteVariableScriptFile ( ) ;
862
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
856
863
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
857
864
858
865
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
@@ -872,7 +879,7 @@ await debugService.SetLineBreakpointsAsync(
872
879
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 17 ) } ) . ConfigureAwait ( true ) ;
873
880
874
881
// Execute the script and wait for the breakpoint to be hit
875
- Task _ = ExecuteVariableScriptFile ( ) ;
882
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
876
883
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
877
884
878
885
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
@@ -898,7 +905,7 @@ public async Task DebuggerEnumerableShowsRawView()
898
905
await debugService . SetCommandBreakpointsAsync ( new [ ] { breakpoint } ) . ConfigureAwait ( true ) ;
899
906
900
907
// Execute the script and wait for the breakpoint to be hit
901
- Task _ = ExecuteVariableScriptFile ( ) ;
908
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
902
909
AssertDebuggerStopped ( commandBreakpointDetails : breakpoint ) ;
903
910
904
911
VariableDetailsBase simpleArrayVar = Array . Find (
@@ -935,7 +942,7 @@ public async Task DebuggerDictionaryShowsRawView()
935
942
await debugService . SetCommandBreakpointsAsync ( new [ ] { breakpoint } ) . ConfigureAwait ( true ) ;
936
943
937
944
// Execute the script and wait for the breakpoint to be hit
938
- Task _ = ExecuteVariableScriptFile ( ) ;
945
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
939
946
AssertDebuggerStopped ( commandBreakpointDetails : breakpoint ) ;
940
947
941
948
VariableDetailsBase simpleDictionaryVar = Array . Find (
@@ -971,7 +978,7 @@ public async Task DebuggerDerivedDictionaryPropertyInRawView()
971
978
await debugService . SetCommandBreakpointsAsync ( new [ ] { breakpoint } ) . ConfigureAwait ( true ) ;
972
979
973
980
// Execute the script and wait for the breakpoint to be hit
974
- Task _ = ExecuteVariableScriptFile ( ) ;
981
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
975
982
AssertDebuggerStopped ( commandBreakpointDetails : breakpoint ) ;
976
983
977
984
VariableDetailsBase sortedDictionaryVar = Array . Find (
@@ -1000,7 +1007,7 @@ await debugService.SetLineBreakpointsAsync(
1000
1007
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 18 ) } ) . ConfigureAwait ( true ) ;
1001
1008
1002
1009
// Execute the script and wait for the breakpoint to be hit
1003
- Task _ = ExecuteVariableScriptFile ( ) ;
1010
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
1004
1011
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
1005
1012
1006
1013
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
@@ -1029,7 +1036,7 @@ await debugService.SetLineBreakpointsAsync(
1029
1036
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 19 ) } ) . ConfigureAwait ( true ) ;
1030
1037
1031
1038
// Execute the script and wait for the breakpoint to be hit
1032
- Task _ = ExecuteVariableScriptFile ( ) ;
1039
+ Task _ = ExecuteVariableScriptFileAsync ( ) ;
1033
1040
AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
1034
1041
1035
1042
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) . ConfigureAwait ( true ) ;
0 commit comments